diff --git a/main.go b/main.go index e88644e..fc3ad90 100644 --- a/main.go +++ b/main.go @@ -297,6 +297,7 @@ func run() (exitCode int) { registerAuthCommands(configDir) registerCustomerContextCommands(configDir) registerUpgradeCommand(configDir) + registerVersionCommand() registerSkillCommands() // Unhide the customer-context command for DoiT employees so it appears in help. if cachedTokenIsDoer() { @@ -1118,6 +1119,17 @@ func registerStatusCommands(configDir string) { }) } +func registerVersionCommand() { + cli.Root.AddCommand(&cobra.Command{ + Use: "version", + Short: "Print the DCI CLI version", + Args: cobra.NoArgs, + Run: func(cmd *cobra.Command, args []string) { + fmt.Fprintln(os.Stdout, version) + }, + }) +} + // applyAPIKeyAuth injects DCI_API_KEY into restish's auth cache as a Bearer // token. Restish's OAuth TokenHandler checks the cache before triggering a // browser flow, so pre-populating it bypasses interactive login. We use diff --git a/main_test.go b/main_test.go index 0c1c388..6910ccd 100644 --- a/main_test.go +++ b/main_test.go @@ -107,6 +107,22 @@ func TestNormalizeArgs(t *testing.T) { } } +func TestRegisterVersionCommand(t *testing.T) { + setupTestRoot(t) + registerVersionCommand() + + command, _, err := cli.Root.Find([]string{"version"}) + if err != nil { + t.Fatal(err) + } + if command.Name() != "version" { + t.Fatalf("command = %q, want version", command.Name()) + } + if command.Short != "Print the DCI CLI version" { + t.Fatalf("short description = %q", command.Short) + } +} + func TestRejectProfileFlags(t *testing.T) { setupTestRoot(t)