diff --git a/cmd/flags.go b/cmd/flags.go new file mode 100644 index 0000000..02bb98c --- /dev/null +++ b/cmd/flags.go @@ -0,0 +1,34 @@ +package cmd + +import ( + "fmt" + + "github.com/Yakiyo/tilde/meta" + "github.com/Yakiyo/tilde/utils" +) + +func init() { + rootCmd.SetVersionTemplate(func() string { + return `tilde {{printf "version %s" .Version}}` + + fmt.Sprintf("\ntldr spec version %v\n", meta.TldrSpec) + }()) + + f := rootCmd.Flags() + // config flags + f.String("log-level", "", "Set log level [debug, info, warn, error]") + f.StringP("dir", "d", "", "Set root directory to use for tilde") + f.StringP("config", "c", "", "Set path to config file") + f.String("color", "", "Enable or disable color output") + + // command-ish flags + f.BoolP("list", "l", false, "List all commands in cache") + f.BoolP("update", "u", false, "Update local cache") + f.Bool("clear-cache", false, "Clear local cache") + f.Bool("seed-config", false, "Creates the default configuration file at the default location") + f.StringP("render", "f", "", "Render a local file") + + // command related flags + f.StringP("style", "s", "", "Set output style [fancy, plain, raw]") + f.StringP("language", "L", "", "Override language") + f.StringP("platform", "p", utils.Platform(), "Override operating system") +} diff --git a/cmd/root.go b/cmd/root.go index fd6da21..3fd3cc3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -35,8 +35,10 @@ View community driven and simplified man pages in your terminal`, config.Read() log.SetLevel(log.ParseLevel(viper.GetString("log_level"))) + where.SetRoot(viper.GetString("root_dir")) return nil }, + Args: cobra.MaximumNArgs(2), Run: func(cmd *cobra.Command, args []string) { log.Debug(viper.AllSettings()) @@ -68,6 +70,13 @@ View community driven and simplified man pages in your terminal`, // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { + if err := rootCmd.Execute(); err != nil { + log.Error(err) + os.Exit(1) + } +} + +func init() { cc.Init(&cc.Config{ RootCmd: rootCmd, Headings: cc.HiCyan + cc.Bold + cc.Underline, @@ -78,35 +87,4 @@ func Execute() { FlagsDataType: cc.Italic + cc.HiBlue, NoExtraNewlines: true, }) - - if err := rootCmd.Execute(); err != nil { - log.Error(err) - os.Exit(1) - } -} - -func init() { - rootCmd.SetVersionTemplate(func() string { - return `tilde {{printf "version %s" .Version}}` + - fmt.Sprintf("\ntldr spec version %v\n", meta.TldrSpec) - }()) - - f := rootCmd.Flags() - // config flags - f.String("log-level", "", "Set log level [debug, info, warn, error]") - f.StringP("dir", "d", "", "Set root directory to use for tilde") - f.StringP("config", "c", "", "Set path to config file") - f.String("color", "", "Enable or disable color output") - - // command-ish flags - f.BoolP("list", "l", false, "List all commands in cache") - f.BoolP("update", "u", false, "Update local cache") - f.Bool("clear-cache", false, "Clear local cache") - f.Bool("seed-config", false, "Creates the default configuration file at the default location") - f.StringP("render", "f", "", "Render a local file") - - // command related flags - f.StringP("style", "s", "", "Set output style [fancy, plain, raw]") - f.StringP("language", "L", "", "Override language") - f.StringP("platform", "p", utils.Platform(), "Override operating system") }