mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
refactor(cli): hide deprecated/internal subcommands and flags
This commit is contained in:
parent
d2e04b6654
commit
9ce9ed72bb
110
src/cli/debug.go
110
src/cli/debug.go
|
@ -15,56 +15,68 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// debugCmd represents the prompt command
|
// debugCmd represents the prompt command
|
||||||
var debugCmd = &cobra.Command{
|
var debugCmd = createDebugCmd()
|
||||||
Use: "debug [bash|zsh|fish|powershell|pwsh|cmd|nu|tcsh|elvish|xonsh]",
|
|
||||||
Short: "Print the prompt in debug mode",
|
|
||||||
Long: "Print the prompt in debug mode.",
|
|
||||||
ValidArgs: supportedShells,
|
|
||||||
Args: NoArgsOrOneValidArg,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
startTime := time.Now()
|
|
||||||
|
|
||||||
if len(args) == 0 {
|
|
||||||
_ = cmd.Help()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
env := &runtime.Terminal{
|
|
||||||
CmdFlags: &runtime.Flags{
|
|
||||||
Config: configFlag,
|
|
||||||
Debug: true,
|
|
||||||
PWD: pwd,
|
|
||||||
Shell: args[0],
|
|
||||||
Plain: plain,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
env.Init()
|
|
||||||
defer env.Close()
|
|
||||||
|
|
||||||
cfg := config.Load(env)
|
|
||||||
|
|
||||||
// add variables to the environment
|
|
||||||
env.Var = cfg.Var
|
|
||||||
|
|
||||||
terminal.Init(shell.GENERIC)
|
|
||||||
terminal.BackgroundColor = cfg.TerminalBackground.ResolveTemplate(env)
|
|
||||||
terminal.Colors = cfg.MakeColors()
|
|
||||||
terminal.Plain = plain
|
|
||||||
|
|
||||||
eng := &prompt.Engine{
|
|
||||||
Config: cfg,
|
|
||||||
Env: env,
|
|
||||||
Plain: plain,
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Print(eng.PrintDebug(startTime, build.Version))
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
debugCmd.Flags().StringVar(&pwd, "pwd", "", "current working directory")
|
|
||||||
debugCmd.Flags().StringVar(&shellName, "shell", "", "the shell to print for")
|
|
||||||
debugCmd.Flags().BoolVarP(&plain, "plain", "p", false, "plain text output (no ANSI)")
|
|
||||||
RootCmd.AddCommand(debugCmd)
|
RootCmd.AddCommand(debugCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createDebugCmd() *cobra.Command {
|
||||||
|
debugCmd := &cobra.Command{
|
||||||
|
Use: "debug [bash|zsh|fish|powershell|pwsh|cmd|nu|tcsh|elvish|xonsh]",
|
||||||
|
Short: "Print the prompt in debug mode",
|
||||||
|
Long: "Print the prompt in debug mode.",
|
||||||
|
ValidArgs: supportedShells,
|
||||||
|
Args: NoArgsOrOneValidArg,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
startTime := time.Now()
|
||||||
|
|
||||||
|
if len(args) == 0 {
|
||||||
|
_ = cmd.Help()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
env := &runtime.Terminal{
|
||||||
|
CmdFlags: &runtime.Flags{
|
||||||
|
Config: configFlag,
|
||||||
|
Debug: true,
|
||||||
|
PWD: pwd,
|
||||||
|
Shell: args[0],
|
||||||
|
Plain: plain,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
env.Init()
|
||||||
|
defer env.Close()
|
||||||
|
|
||||||
|
cfg := config.Load(env)
|
||||||
|
|
||||||
|
// add variables to the environment
|
||||||
|
env.Var = cfg.Var
|
||||||
|
|
||||||
|
terminal.Init(shell.GENERIC)
|
||||||
|
terminal.BackgroundColor = cfg.TerminalBackground.ResolveTemplate(env)
|
||||||
|
terminal.Colors = cfg.MakeColors()
|
||||||
|
terminal.Plain = plain
|
||||||
|
|
||||||
|
eng := &prompt.Engine{
|
||||||
|
Config: cfg,
|
||||||
|
Env: env,
|
||||||
|
Plain: plain,
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print(eng.PrintDebug(startTime, build.Version))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
debugCmd.Flags().StringVar(&pwd, "pwd", "", "current working directory")
|
||||||
|
debugCmd.Flags().BoolVarP(&plain, "plain", "p", false, "plain text output (no ANSI)")
|
||||||
|
|
||||||
|
// Deprecated flags, should be kept to avoid breaking CLI integration.
|
||||||
|
debugCmd.Flags().StringVar(&shellName, "shell", "", "the shell to print for")
|
||||||
|
|
||||||
|
// Hide flags that are deprecated or for internal use only.
|
||||||
|
_ = debugCmd.Flags().MarkHidden("shell")
|
||||||
|
|
||||||
|
return debugCmd
|
||||||
|
}
|
||||||
|
|
|
@ -30,7 +30,15 @@ var (
|
||||||
"xonsh",
|
"xonsh",
|
||||||
}
|
}
|
||||||
|
|
||||||
initCmd = &cobra.Command{
|
initCmd = createInitCmd()
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RootCmd.AddCommand(initCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createInitCmd() *cobra.Command {
|
||||||
|
initCmd := &cobra.Command{
|
||||||
Use: "init [bash|zsh|fish|powershell|pwsh|cmd|nu|tcsh|elvish|xonsh]",
|
Use: "init [bash|zsh|fish|powershell|pwsh|cmd|nu|tcsh|elvish|xonsh]",
|
||||||
Short: "Initialize your shell and config",
|
Short: "Initialize your shell and config",
|
||||||
Long: `Initialize your shell and config.
|
Long: `Initialize your shell and config.
|
||||||
|
@ -46,15 +54,20 @@ See the documentation to initialize your shell: https://ohmyposh.dev/docs/instal
|
||||||
runInit(args[0])
|
runInit(args[0])
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
initCmd.Flags().BoolVarP(&printOutput, "print", "p", false, "print the init script")
|
initCmd.Flags().BoolVarP(&printOutput, "print", "p", false, "print the init script")
|
||||||
initCmd.Flags().BoolVarP(&strict, "strict", "s", false, "run in strict mode")
|
initCmd.Flags().BoolVarP(&strict, "strict", "s", false, "run in strict mode")
|
||||||
initCmd.Flags().BoolVarP(&manual, "manual", "m", false, "enable/disable manual mode")
|
|
||||||
initCmd.Flags().BoolVar(&debug, "debug", false, "enable/disable debug mode")
|
initCmd.Flags().BoolVar(&debug, "debug", false, "enable/disable debug mode")
|
||||||
|
|
||||||
|
// Deprecated flags, should be kept to avoid breaking CLI integration.
|
||||||
|
initCmd.Flags().BoolVarP(&manual, "manual", "m", false, "enable/disable manual mode")
|
||||||
|
|
||||||
|
// Hide flags that are deprecated or for internal use only.
|
||||||
|
_ = initCmd.Flags().MarkHidden("manual")
|
||||||
|
|
||||||
_ = initCmd.MarkPersistentFlagRequired("config")
|
_ = initCmd.MarkPersistentFlagRequired("config")
|
||||||
RootCmd.AddCommand(initCmd)
|
|
||||||
|
return initCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func runInit(shellName string) {
|
func runInit(shellName string) {
|
||||||
|
@ -68,7 +81,6 @@ func runInit(shellName string) {
|
||||||
Shell: shellName,
|
Shell: shellName,
|
||||||
Config: configFlag,
|
Config: configFlag,
|
||||||
Strict: strict,
|
Strict: strict,
|
||||||
Manual: manual,
|
|
||||||
Debug: debug,
|
Debug: debug,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
147
src/cli/print.go
147
src/cli/print.go
|
@ -30,74 +30,80 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// printCmd represents the prompt command
|
// printCmd represents the prompt command
|
||||||
var printCmd = &cobra.Command{
|
var printCmd = createPrintCmd()
|
||||||
Use: "print [debug|primary|secondary|transient|right|tooltip|valid|error]",
|
|
||||||
Short: "Print the prompt/context",
|
|
||||||
Long: "Print one of the prompts based on the location/use-case.",
|
|
||||||
ValidArgs: []string{
|
|
||||||
"debug",
|
|
||||||
"primary",
|
|
||||||
"secondary",
|
|
||||||
"transient",
|
|
||||||
"right",
|
|
||||||
"tooltip",
|
|
||||||
"valid",
|
|
||||||
"error",
|
|
||||||
},
|
|
||||||
Args: NoArgsOrOneValidArg,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
if len(args) == 0 {
|
|
||||||
_ = cmd.Help()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
flags := &runtime.Flags{
|
|
||||||
Config: configFlag,
|
|
||||||
PWD: pwd,
|
|
||||||
PSWD: pswd,
|
|
||||||
ErrorCode: status,
|
|
||||||
PipeStatus: pipestatus,
|
|
||||||
ExecutionTime: timing,
|
|
||||||
StackCount: stackCount,
|
|
||||||
TerminalWidth: terminalWidth,
|
|
||||||
Eval: eval,
|
|
||||||
Shell: shellName,
|
|
||||||
ShellVersion: shellVersion,
|
|
||||||
Plain: plain,
|
|
||||||
Primary: args[0] == "primary",
|
|
||||||
Cleared: cleared,
|
|
||||||
NoExitCode: noStatus,
|
|
||||||
Column: column,
|
|
||||||
JobCount: jobCount,
|
|
||||||
}
|
|
||||||
|
|
||||||
eng := prompt.New(flags)
|
|
||||||
defer eng.Env.Close()
|
|
||||||
|
|
||||||
switch args[0] {
|
|
||||||
case "debug":
|
|
||||||
fmt.Print(eng.ExtraPrompt(prompt.Debug))
|
|
||||||
case "primary":
|
|
||||||
fmt.Print(eng.Primary())
|
|
||||||
case "secondary":
|
|
||||||
fmt.Print(eng.ExtraPrompt(prompt.Secondary))
|
|
||||||
case "transient":
|
|
||||||
fmt.Print(eng.ExtraPrompt(prompt.Transient))
|
|
||||||
case "right":
|
|
||||||
fmt.Print(eng.RPrompt())
|
|
||||||
case "tooltip":
|
|
||||||
fmt.Print(eng.Tooltip(command))
|
|
||||||
case "valid":
|
|
||||||
fmt.Print(eng.ExtraPrompt(prompt.Valid))
|
|
||||||
case "error":
|
|
||||||
fmt.Print(eng.ExtraPrompt(prompt.Error))
|
|
||||||
default:
|
|
||||||
_ = cmd.Help()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
RootCmd.AddCommand(printCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createPrintCmd() *cobra.Command {
|
||||||
|
printCmd := &cobra.Command{
|
||||||
|
Use: "print [debug|primary|secondary|transient|right|tooltip|valid|error]",
|
||||||
|
Short: "Print the prompt/context",
|
||||||
|
Long: "Print one of the prompts based on the location/use-case.",
|
||||||
|
ValidArgs: []string{
|
||||||
|
"debug",
|
||||||
|
"primary",
|
||||||
|
"secondary",
|
||||||
|
"transient",
|
||||||
|
"right",
|
||||||
|
"tooltip",
|
||||||
|
"valid",
|
||||||
|
"error",
|
||||||
|
},
|
||||||
|
Args: NoArgsOrOneValidArg,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
_ = cmd.Help()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
flags := &runtime.Flags{
|
||||||
|
Config: configFlag,
|
||||||
|
PWD: pwd,
|
||||||
|
PSWD: pswd,
|
||||||
|
ErrorCode: status,
|
||||||
|
PipeStatus: pipestatus,
|
||||||
|
ExecutionTime: timing,
|
||||||
|
StackCount: stackCount,
|
||||||
|
TerminalWidth: terminalWidth,
|
||||||
|
Eval: eval,
|
||||||
|
Shell: shellName,
|
||||||
|
ShellVersion: shellVersion,
|
||||||
|
Plain: plain,
|
||||||
|
Primary: args[0] == "primary",
|
||||||
|
Cleared: cleared,
|
||||||
|
NoExitCode: noStatus,
|
||||||
|
Column: column,
|
||||||
|
JobCount: jobCount,
|
||||||
|
}
|
||||||
|
|
||||||
|
eng := prompt.New(flags)
|
||||||
|
defer eng.Env.Close()
|
||||||
|
|
||||||
|
switch args[0] {
|
||||||
|
case "debug":
|
||||||
|
fmt.Print(eng.ExtraPrompt(prompt.Debug))
|
||||||
|
case "primary":
|
||||||
|
fmt.Print(eng.Primary())
|
||||||
|
case "secondary":
|
||||||
|
fmt.Print(eng.ExtraPrompt(prompt.Secondary))
|
||||||
|
case "transient":
|
||||||
|
fmt.Print(eng.ExtraPrompt(prompt.Transient))
|
||||||
|
case "right":
|
||||||
|
fmt.Print(eng.RPrompt())
|
||||||
|
case "tooltip":
|
||||||
|
fmt.Print(eng.Tooltip(command))
|
||||||
|
case "valid":
|
||||||
|
fmt.Print(eng.ExtraPrompt(prompt.Valid))
|
||||||
|
case "error":
|
||||||
|
fmt.Print(eng.ExtraPrompt(prompt.Error))
|
||||||
|
default:
|
||||||
|
_ = cmd.Help()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
printCmd.Flags().StringVar(&pwd, "pwd", "", "current working directory")
|
printCmd.Flags().StringVar(&pwd, "pwd", "", "current working directory")
|
||||||
printCmd.Flags().StringVar(&pswd, "pswd", "", "current working directory (according to pwsh)")
|
printCmd.Flags().StringVar(&pswd, "pswd", "", "current working directory (according to pwsh)")
|
||||||
printCmd.Flags().StringVar(&shellName, "shell", "", "the shell to print for")
|
printCmd.Flags().StringVar(&shellName, "shell", "", "the shell to print for")
|
||||||
|
@ -115,10 +121,15 @@ func init() {
|
||||||
printCmd.Flags().IntVar(&column, "column", 0, "the column position of the cursor")
|
printCmd.Flags().IntVar(&column, "column", 0, "the column position of the cursor")
|
||||||
printCmd.Flags().IntVar(&jobCount, "job-count", 0, "number of background jobs")
|
printCmd.Flags().IntVar(&jobCount, "job-count", 0, "number of background jobs")
|
||||||
|
|
||||||
// Deprecated flags, keep to not break CLI integration
|
// Deprecated flags, should be kept to avoid breaking CLI integration.
|
||||||
printCmd.Flags().IntVarP(&status, "error", "e", 0, "last exit code")
|
printCmd.Flags().IntVarP(&status, "error", "e", 0, "last exit code")
|
||||||
printCmd.Flags().BoolVar(&noStatus, "no-exit-code", false, "no valid exit code (cancelled or no command yet)")
|
printCmd.Flags().BoolVar(&noStatus, "no-exit-code", false, "no valid exit code (cancelled or no command yet)")
|
||||||
printCmd.Flags().BoolVar(&cached, "cached", false, "use a cached prompt")
|
printCmd.Flags().BoolVar(&cached, "cached", false, "use a cached prompt")
|
||||||
|
|
||||||
RootCmd.AddCommand(printCmd)
|
// Hide flags that are deprecated or for internal use only.
|
||||||
|
_ = printCmd.Flags().MarkHidden("error")
|
||||||
|
_ = printCmd.Flags().MarkHidden("no-exit-code")
|
||||||
|
_ = printCmd.Flags().MarkHidden("cached")
|
||||||
|
|
||||||
|
return printCmd
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,11 @@ import (
|
||||||
|
|
||||||
// promptCmd represents the prompt command
|
// promptCmd represents the prompt command
|
||||||
var promptCmd = &cobra.Command{
|
var promptCmd = &cobra.Command{
|
||||||
Use: "prompt",
|
Use: "prompt",
|
||||||
Short: "Set up the prompt for your shell (deprecated)",
|
Short: "Set up the prompt for your shell (deprecated)",
|
||||||
Long: `Set up the prompt for your shell. (deprecated)`,
|
Long: `Set up the prompt for your shell. (deprecated)`,
|
||||||
Args: cobra.NoArgs,
|
Hidden: true,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
Run: func(cmd *cobra.Command, _ []string) {
|
Run: func(cmd *cobra.Command, _ []string) {
|
||||||
_ = cmd.Help()
|
_ = cmd.Help()
|
||||||
},
|
},
|
||||||
|
@ -17,8 +18,8 @@ var promptCmd = &cobra.Command{
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// legacy support
|
// legacy support
|
||||||
promptCmd.AddCommand(initCmd)
|
promptCmd.AddCommand(createInitCmd())
|
||||||
promptCmd.AddCommand(debugCmd)
|
promptCmd.AddCommand(createDebugCmd())
|
||||||
promptCmd.AddCommand(printCmd)
|
promptCmd.AddCommand(createPrintCmd())
|
||||||
RootCmd.AddCommand(promptCmd)
|
RootCmd.AddCommand(promptCmd)
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,13 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RootCmd.PersistentFlags().StringVarP(&configFlag, "config", "c", "", "config file path")
|
RootCmd.PersistentFlags().StringVarP(&configFlag, "config", "c", "", "config file path")
|
||||||
RootCmd.Flags().BoolVarP(&initialize, "init", "i", false, "init (deprecated)")
|
|
||||||
RootCmd.Flags().BoolVar(&displayVersion, "version", false, "version")
|
RootCmd.Flags().BoolVar(&displayVersion, "version", false, "version")
|
||||||
RootCmd.Flags().StringVarP(&shellName, "shell", "s", "", "shell (deprecated)")
|
|
||||||
|
// 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.Flags().MarkHidden("init")
|
||||||
|
_ = RootCmd.Flags().MarkHidden("shell")
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,10 +49,6 @@ func Init(env runtime.Environment, feats Features) string {
|
||||||
additionalParams += " --strict"
|
additionalParams += " --strict"
|
||||||
}
|
}
|
||||||
|
|
||||||
if env.Flags().Manual {
|
|
||||||
additionalParams += " --manual"
|
|
||||||
}
|
|
||||||
|
|
||||||
var command, config string
|
var command, config string
|
||||||
|
|
||||||
switch shell {
|
switch shell {
|
||||||
|
|
Loading…
Reference in a new issue