Allow defaultValueDesc even without defaultValue; Cosmetic changes

This commit is contained in:
Zahary Karadjov 2021-05-17 20:40:57 +03:00
parent 5f2f882151
commit 5f7cfa8d98
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 2 additions and 4 deletions

View File

@ -226,7 +226,7 @@ proc writeDesc(help: var string,
descIndent = (5 + appInfo.namesWidth + descSpacing.len)
remainingColumns = appInfo.terminalWidth - descIndent
defaultValSuffix = if defaultValue.len == 0: ""
else: " [default: " & defaultValue & "]"
else: " [=" & defaultValue & "]"
fullDesc = desc & defaultValSuffix & "."
if remainingColumns < confutils_narrow_terminal_width:
@ -684,14 +684,12 @@ proc cmdInfoFromType(T: NimNode): CmdInfo =
elif field.readPragma("argument") != nil: Arg
else: CliSwitch
if defaultValueDesc != nil and defaultValue == nil:
error "The `defaultValueDesc` pragma cannot be specified without also specifying `defaultValue`", defaultValueDesc
var opt = OptInfo(kind: optKind,
idx: fieldIdx,
name: $field.name,
isHidden: isHidden,
defaultValue: if defaultValueOnScreen == nil: ""
elif defaultValueOnScreen.kind in {nnkStrLit..nnkTripleStrLit}: defaultValueOnScreen.strVal
else: repr(defaultValueOnScreen),
typename: field.typ.repr)