Skip to content

Commit

Permalink
Some steps towards fixing #19
Browse files Browse the repository at this point in the history
  • Loading branch information
zah committed May 16, 2021
1 parent 66a17f6 commit d1a45cf
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions confutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type
OptInfo = ref object
name, abbr, desc, typename: string
idx: int
hasDefault: bool
isHidden: bool
defaultValue: string
case kind: OptKind
of Discriminator:
isCommand: bool
Expand Down Expand Up @@ -126,6 +126,7 @@ else:

const
fgSection = fgYellow
fgDefault = fgWhite
fgCommand = fgCyan
fgOption = fgBlue
fgArg = fgBlue
Expand Down Expand Up @@ -207,6 +208,9 @@ func hasAbbrs(cmd: CmdInfo): bool =
if hasAbbrs(subCmd):
return true

template hasDefault(opt: OptInfo): bool =
opt.defaultValue.len > 0

func humaneName(opt: OptInfo): string =
if opt.name.len > 0: opt.name
else: opt.abbr
Expand Down Expand Up @@ -315,6 +319,10 @@ proc describeOptions(help: var string,

if i == opt.defaultSubCmd: helpOutput " (default)"
help.describeOptions subCmd, cmdInvocation, appInfo, conditionalOpts
else:
if opt.hasDefault:
helpOutput spaces(7 + appInfo.namesWidth)
helpOutput fgDefault, "default value: ", fgWhite, styleBright, opt.defaultValue, "\p"

let subCmdDiscriminator = cmd.getSubCmdDiscriminator
if subCmdDiscriminator != nil:
Expand Down Expand Up @@ -674,7 +682,8 @@ proc cmdInfoFromType(T: NimNode): CmdInfo =
idx: fieldIdx,
name: $field.name,
isHidden: isHidden,
hasDefault: defaultValue != nil,
defaultValue: if defaultValue == nil: ""
else: repr(defaultValue),
typename: field.typ.repr)

if desc != nil: opt.desc = desc.strVal
Expand Down

0 comments on commit d1a45cf

Please sign in to comment.