cli: refactor to allow definition of subcommands next to their implementation
This commit is contained in:
+32
-4
@@ -1,8 +1,36 @@
|
||||
package client
|
||||
|
||||
import "github.com/zrepl/zrepl/config"
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/kr/pretty"
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/zrepl/yaml-config"
|
||||
"github.com/zrepl/zrepl/cli"
|
||||
"os"
|
||||
)
|
||||
|
||||
func RunConfigcheck(conf *config.Config, args []string) error {
|
||||
// TODO: do the 'build' steps, e.g. build the jobs and see if that fails
|
||||
return nil
|
||||
var configcheckArgs struct {
|
||||
format string
|
||||
}
|
||||
|
||||
var ConfigcheckCmd = &cli.Subcommand{
|
||||
Use: "configcheck",
|
||||
Short: "check if config can be parsed without errors",
|
||||
SetupFlags: func(f *pflag.FlagSet) {
|
||||
f.StringVar(&configcheckArgs.format, "format", "", "dump parsed config object [pretty|yaml|json]")
|
||||
},
|
||||
Run: func(subcommand *cli.Subcommand, args []string) error {
|
||||
switch configcheckArgs.format {
|
||||
case "pretty":
|
||||
_, err := pretty.Println(subcommand.Config())
|
||||
return err
|
||||
case "json":
|
||||
return json.NewEncoder(os.Stdout).Encode(subcommand.Config())
|
||||
case "yaml":
|
||||
return yaml.NewEncoder(os.Stdout).Encode(subcommand.Config())
|
||||
default: // no output
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user