Update version command
This commit is contained in:
parent
ca6e002235
commit
f7c9fe6d20
|
@ -1,18 +1,55 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/vault/version"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
// Ensure we are implementing the right interfaces.
|
||||
var _ cli.Command = (*VersionCommand)(nil)
|
||||
var _ cli.CommandAutocomplete = (*VersionCommand)(nil)
|
||||
|
||||
// VersionCommand is a Command implementation prints the version.
|
||||
type VersionCommand struct {
|
||||
*BaseCommand
|
||||
|
||||
VersionInfo *version.VersionInfo
|
||||
Ui cli.Ui
|
||||
}
|
||||
|
||||
func (c *VersionCommand) Synopsis() string {
|
||||
return "Prints the Vault CLI version"
|
||||
}
|
||||
|
||||
func (c *VersionCommand) Help() string {
|
||||
return ""
|
||||
helpText := `
|
||||
Usage: vault version
|
||||
|
||||
Prints the version of this Vault CLI. This does not print the target Vault
|
||||
server version.
|
||||
|
||||
Print the version:
|
||||
|
||||
$ vault version
|
||||
|
||||
There are no arguments or flags to this command. Any additional arguments or
|
||||
flags are ignored.
|
||||
`
|
||||
return strings.TrimSpace(helpText)
|
||||
}
|
||||
|
||||
func (c *VersionCommand) Flags() *FlagSets {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *VersionCommand) AutocompleteArgs() complete.Predictor {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *VersionCommand) AutocompleteFlags() complete.Flags {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *VersionCommand) Run(_ []string) int {
|
||||
|
@ -20,10 +57,6 @@ func (c *VersionCommand) Run(_ []string) int {
|
|||
if version.CgoEnabled {
|
||||
out += " (cgo)"
|
||||
}
|
||||
c.Ui.Output(out)
|
||||
c.UI.Output(out)
|
||||
return 0
|
||||
}
|
||||
|
||||
func (c *VersionCommand) Synopsis() string {
|
||||
return "Prints the Vault version"
|
||||
}
|
||||
|
|
|
@ -1,11 +1,48 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/vault/version"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
func TestVersionCommand_implements(t *testing.T) {
|
||||
var _ cli.Command = &VersionCommand{}
|
||||
func testVersionCommand(tb testing.TB) (*cli.MockUi, *VersionCommand) {
|
||||
tb.Helper()
|
||||
|
||||
ui := cli.NewMockUi()
|
||||
return ui, &VersionCommand{
|
||||
VersionInfo: &version.VersionInfo{},
|
||||
BaseCommand: &BaseCommand{
|
||||
UI: ui,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersionCommand_Run(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("output", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ui, cmd := testVersionCommand(t)
|
||||
code := cmd.Run(nil)
|
||||
if exp := 0; code != exp {
|
||||
t.Errorf("expected %d to be %d", code, exp)
|
||||
}
|
||||
|
||||
expected := "Vault"
|
||||
combined := ui.OutputWriter.String() + ui.ErrorWriter.String()
|
||||
if !strings.Contains(combined, expected) {
|
||||
t.Errorf("expected %q to equal %q", combined, expected)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("no_tabs", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, cmd := testVersionCommand(t)
|
||||
assertNoTabs(t, cmd)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue