From a0002e16b5b061a0330457648051346a0d39e2d9 Mon Sep 17 00:00:00 2001 From: "L. Yeung" Date: Tue, 12 Nov 2024 00:22:19 +0800 Subject: [PATCH] feat(cli): restore `--version` option --- src/cli/root.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/cli/root.go b/src/cli/root.go index c08d4769..0f269a1b 100644 --- a/src/cli/root.go +++ b/src/cli/root.go @@ -1,17 +1,23 @@ package cli import ( + "fmt" "os" "strings" + "github.com/jandedobbeleer/oh-my-posh/src/build" "github.com/spf13/cobra" ) var ( - configFlag string - shellName string - silent bool - // Deprecated flags, should be kept to avoid breaking CLI integration. + configFlag string + shellName string + printVersion bool + + // for internal use only + silent bool + + // deprecated initialize bool ) @@ -27,6 +33,10 @@ on getting started, have a look at the docs at https://ohmyposh.dev`, runInit(strings.ToLower(shellName)) return } + if printVersion { + fmt.Println(build.Version) + return + } _ = cmd.Help() }, @@ -42,6 +52,7 @@ func Execute() { func init() { RootCmd.PersistentFlags().StringVarP(&configFlag, "config", "c", "", "config file path") RootCmd.PersistentFlags().BoolVar(&silent, "silent", false, "do not print anything") + RootCmd.Flags().BoolVar(&printVersion, "version", false, "print the version number and exit") // Deprecated flags, should be kept to avoid breaking CLI integration. RootCmd.Flags().BoolVarP(&initialize, "init", "i", false, "init")