Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pkg/cmd/root/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"regexp"
"strings"

version "github.com/OctopusDeploy/cli"
"github.com/OctopusDeploy/cli/pkg/constants"
"github.com/OctopusDeploy/cli/pkg/constants/annotations"
"github.com/OctopusDeploy/cli/pkg/output"
Expand All @@ -24,6 +25,20 @@ func rootHelpFunc(cmd *cobra.Command, _ []string) {
libraryCmds := []string{}
infrastructureCmds := []string{}
additionalCmds := []string{}

flags := cmd.Flags()

if isRootCmd(cmd) {
out := cmd.OutOrStdout()
if versionVal, err := flags.GetBool(constants.FlagHelp); err == nil && versionVal {
fmt.Fprintln(out, strings.TrimSpace(version.Version))
return
} else if err != nil {
fmt.Fprintln(out, err)
return
}
}

for _, c := range cmd.Commands() {
if c.Short == "" {
continue
Expand Down Expand Up @@ -119,7 +134,7 @@ func rootHelpFunc(cmd *cobra.Command, _ []string) {
}

func calculatePadding(cmd *cobra.Command) int {
namePadding:= 12
namePadding := 12
for _, c := range cmd.Commands() {
if len(c.Name()) > namePadding {
namePadding = len(c.Name()) + 2
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,7 @@ func NewCmdRoot(f factory.Factory, clientFactory apiclient.ClientFactory, askPro
}
}

cmd.Flags().Bool(constants.FlagVersion, false, "Show version")

return cmd
}
1 change: 1 addition & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const (

// flags for command line switches
const (
FlagVersion = "version"
FlagHelp = "help"
FlagSpace = "space"
FlagOutputFormat = "output-format"
Expand Down