mirror of https://github.com/hashicorp/consul
commands: move snapshot inspect command to separate pkg
parent
c8992cbe28
commit
3a02ce9ebc
|
@ -36,8 +36,9 @@ import (
|
|||
"github.com/hashicorp/consul/command/operraftremove"
|
||||
"github.com/hashicorp/consul/command/reload"
|
||||
"github.com/hashicorp/consul/command/rtt"
|
||||
"github.com/hashicorp/consul/command/snapshot"
|
||||
"github.com/hashicorp/consul/command/snapshotinspect"
|
||||
"github.com/hashicorp/consul/command/validate"
|
||||
"github.com/hashicorp/consul/snapshot"
|
||||
"github.com/hashicorp/consul/version"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
@ -210,12 +211,7 @@ func init() {
|
|||
},
|
||||
|
||||
"snapshot inspect": func() (cli.Command, error) {
|
||||
return &SnapshotInspectCommand{
|
||||
BaseCommand: BaseCommand{
|
||||
Flags: FlagSetNone,
|
||||
UI: ui,
|
||||
},
|
||||
}, nil
|
||||
return snapshotinspect.New(ui), nil
|
||||
},
|
||||
|
||||
"validate": func() (cli.Command, error) {
|
||||
|
|
|
@ -1,44 +1,50 @@
|
|||
package command
|
||||
package snapshotinspect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/hashicorp/consul/command/flags"
|
||||
"github.com/hashicorp/consul/snapshot"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
// SnapshotInspectCommand is a Command implementation that is used to display
|
||||
// metadata about a snapshot file
|
||||
type SnapshotInspectCommand struct {
|
||||
BaseCommand
|
||||
func New(ui cli.Ui) *cmd {
|
||||
c := &cmd{UI: ui}
|
||||
c.init()
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *SnapshotInspectCommand) Help() string {
|
||||
c.InitFlagSet()
|
||||
return c.HelpCommand(`
|
||||
Usage: consul snapshot inspect [options] FILE
|
||||
|
||||
Displays information about a snapshot file on disk.
|
||||
|
||||
To inspect the file "backup.snap":
|
||||
|
||||
$ consul snapshot inspect backup.snap
|
||||
|
||||
For a full list of options and examples, please see the Consul documentation.
|
||||
`)
|
||||
type cmd struct {
|
||||
UI cli.Ui
|
||||
flags *flag.FlagSet
|
||||
usage string
|
||||
}
|
||||
|
||||
func (c *SnapshotInspectCommand) Run(args []string) int {
|
||||
c.InitFlagSet()
|
||||
if err := c.FlagSet.Parse(args); err != nil {
|
||||
func (c *cmd) init() {
|
||||
c.flags = flag.NewFlagSet("", flag.ContinueOnError)
|
||||
c.usage = flags.Usage(usage, c.flags, nil, nil)
|
||||
}
|
||||
|
||||
func (c *cmd) Synopsis() string {
|
||||
return "Displays information about a Consul snapshot file"
|
||||
}
|
||||
|
||||
func (c *cmd) Help() string {
|
||||
return c.usage
|
||||
}
|
||||
|
||||
func (c *cmd) Run(args []string) int {
|
||||
if err := c.flags.Parse(args); err != nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
var file string
|
||||
|
||||
args = c.FlagSet.Args()
|
||||
args = c.flags.Args()
|
||||
switch len(args) {
|
||||
case 0:
|
||||
c.UI.Error("Missing FILE argument")
|
||||
|
@ -79,6 +85,12 @@ func (c *SnapshotInspectCommand) Run(args []string) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func (c *SnapshotInspectCommand) Synopsis() string {
|
||||
return "Displays information about a Consul snapshot file"
|
||||
}
|
||||
const usage = `Usage: consul snapshot inspect [options] FILE
|
||||
|
||||
Displays information about a snapshot file on disk.
|
||||
|
||||
To inspect the file "backup.snap":
|
||||
|
||||
$ consul snapshot inspect backup.snap
|
||||
|
||||
For a full list of options and examples, please see the Consul documentation.`
|
|
@ -1,4 +1,4 @@
|
|||
package command
|
||||
package snapshotinspect
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
@ -12,29 +12,17 @@ import (
|
|||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
func testSnapshotInspectCommand(t *testing.T) (*cli.MockUi, *SnapshotInspectCommand) {
|
||||
ui := cli.NewMockUi()
|
||||
return ui, &SnapshotInspectCommand{
|
||||
BaseCommand: BaseCommand{
|
||||
UI: ui,
|
||||
Flags: FlagSetNone,
|
||||
},
|
||||
func TestSnapshotInpectCommand_noTabs(t *testing.T) {
|
||||
t.Parallel()
|
||||
if strings.ContainsRune(New(cli.NewMockUi()).Help(), '\t') {
|
||||
t.Fatal("usage has tabs")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSnapshotInspectCommand_implements(t *testing.T) {
|
||||
t.Parallel()
|
||||
var _ cli.Command = &SnapshotInspectCommand{}
|
||||
}
|
||||
|
||||
func TestSnapshotInspectCommand_noTabs(t *testing.T) {
|
||||
t.Parallel()
|
||||
assertNoTabs(t, new(SnapshotInspectCommand))
|
||||
}
|
||||
|
||||
func TestSnapshotInspectCommand_Validation(t *testing.T) {
|
||||
t.Parallel()
|
||||
ui, c := testSnapshotInspectCommand(t)
|
||||
ui := cli.NewMockUi()
|
||||
c := New(ui)
|
||||
|
||||
cases := map[string]struct {
|
||||
args []string
|
||||
|
@ -102,7 +90,8 @@ func TestSnapshotInspectCommand_Run(t *testing.T) {
|
|||
}
|
||||
|
||||
// Inspect the snapshot
|
||||
ui, c := testSnapshotInspectCommand(t)
|
||||
ui := cli.NewMockUi()
|
||||
c := New(ui)
|
||||
args := []string{file}
|
||||
|
||||
code := c.Run(args)
|
Loading…
Reference in New Issue