feat(init): toggle auto config state with flag

resolves #2848
This commit is contained in:
Jan De Dobbeleer 2022-10-03 12:56:49 +02:00 committed by Jan De Dobbeleer
parent 8dada3cbaf
commit 94a379b26a
3 changed files with 15 additions and 3 deletions

View file

@ -12,6 +12,7 @@ import (
var (
print bool
strict bool
manual bool
initCmd = &cobra.Command{
Use: "init [bash|zsh|fish|powershell|pwsh|cmd|nu] --config ~/.mytheme.omp.json",
@ -42,6 +43,7 @@ See the documentation to initialize your shell: https://ohmyposh.dev/docs/instal
func init() { //nolint:gochecknoinits
initCmd.Flags().BoolVarP(&print, "print", "p", false, "print the init script")
initCmd.Flags().BoolVarP(&strict, "strict", "s", false, "run in strict mode")
initCmd.Flags().BoolVarP(&manual, "manual", "m", false, "enable/disable manual mode")
_ = initCmd.MarkPersistentFlagRequired("config")
rootCmd.AddCommand(initCmd)
}
@ -53,6 +55,7 @@ func runInit(shellName string) {
Shell: shellName,
Config: config,
Strict: strict,
Manual: manual,
},
}
env.Init()

View file

@ -54,6 +54,7 @@ type Flags struct {
TerminalWidth int
Strict bool
Debug bool
Manual bool
}
type CommandError struct {

View file

@ -174,6 +174,14 @@ func PrintInit(env environment.Environment) string {
if err != nil {
return noExe
}
toggleSetting := func(setting bool) string {
if env.Flags().Manual {
return "false"
}
return strconv.FormatBool(setting)
}
shell := env.Flags().Shell
configFile := env.Flags().Config
var script string
@ -209,9 +217,9 @@ func PrintInit(env environment.Environment) string {
"::OMP::", executable,
"::CONFIG::", configFile,
"::SHELL::", shell,
"::TRANSIENT::", strconv.FormatBool(Transient),
"::ERROR_LINE::", strconv.FormatBool(ErrorLine),
"::TOOLTIPS::", strconv.FormatBool(Tooltips),
"::TRANSIENT::", toggleSetting(Transient),
"::ERROR_LINE::", toggleSetting(ErrorLine),
"::TOOLTIPS::", toggleSetting(Tooltips),
).Replace(script)
}