@@ -334,9 +334,7 @@ proc describeOptionsList(
334334 appInfo: HelpAppInfo
335335) =
336336 for opt in cmd.opts:
337- if opt.kind == Arg or
338- opt.kind == Discriminator or
339- opt.isHidden:
337+ if not opt.isOpt:
340338 continue
341339
342340 if opt.separator.len > 0 :
@@ -367,27 +365,18 @@ proc describeOptionsList(
367365
368366 helpOutput " \p "
369367
370- # TODO : this is not reached: https://github.com/status-im/nim-confutils/issues/39
371- when false :
372- if opt.kind == Discriminator :
373- for i, subCmd in opt.subCmds:
374- if not subCmd.hasOpts: continue
375-
376- helpOutput " \p When " , styleBright, fgBlue, opt.humaneName, resetStyle, " = " , fgGreen, subCmd.name
377-
378- if i == opt.defaultSubCmd: helpOutput " (default)"
379- help.describeOptions subCmd, cmdInvocation, appInfo, conditionalOpts
380-
381368proc describeOptions (
382369 help: var string ,
383- cmd: CmdInfo ,
370+ cmds: openArray [ CmdInfo ] ,
384371 cmdInvocation: string ,
385372 appInfo: HelpAppInfo ,
386- optionsType = normalOpts,
387- activeCmds: openArray [CmdInfo ] = @ []
373+ optionsType = normalOpts
388374) =
389- var hasOpts = cmd.hasOpts
390- for c in activeCmds:
375+ if cmds.len == 0 :
376+ return
377+
378+ var hasOpts = false
379+ for c in cmds:
391380 if c.hasOpts:
392381 hasOpts = true
393382
@@ -400,26 +389,37 @@ proc describeOptions(
400389 of defaultCmdOpts:
401390 discard
402391
403- if activeCmds.len > 0 :
404- for c in activeCmds:
405- describeOptionsList (help, c, appInfo)
406- else :
407- describeOptionsList (help, cmd, appInfo)
392+ for c in cmds:
393+ describeOptionsList (help, c, appInfo)
394+
395+ for c in cmds:
396+ for opt in c.opts:
397+ if opt.isOpt and opt.kind == Discriminator :
398+ for i, subCmd in opt.subCmds:
399+ if not subCmd.hasOpts:
400+ continue
401+
402+ helpOutput " \p When " , styleBright, fgBlue, opt.humaneName, resetStyle, " = " , fgGreen, subCmd.name
403+
404+ if i == opt.defaultSubCmd:
405+ helpOutput " (default)"
406+ help.describeOptions [subCmd], cmdInvocation, appInfo, conditionalOpts
408407
408+ let cmd = cmds[^ 1 ]
409409 let subCmdDiscriminator = cmd.getSubCmdDiscriminator
410410 if subCmdDiscriminator != nil :
411411 let defaultCmdIdx = subCmdDiscriminator.defaultSubCmd
412412 if defaultCmdIdx != - 1 :
413413 let defaultCmd = subCmdDiscriminator.subCmds[defaultCmdIdx]
414- help.describeOptions defaultCmd, cmdInvocation, appInfo, defaultCmdOpts
414+ help.describeOptions [ defaultCmd] , cmdInvocation, appInfo, defaultCmdOpts
415415
416416 helpOutput fgSection, " \p Available sub-commands:\p "
417417
418418 for i, subCmd in subCmdDiscriminator.subCmds:
419419 if i != subCmdDiscriminator.defaultSubCmd:
420420 let subCmdInvocation = cmdInvocation & " " & subCmd.name
421421 help.describeInvocation subCmd, subCmdInvocation, appInfo
422- help.describeOptions subCmd, subCmdInvocation, appInfo
422+ help.describeOptions [ subCmd] , subCmdInvocation, appInfo
423423
424424proc showHelp (help: var string ,
425425 appInfo: HelpAppInfo ,
@@ -448,7 +448,7 @@ proc showHelp(help: var string,
448448 # Write out the app or script name
449449 helpOutput fgSection, " Usage: \p "
450450 help.describeInvocation cmd, cmdInvocation, appInfo
451- help.describeOptions cmd , cmdInvocation, appInfo, activeCmds = activeCmds
451+ help.describeOptions activeCmds , cmdInvocation, appInfo
452452 helpOutput " \p "
453453
454454 flushOutputAndQuit QuitSuccess
0 commit comments