mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
refactor(cli): hide deprecated/internal subcommands and flags
This commit is contained in:
parent
d2e04b6654
commit
9ce9ed72bb
|
@ -15,7 +15,14 @@ import (
|
|||
)
|
||||
|
||||
// debugCmd represents the prompt command
|
||||
var debugCmd = &cobra.Command{
|
||||
var debugCmd = createDebugCmd()
|
||||
|
||||
func init() {
|
||||
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.",
|
||||
|
@ -60,11 +67,16 @@ var debugCmd = &cobra.Command{
|
|||
|
||||
fmt.Print(eng.PrintDebug(startTime, build.Version))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
// 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",
|
||||
}
|
||||
|
||||
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]",
|
||||
Short: "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])
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
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(&manual, "manual", "m", false, "enable/disable manual 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")
|
||||
RootCmd.AddCommand(initCmd)
|
||||
|
||||
return initCmd
|
||||
}
|
||||
|
||||
func runInit(shellName string) {
|
||||
|
@ -68,7 +81,6 @@ func runInit(shellName string) {
|
|||
Shell: shellName,
|
||||
Config: configFlag,
|
||||
Strict: strict,
|
||||
Manual: manual,
|
||||
Debug: debug,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -30,7 +30,14 @@ var (
|
|||
)
|
||||
|
||||
// printCmd represents the prompt command
|
||||
var printCmd = &cobra.Command{
|
||||
var printCmd = createPrintCmd()
|
||||
|
||||
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.",
|
||||
|
@ -95,9 +102,8 @@ var printCmd = &cobra.Command{
|
|||
_ = cmd.Help()
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
printCmd.Flags().StringVar(&pwd, "pwd", "", "current working directory")
|
||||
printCmd.Flags().StringVar(&pswd, "pswd", "", "current working directory (according to pwsh)")
|
||||
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(&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().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")
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ var promptCmd = &cobra.Command{
|
|||
Use: "prompt",
|
||||
Short: "Set up the prompt for your shell (deprecated)",
|
||||
Long: `Set up the prompt for your shell. (deprecated)`,
|
||||
Hidden: true,
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, _ []string) {
|
||||
_ = cmd.Help()
|
||||
|
@ -17,8 +18,8 @@ var promptCmd = &cobra.Command{
|
|||
|
||||
func init() {
|
||||
// legacy support
|
||||
promptCmd.AddCommand(initCmd)
|
||||
promptCmd.AddCommand(debugCmd)
|
||||
promptCmd.AddCommand(printCmd)
|
||||
promptCmd.AddCommand(createInitCmd())
|
||||
promptCmd.AddCommand(createDebugCmd())
|
||||
promptCmd.AddCommand(createPrintCmd())
|
||||
RootCmd.AddCommand(promptCmd)
|
||||
}
|
||||
|
|
|
@ -49,7 +49,13 @@ var (
|
|||
|
||||
func init() {
|
||||
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().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"
|
||||
}
|
||||
|
||||
if env.Flags().Manual {
|
||||
additionalParams += " --manual"
|
||||
}
|
||||
|
||||
var command, config string
|
||||
|
||||
switch shell {
|
||||
|
|
Loading…
Reference in a new issue