Skip to content

Commit

Permalink
add verify-config flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zakuro9715 committed May 6, 2021
1 parent 1a61f01 commit c682829
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Usage:
Options:
-c config, --config=config Specify config file [default: z.yaml, env: ZCONFIG]
-v, --verbose Enbale verbose log [env: ZVERBOSE]
--verify-config Only verify config. no task will run
--silent Supress output [env: ZSILENT]
-h, --help Print help
-V, --verison Print version
Expand Down Expand Up @@ -104,6 +105,7 @@ func processFlags(nzargs []nzflag.Value) (i int, cfg *config.Config, rconfig *ru

helpFlag := false
verboseFlag := isEnvValTrue(os.Getenv(ENV_KEY_ZVERBOSE))
verifyConfigFlag := false
rconfig = &runner.Config{Silent: isEnvValTrue(os.Getenv(ENV_KEY_ZSILENT))}
for ; i < len(nzargs); i++ {
arg := nzargs[i]
Expand All @@ -123,6 +125,8 @@ func processFlags(nzargs []nzflag.Value) (i int, cfg *config.Config, rconfig *ru
configPath = arg.Flag().Values[0]
case arg.Flag().Name == "silent":
rconfig.Silent = true
case arg.Flag().Name == "verify-config":
verifyConfigFlag = true
default: // unknow flag
goto parse_end
}
Expand Down Expand Up @@ -151,6 +155,12 @@ parse_end:
return
}

if verifyConfigFlag {
// Config is loaded above. So config is valid at here.
code = 0
return
}

code = -1
return
}
Expand Down
5 changes: 5 additions & 0 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,8 @@ func ExampleAlias() {
// Output:
// hello world alias
}

func ExampleVerifyConfig() {
cli.Main([]string{"--verify-config"})
// Output:
}

0 comments on commit c682829

Please sign in to comment.