|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + |
| 6 | + "github.com/spf13/cobra" |
| 7 | + "github.com/spf13/viper" |
| 8 | +) |
| 9 | + |
| 10 | +// rootCmd represents the base command when called without any subcommands |
| 11 | +var Verbose bool |
| 12 | +var Debug bool |
| 13 | +var Highlight int |
| 14 | + |
| 15 | +var rootCmd = &cobra.Command{ |
| 16 | + Use: "getsize", |
| 17 | + Short: "List the size of a local directory.", |
| 18 | + Long: `This command will display the size of a directory with several different options.`, |
| 19 | +} |
| 20 | + |
| 21 | +// Execute adds all child commands to the root command and sets flags appropriately. |
| 22 | +// This is called by main.main(). It only needs to happen once to the rootCmd. |
| 23 | +func Execute() { |
| 24 | + err := rootCmd.Execute() |
| 25 | + if err != nil { |
| 26 | + os.Exit(1) |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +func init() { |
| 31 | + rootCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "Display more verbose output in console output. (default: false)") |
| 32 | + viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose")) |
| 33 | + |
| 34 | + rootCmd.PersistentFlags().BoolVarP(&Debug, "debug", "d", false, "Display debugging output in the console. (default: false)") |
| 35 | + viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug")) |
| 36 | + |
| 37 | + rootCmd.PersistentFlags().IntVarP(&Highlight, "highlight", "", 500, "Highlight files/directories over this threshold, in MB") |
| 38 | + viper.BindPFlag("highlight", rootCmd.PersistentFlags().Lookup("highlight")) |
| 39 | + |
| 40 | + rootCmd.PersistentFlags().StringVarP(&Path, "path", "p", "", "Define the path to scan.") |
| 41 | + rootCmd.MarkPersistentFlagRequired("path") |
| 42 | + viper.BindPFlag("path", rootCmd.PersistentFlags().Lookup("path")) |
| 43 | +} |
0 commit comments