fix(cli): revert breaking CLI change
Some checks are pending
Code QL / code-ql (push) Waiting to run
Release / changelog (push) Waiting to run
Release / artifacts (push) Blocked by required conditions

This commit is contained in:
Jan De Dobbeleer 2024-11-06 06:32:59 +01:00 committed by Jan De Dobbeleer
parent 7de2809187
commit 466f9e72b8
2 changed files with 53 additions and 37 deletions

View file

@ -51,43 +51,7 @@ See the documentation to initialize your shell: https://ohmyposh.dev/docs/instal
return
}
var startTime time.Time
if debug {
startTime = time.Now()
}
env := &runtime.Terminal{
CmdFlags: &runtime.Flags{
Shell: args[0],
Config: configFlag,
Strict: strict,
Debug: debug,
},
}
env.Init()
defer env.Close()
template.Init(env)
cfg := config.Load(env)
feats := cfg.Features()
var output string
switch {
case printOutput, debug:
output = shell.PrintInit(env, feats, &startTime)
default:
output = shell.Init(env, feats)
}
if silent {
return
}
fmt.Print(output)
runInit(args[0])
},
}
@ -99,3 +63,43 @@ See the documentation to initialize your shell: https://ohmyposh.dev/docs/instal
return initCmd
}
func runInit(sh string) {
var startTime time.Time
if debug {
startTime = time.Now()
}
env := &runtime.Terminal{
CmdFlags: &runtime.Flags{
Shell: sh,
Config: configFlag,
Strict: strict,
Debug: debug,
},
}
env.Init()
defer env.Close()
template.Init(env)
cfg := config.Load(env)
feats := cfg.Features()
var output string
switch {
case printOutput, debug:
output = shell.PrintInit(env, feats, &startTime)
default:
output = shell.Init(env, feats)
}
if silent {
return
}
fmt.Print(output)
}

View file

@ -2,6 +2,7 @@ package cli
import (
"os"
"strings"
"github.com/spf13/cobra"
)
@ -10,6 +11,8 @@ var (
configFlag string
shellName string
silent bool
// Deprecated flags, should be kept to avoid breaking CLI integration.
initialize bool
)
var RootCmd = &cobra.Command{
@ -20,6 +23,11 @@ It can use the same configuration everywhere to offer a consistent
experience, regardless of where you are. For a detailed guide
on getting started, have a look at the docs at https://ohmyposh.dev`,
Run: func(cmd *cobra.Command, _ []string) {
if initialize {
runInit(strings.ToLower(shellName))
return
}
_ = cmd.Help()
},
}
@ -34,6 +42,10 @@ func Execute() {
func init() {
RootCmd.PersistentFlags().StringVarP(&configFlag, "config", "c", "", "config file path")
// Deprecated flags, should be kept to avoid breaking CLI integration.
RootCmd.Flags().BoolVarP(&initialize, "init", "i", false, "init")
RootCmd.Flags().StringVarP(&shellName, "shell", "s", "", "shell")
// Hide flags that are deprecated or for internal use only.
RootCmd.PersistentFlags().BoolVar(&silent, "silent", false, "do not print anything")
_ = RootCmd.Flags().MarkHidden("silent")