From 470003432d593d792bffccfbff4a5dcdb1c83930 Mon Sep 17 00:00:00 2001 From: djelusic Date: Mon, 8 Nov 2021 13:13:17 +0100 Subject: [PATCH] replace [flags] with [options] in use line --- cli/cmd/commands.go | 10 +++++----- cli/cmd/root.go | 10 +++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cli/cmd/commands.go b/cli/cmd/commands.go index 294599a1..71ab5982 100644 --- a/cli/cmd/commands.go +++ b/cli/cmd/commands.go @@ -19,8 +19,8 @@ func newAwsCommand() *cobra.Command { Short: "AWS node subcommand", Args: cobra.NoArgs, } - cmd.AddCommand(newAwsInstallCommand()) - cmd.AddCommand(newAwsUninstallCommand()) + addCommand(cmd, newAwsInstallCommand()) + addCommand(cmd, newAwsUninstallCommand()) return cmd } @@ -356,8 +356,8 @@ which can be managed and configured separately. Stages can be deployed to any node in the workspace.`, } - cmd.AddCommand(newStageNewCommand()) - cmd.AddCommand(newStageDestroyCommand()) + addCommand(cmd, newStageNewCommand()) + addCommand(cmd, newStageDestroyCommand()) return cmd } @@ -428,7 +428,7 @@ func newGenerateCommand() *cobra.Command { Use: "generate", Short: "Automatically generate code in the project", } - cmd.AddCommand(newGenerateApiCommand()) + addCommand(cmd, newGenerateApiCommand()) return cmd } diff --git a/cli/cmd/root.go b/cli/cmd/root.go index a846fea8..2299cd3d 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -56,7 +56,7 @@ func root() *cobra.Command { add := func(factory func() *cobra.Command) { sub := factory() - cmd.AddCommand(sub) + addCommand(cmd, sub) } subCommands := []func() *cobra.Command{ newEnvCommand, @@ -190,3 +190,11 @@ Please check the following rules when naming projects, stages and functions: ui.Error(err) } + +func addCommand(target, cmd *cobra.Command) { + cmd.DisableFlagsInUseLine = true + if cmd.HasAvailableFlags() && !strings.Contains(cmd.Use, "[options]") { + cmd.Use += " [options]" + } + target.AddCommand(cmd) +}