diff --git a/pkg/cmd/version/version.go b/pkg/cmd/version/version.go index 040a3132e..d473ab0b2 100644 --- a/pkg/cmd/version/version.go +++ b/pkg/cmd/version/version.go @@ -26,11 +26,12 @@ func NewCmdVersion(f *cmdutil.Factory, version, buildDate string) *cobra.Command func Format(version, buildDate string) string { version = strings.TrimPrefix(version, "v") + var dateStr string if buildDate != "" { - version = fmt.Sprintf("%s (%s)", version, buildDate) + dateStr = fmt.Sprintf(" (%s)", buildDate) } - return fmt.Sprintf("gh version %s\n%s\n", version, changelogURL(version)) + return fmt.Sprintf("gh version %s%s\n%s\n", version, dateStr, changelogURL(version)) } func changelogURL(version string) string { diff --git a/pkg/cmd/version/version_test.go b/pkg/cmd/version/version_test.go index 9a1d49db3..be1065dfd 100644 --- a/pkg/cmd/version/version_test.go +++ b/pkg/cmd/version/version_test.go @@ -4,6 +4,13 @@ import ( "testing" ) +func TestFormat(t *testing.T) { + expects := "gh version 1.4.0 (2020-12-15)\nhttps://github.com/cli/cli/releases/tag/v1.4.0\n" + if got := Format("1.4.0", "2020-12-15"); got != expects { + t.Errorf("Format() = %q, wants %q", got, expects) + } +} + func TestChangelogURL(t *testing.T) { tag := "0.3.2" url := "https://github.com/cli/cli/releases/tag/v0.3.2"