Browse Source

Add -quiet flag to validate

pull/2732/head
Kyle Havlovitz 8 years ago
parent
commit
2aebff3bd3
No known key found for this signature in database
GPG Key ID: 8A5E6B173056AD6C
  1. 7
      command/validate.go
  2. 19
      command/validate_test.go

7
command/validate.go

@ -33,6 +33,7 @@ Usage: consul validate [options] FILE_OR_DIRECTORY...
func (c *ValidateCommand) Run(args []string) int {
var configFiles []string
var quiet bool
f := c.Command.NewFlagSet(c)
f.Var((*agent.AppendSliceValue)(&configFiles), "config-file",
@ -40,6 +41,8 @@ func (c *ValidateCommand) Run(args []string) int {
f.Var((*agent.AppendSliceValue)(&configFiles), "config-dir",
"Path to a directory to read configuration files from. This will read every file ending in "+
".json as configuration in this directory in alphabetical order.")
f.BoolVar(&quiet, "quiet", false,
"When given, a successful run will produce no output.")
c.Command.HideFlags("config-file", "config-dir")
if err := c.Command.Parse(args); err != nil {
@ -61,7 +64,9 @@ func (c *ValidateCommand) Run(args []string) int {
return 1
}
c.Ui.Output("Configuration is valid!")
if !quiet {
c.Ui.Output("Configuration is valid!")
}
return 0
}

19
command/validate_test.go

@ -119,3 +119,22 @@ func TestValidateCommandSucceedOnConfigDirWithEmptyFile(t *testing.T) {
t.Fatalf("bad: %d", code)
}
}
func TestValidateCommandQuiet(t *testing.T) {
td, err := ioutil.TempDir("", "consul")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.RemoveAll(td)
ui, cmd := testValidateCommand(t)
args := []string{"-quiet", td}
if code := cmd.Run(args); code != 0 {
t.Fatalf("bad: %d, %s", code, ui.ErrorWriter.String())
}
if ui.OutputWriter.String() != "<nil>" {
t.Fatalf("bad: %v", ui.OutputWriter.String())
}
}

Loading…
Cancel
Save