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>
*/
package cmd
package cli
import (
"github.com/spf13/cobra"

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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