Skip to content

Commit d8757b6

Browse files
committed
fix(param/cli): exit app if meet unknown option from config
1 parent 787044e commit d8757b6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/param/cli.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func doParseCli() []*Param {
198198
undefs := result.GetUndefs()
199199
if len(undefs) > 0 {
200200
fmt.Println("unknown option:", strings.Join(undefs, " "))
201-
os.Exit(0)
201+
os.Exit(1)
202202
}
203203

204204
// version
@@ -218,11 +218,11 @@ func doParseCli() []*Param {
218218
configs := []string{}
219219
groupSeps := cliCmd.Options().GroupSeps()[0]
220220
foundConfig := false
221-
for _, result := range results {
221+
for i := range results {
222222
configs = append(configs, groupSeps)
223223

224224
// config file
225-
config, _ := result.GetString("config")
225+
config, _ := results[i].GetString("config")
226226
if len(config) == 0 {
227227
continue
228228
}
@@ -244,6 +244,13 @@ func doParseCli() []*Param {
244244
if foundConfig {
245245
configs = configs[1:]
246246
results = cliCmd.ParseGroups(args, configs)
247+
for i := range results {
248+
undefs := results[i].GetUndefs()
249+
if len(undefs) > 0 {
250+
fmt.Println("unknown option from config:", strings.Join(undefs, " "))
251+
os.Exit(1)
252+
}
253+
}
247254
}
248255

249256
// init param data

0 commit comments

Comments
 (0)