Allow specifying a description for sub-commands

This commit is contained in:
Zahary Karadjov 2020-03-10 13:38:29 +02:00
parent 0bdfb3786c
commit f354a3ef61
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609

View File

@ -29,8 +29,8 @@ type
CmdInfo = ref object
name: string
desc: string
opts: seq[OptInfo]
shortHelpString: string
OptKind = enum
Discriminator
@ -233,6 +233,9 @@ proc describeInvocation(help: var string,
helpOutput "\p"
if cmd.desc.len > 0:
helpOutput "\p ", cmd.desc, "\p"
for arg in cmd.args:
if arg.desc.len > 0:
let cliArg = "<" & arg.humaneName & ">"
@ -644,10 +647,16 @@ macro buildCommandTree(RecordType: type): untyped =
opt.isCommand = field.readPragma"command" != nil
for i in 1 ..< cmdType.len:
let name = $cmdType[i]
let enumVal = cmdType[i]
var name, desc: string
if enumVal.kind == nnkEnumFieldDef:
name = $enumVal[0]
desc = $enumVal[1]
else:
name = $enumVal
if defaultValue != nil and eqIdent(name, defaultValue):
opt.defaultSubCmd = i - 1
opt.subCmds.add CmdInfo(name: name)
opt.subCmds.add CmdInfo(name: name, desc: desc)
if defaultValue == nil:
opt.defaultSubCmd = -1