From e1cd3d93d7d2f3cfd89b1945f32b808a477cb9d7 Mon Sep 17 00:00:00 2001 From: Khosrow Moossavi Date: Mon, 5 Aug 2019 12:35:57 -0400 Subject: [PATCH] Command long description helper function --- cmd/cca/completion/completion.go | 8 ++------ pkg/cmdutil/description.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 pkg/cmdutil/description.go diff --git a/cmd/cca/completion/completion.go b/cmd/cca/completion/completion.go index 6ccc6d6..42c5999 100644 --- a/cmd/cca/completion/completion.go +++ b/cmd/cca/completion/completion.go @@ -16,13 +16,9 @@ package completion import ( - "fmt" - "strings" - "github.com/cloud-ca/cca/cmd/cca/completion/bash" "github.com/cloud-ca/cca/cmd/cca/completion/zsh" "github.com/cloud-ca/cca/pkg/cmdutil" - "github.com/lithammer/dedent" "github.com/spf13/cobra" ) @@ -32,7 +28,7 @@ func NewCommand(gf *cmdutil.GlobalFlags) *cobra.Command { Args: cobra.NoArgs, Use: "completion", Short: "Output completion code for the specified shell (bash or zsh)", - Long: strings.TrimLeft(dedent.Dedent(fmt.Sprint(` + Long: cmdutil.LongDescription(` Outputs cca shell completion for the given shell (bash or zsh) This depends on the bash-completion binary. Example installation instructions: @@ -46,7 +42,7 @@ func NewCommand(gf *cmdutil.GlobalFlags) *cobra.Command { Additionally, you may want to output the completion to a file and source in your .bashrc Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2 - `)), "\n"), + `), } cmd.AddCommand(zsh.NewCommand(gf)) diff --git a/pkg/cmdutil/description.go b/pkg/cmdutil/description.go new file mode 100644 index 0000000..a4b0737 --- /dev/null +++ b/pkg/cmdutil/description.go @@ -0,0 +1,14 @@ +package cmdutil + +import ( + "fmt" + "strings" + + "github.com/lithammer/dedent" +) + +// LongDescription formats long multi-line description and removes +// the left empty space from the lines +func LongDescription(a interface{}) string { + return strings.TrimLeft(dedent.Dedent(fmt.Sprint(a)), "\n") +}