github.com/jaypipes/ghw@v0.21.1/cmd/ghw-snapshot/command/root.go (about)

     1  //
     2  // Use and distribution licensed under the Apache license version 2.
     3  //
     4  // See the COPYING file in the root project directory for full text.
     5  //
     6  
     7  package command
     8  
     9  import (
    10  	"fmt"
    11  	"os"
    12  
    13  	"github.com/spf13/cobra"
    14  )
    15  
    16  var (
    17  	debug bool
    18  )
    19  
    20  // rootCmd represents the base command when called without any subcommands
    21  var rootCmd = &cobra.Command{
    22  	Use:   "ghw-snapshot",
    23  	Short: "ghw-snapshot - create and read ghw snapshots.",
    24  	Long: `
    25          __                                                   __           __   
    26  .-----.|  |--.--.--.--.______.-----.-----.---.-.-----.-----.|  |--.-----.|  |_ 
    27  |  _  ||     |  |  |  |______|__ --|     |  _  |  _  |__ --||     |  _  ||   _|
    28  |___  ||__|__|________|      |_____|__|__|___._|   __|_____||__|__|_____||____|
    29  |_____|                                        |__|                            
    30  
    31  Create and read ghw snapshots.
    32  
    33  https://github.com/jaypipes/ghw
    34  `,
    35  	RunE: doCreate,
    36  }
    37  
    38  // Execute adds all child commands to the root command and sets flags
    39  // appropriately. This is called by main.main(). It only needs to happen once
    40  // to the rootCmd.
    41  func Execute() {
    42  	if err := rootCmd.Execute(); err != nil {
    43  		fmt.Println(err)
    44  		os.Exit(1)
    45  	}
    46  }
    47  
    48  func trace(msg string, args ...interface{}) {
    49  	if !debug {
    50  		return
    51  	}
    52  	fmt.Printf(msg, args...)
    53  }
    54  
    55  func init() {
    56  	rootCmd.PersistentFlags().BoolVar(
    57  		&debug, "debug", false, "Enable or disable debug mode",
    58  	)
    59  }