Merge pull request #721 from ahlaw/main

Normalize case of command and flag help
This commit is contained in:
Guillaume Tardif 2020-10-05 11:45:47 +02:00 committed by GitHub
commit 144c403e96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 7 deletions

View File

@ -89,9 +89,9 @@ $ docker context create my-context --description "some description" --docker "ho
flags.String( flags.String(
"default-stack-orchestrator", "", "default-stack-orchestrator", "",
"Default orchestrator for stack operations to use with this context (swarm|kubernetes|all)") "Default orchestrator for stack operations to use with this context (swarm|kubernetes|all)")
flags.StringToString("docker", nil, "set the docker endpoint") flags.StringToString("docker", nil, "Set the docker endpoint")
flags.StringToString("kubernetes", nil, "set the kubernetes endpoint") flags.StringToString("kubernetes", nil, "Set the kubernetes endpoint")
flags.String("from", "", "create context from a named context") flags.String("from", "", "Create context from a named context")
return cmd return cmd
} }

View File

@ -44,7 +44,7 @@ func removeCommand() *cobra.Command {
return runRemove(cmd.Context(), args, opts.force) return runRemove(cmd.Context(), args, opts.force)
}, },
} }
cmd.Flags().BoolVarP(&opts.force, "force", "f", false, "force removing current context") cmd.Flags().BoolVarP(&opts.force, "force", "f", false, "Force removing current context")
return cmd return cmd
} }

View File

@ -139,12 +139,16 @@ func main() {
helpFunc(cmd, args) helpFunc(cmd, args)
}) })
root.PersistentFlags().BoolVarP(&opts.Debug, "debug", "D", false, "enable debug output in the logs") root.PersistentFlags().BoolVarP(&opts.Debug, "debug", "D", false, "Enable debug output in the logs")
root.PersistentFlags().StringVarP(&opts.Host, "host", "H", "", "Daemon socket(s) to connect to") root.PersistentFlags().StringVarP(&opts.Host, "host", "H", "", "Daemon socket(s) to connect to")
opts.AddConfigFlags(root.PersistentFlags()) opts.AddConfigFlags(root.PersistentFlags())
opts.AddContextFlags(root.PersistentFlags()) opts.AddContextFlags(root.PersistentFlags())
root.Flags().BoolVarP(&opts.Version, "version", "v", false, "Print version information and quit") root.Flags().BoolVarP(&opts.Version, "version", "v", false, "Print version information and quit")
walk(root, func(c *cobra.Command) {
c.Flags().BoolP("help", "h", false, "Help for "+c.Name())
})
// populate the opts with the global flags // populate the opts with the global flags
_ = root.PersistentFlags().Parse(os.Args[1:]) _ = root.PersistentFlags().Parse(os.Args[1:])
if opts.Debug { if opts.Debug {
@ -277,3 +281,10 @@ func determineCurrentContext(flag string, configDir string) string {
} }
return res return res
} }
func walk(c *cobra.Command, f func(*cobra.Command)) {
f(c)
for _, c := range c.Commands() {
walk(c, f)
}
}

View File

@ -50,9 +50,9 @@ Options:
this context this context
(swarm|kubernetes|all) (swarm|kubernetes|all)
--description string Description of the context --description string Description of the context
--docker stringToString set the docker endpoint --docker stringToString Set the docker endpoint
(default []) (default [])
--kubernetes stringToString set the kubernetes endpoint --kubernetes stringToString Set the kubernetes endpoint
(default []) (default [])
--from string Create the context from an existing context --from string Create the context from an existing context
``` ```