1
0
mirror of https://github.com/rancher/os.git synced 2025-09-01 14:48:55 +00:00

Add command to validate configuration

This commit is contained in:
Josh Curl
2016-11-06 13:41:46 -08:00
parent 33b6145162
commit 25e5ca5e4c
7 changed files with 534 additions and 12 deletions

View File

@@ -76,6 +76,17 @@ func configSubcommands() []cli.Command {
},
},
},
{
Name: "validate",
Usage: "validate configuration from stdin",
Action: validate,
Flags: []cli.Flag{
cli.StringFlag{
Name: "input, i",
Usage: "File from which to read",
},
},
},
}
}
@@ -183,18 +194,7 @@ func configGet(c *cli.Context) error {
}
func merge(c *cli.Context) error {
input := os.Stdin
inputFile := c.String("input")
if inputFile != "" {
var err error
input, err = os.Open(inputFile)
if err != nil {
log.Fatal(err)
}
defer input.Close()
}
bytes, err := ioutil.ReadAll(input)
bytes, err := inputBytes(c)
if err != nil {
log.Fatal(err)
}
@@ -224,3 +224,32 @@ func export(c *cli.Context) error {
return nil
}
func validate(c *cli.Context) error {
bytes, err := inputBytes(c)
if err != nil {
log.Fatal(err)
}
validationErrors, err := config.Validate(bytes)
if err != nil {
log.Fatal(err)
}
for _, validationError := range validationErrors.Errors() {
log.Error(validationError)
}
return nil
}
func inputBytes(c *cli.Context) ([]byte, error) {
input := os.Stdin
inputFile := c.String("input")
if inputFile != "" {
var err error
input, err = os.Open(inputFile)
if err != nil {
return nil, err
}
defer input.Close()
}
return ioutil.ReadAll(input)
}