fix(cli): version info compatibility

resolves #1911
This commit is contained in:
Jan De Dobbeleer 2022-03-13 07:43:32 +01:00 committed by Jan De Dobbeleer
parent 308ce40302
commit 0bd957fc76
11 changed files with 28 additions and 18 deletions

View file

@ -2,7 +2,7 @@
Copyright © 2022 NAME HERE <EMAIL ADDRESS> Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/ */
package cmd package cli
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"

View file

@ -2,7 +2,7 @@
Copyright © 2022 NAME HERE <EMAIL ADDRESS> Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/ */
package cmd package cli
import ( import (
"fmt" "fmt"

View file

@ -2,7 +2,7 @@
Copyright © 2022 NAME HERE <EMAIL ADDRESS> Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/ */
package cmd package cli
import ( import (
"fmt" "fmt"

View file

@ -2,7 +2,7 @@
Copyright © 2022 NAME HERE <EMAIL ADDRESS> Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/ */
package cmd package cli
import ( import (
"fmt" "fmt"

View file

@ -2,7 +2,7 @@
Copyright © 2022 NAME HERE <EMAIL ADDRESS> Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/ */
package cmd package cli
import ( import (
"fmt" "fmt"

View file

@ -2,7 +2,7 @@
Copyright © 2022 NAME HERE <EMAIL ADDRESS> Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/ */
package cmd package cli
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"

View file

@ -2,7 +2,7 @@
Copyright © 2022 NAME HERE <EMAIL ADDRESS> Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/ */
package cmd package cli
import ( import (
"fmt" "fmt"

View file

@ -2,7 +2,7 @@
Copyright © 2022 NAME HERE <EMAIL ADDRESS> Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/ */
package cmd package cli
import ( import (
"fmt" "fmt"
@ -90,7 +90,7 @@ var printCmd = &cobra.Command{
} }
switch args[0] { switch args[0] {
case "debug": case "debug":
fmt.Print(eng.PrintDebug(Version)) fmt.Print(eng.PrintDebug(cliVersion))
case "primary": case "primary":
fmt.Print(eng.PrintPrimary()) fmt.Print(eng.PrintPrimary())
case "secondary": case "secondary":

View file

@ -1,4 +1,4 @@
package cmd package cli
import ( import (
"fmt" "fmt"
@ -9,8 +9,9 @@ import (
// Version number of oh-my-posh // Version number of oh-my-posh
var ( var (
Version = "development"
config string config string
displayVersion bool
cliVersion string
) )
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
@ -25,11 +26,15 @@ on getting started, have a look at the docs at https://ohmyposh.dev`,
runInit(shell) runInit(shell)
return return
} }
fmt.Println(Version) if displayVersion {
fmt.Println(cliVersion)
return
}
}, },
} }
func Execute() { func Execute(version string) {
cliVersion = version
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
os.Exit(1) os.Exit(1)
@ -45,5 +50,6 @@ var (
func init() { // nolint:gochecknoinits func init() { // nolint:gochecknoinits
rootCmd.PersistentFlags().StringVarP(&config, "config", "c", "", "config (required)") rootCmd.PersistentFlags().StringVarP(&config, "config", "c", "", "config (required)")
rootCmd.Flags().BoolVarP(&initialize, "init", "i", false, "init (deprecated)") rootCmd.Flags().BoolVarP(&initialize, "init", "i", false, "init (deprecated)")
rootCmd.Flags().BoolVar(&displayVersion, "version", false, "version")
rootCmd.Flags().StringVarP(&shell, "shell", "s", "", "shell (deprecated)") rootCmd.Flags().StringVarP(&shell, "shell", "s", "", "shell (deprecated)")
} }

View file

@ -2,7 +2,7 @@
Copyright © 2022 NAME HERE <EMAIL ADDRESS> Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/ */
package cmd package cli
import ( import (
"fmt" "fmt"
@ -16,7 +16,7 @@ var versionCmd = &cobra.Command{
Short: "Print the version", Short: "Print the version",
Long: "Print oh-my-posh version and build information.", Long: "Print oh-my-posh version and build information.",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Println(Version) fmt.Println(cliVersion)
}, },
} }

View file

@ -1,7 +1,11 @@
package main package main
import "oh-my-posh/cmd" import "oh-my-posh/cli"
var (
Version = "development"
)
func main() { func main() {
cmd.Execute() cli.Execute(Version)
} }