Skip to content
Merged
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
11 changes: 4 additions & 7 deletions cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (

// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "databricks",
Short: "Databricks CLI",
Use: "databricks",
Short: "Databricks CLI",
Version: build.GetInfo().Version,

// Cobra prints the usage string to stderr if a command returns an error.
// This usage string should only be displayed if an invalid combination of flags
Expand Down Expand Up @@ -105,9 +106,5 @@ func Execute() {

func init() {
RootCmd.SetFlagErrorFunc(flagErrorFunc)

// The VS Code extension passes `-v` in debug mode and must be changed
// to use the new flags in `./logger.go` prior to removing this flag.
RootCmd.PersistentFlags().BoolP("verbose", "v", false, "")
RootCmd.PersistentFlags().MarkHidden("verbose")
RootCmd.SetVersionTemplate("Databricks CLI v{{.Version}}\n")
}
4 changes: 2 additions & 2 deletions cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ var versionCmd = &cobra.Command{
return enc.Encode(info)
}

fmt.Fprintln(cmd.OutOrStdout(), info.Version)
return nil
_, err := fmt.Fprintf(cmd.OutOrStdout(), "Databricks CLI v%s\n", info.Version)
return err
},
}

Expand Down
1 change: 1 addition & 0 deletions internal/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/databricks/cli/cmd/root"
_ "github.com/databricks/cli/cmd/version"
"github.com/stretchr/testify/require"
)

Expand Down
29 changes: 29 additions & 0 deletions internal/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package internal

import (
"fmt"
"testing"

"github.com/databricks/cli/internal/build"
"github.com/stretchr/testify/assert"
)

var expectedVersion = fmt.Sprintf("Databricks CLI v%s\n", build.GetInfo().Version)

func TestVersionFlagShort(t *testing.T) {
stdout, stderr := RequireSuccessfulRun(t, "-v")
assert.Equal(t, expectedVersion, stdout.String())
assert.Equal(t, "", stderr.String())
}

func TestVersionFlagLong(t *testing.T) {
stdout, stderr := RequireSuccessfulRun(t, "--version")
assert.Equal(t, expectedVersion, stdout.String())
assert.Equal(t, "", stderr.String())
}

func TestVersionCommand(t *testing.T) {
stdout, stderr := RequireSuccessfulRun(t, "version")
assert.Equal(t, expectedVersion, stdout.String())
assert.Equal(t, "", stderr.String())
}