mirror of
https://github.com/status-im/nim-confutils.git
synced 2025-02-03 07:43:55 +00:00
Allow specifying a description for sub-commands
This commit is contained in:
parent
0bdfb3786c
commit
f354a3ef61
@ -29,8 +29,8 @@ type
|
|||||||
|
|
||||||
CmdInfo = ref object
|
CmdInfo = ref object
|
||||||
name: string
|
name: string
|
||||||
|
desc: string
|
||||||
opts: seq[OptInfo]
|
opts: seq[OptInfo]
|
||||||
shortHelpString: string
|
|
||||||
|
|
||||||
OptKind = enum
|
OptKind = enum
|
||||||
Discriminator
|
Discriminator
|
||||||
@ -233,6 +233,9 @@ proc describeInvocation(help: var string,
|
|||||||
|
|
||||||
helpOutput "\p"
|
helpOutput "\p"
|
||||||
|
|
||||||
|
if cmd.desc.len > 0:
|
||||||
|
helpOutput "\p ", cmd.desc, "\p"
|
||||||
|
|
||||||
for arg in cmd.args:
|
for arg in cmd.args:
|
||||||
if arg.desc.len > 0:
|
if arg.desc.len > 0:
|
||||||
let cliArg = "<" & arg.humaneName & ">"
|
let cliArg = "<" & arg.humaneName & ">"
|
||||||
@ -644,10 +647,16 @@ macro buildCommandTree(RecordType: type): untyped =
|
|||||||
opt.isCommand = field.readPragma"command" != nil
|
opt.isCommand = field.readPragma"command" != nil
|
||||||
|
|
||||||
for i in 1 ..< cmdType.len:
|
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):
|
if defaultValue != nil and eqIdent(name, defaultValue):
|
||||||
opt.defaultSubCmd = i - 1
|
opt.defaultSubCmd = i - 1
|
||||||
opt.subCmds.add CmdInfo(name: name)
|
opt.subCmds.add CmdInfo(name: name, desc: desc)
|
||||||
|
|
||||||
if defaultValue == nil:
|
if defaultValue == nil:
|
||||||
opt.defaultSubCmd = -1
|
opt.defaultSubCmd = -1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user