Rename variables to match the renamed pragmas
This commit is contained in:
parent
51df90466d
commit
9863f80e96
|
@ -37,7 +37,7 @@ type
|
||||||
Arg
|
Arg
|
||||||
|
|
||||||
OptInfo = ref object
|
OptInfo = ref object
|
||||||
longform, shortform, desc, typename: string
|
name, abbr, desc, typename: string
|
||||||
idx: int
|
idx: int
|
||||||
hasDefault: bool
|
hasDefault: bool
|
||||||
case kind: OptKind
|
case kind: OptKind
|
||||||
|
@ -113,7 +113,7 @@ else:
|
||||||
styledWrite stderr, args
|
styledWrite stderr, args
|
||||||
|
|
||||||
template helpOutput(args: varargs[untyped]) =
|
template helpOutput(args: varargs[untyped]) =
|
||||||
stdout.styledWrite args
|
styledWrite stdout, args
|
||||||
|
|
||||||
template flushHelp =
|
template flushHelp =
|
||||||
discard
|
discard
|
||||||
|
@ -174,7 +174,7 @@ func maxLongformLen(cmd: CmdInfo): int =
|
||||||
for opt in cmd.opts:
|
for opt in cmd.opts:
|
||||||
if opt.kind == Arg or opt.kind == Discriminator and opt.isCommand:
|
if opt.kind == Arg or opt.kind == Discriminator and opt.isCommand:
|
||||||
continue
|
continue
|
||||||
result = max(result, opt.longform.len)
|
result = max(result, opt.name.len)
|
||||||
if opt.kind == Discriminator:
|
if opt.kind == Discriminator:
|
||||||
for subCmd in opt.subCmds:
|
for subCmd in opt.subCmds:
|
||||||
result = max(result, subCmd.maxLongformLen)
|
result = max(result, subCmd.maxLongformLen)
|
||||||
|
@ -183,7 +183,7 @@ func hasShortforms(cmd: CmdInfo): bool =
|
||||||
for opt in cmd.opts:
|
for opt in cmd.opts:
|
||||||
if opt.kind == Arg or opt.kind == Discriminator and opt.isCommand:
|
if opt.kind == Arg or opt.kind == Discriminator and opt.isCommand:
|
||||||
continue
|
continue
|
||||||
if opt.shortform.len > 0:
|
if opt.abbr.len > 0:
|
||||||
return true
|
return true
|
||||||
if opt.kind == Discriminator:
|
if opt.kind == Discriminator:
|
||||||
for subCmd in opt.subCmds:
|
for subCmd in opt.subCmds:
|
||||||
|
@ -191,8 +191,8 @@ func hasShortforms(cmd: CmdInfo): bool =
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func humaneName(opt: OptInfo): string =
|
func humaneName(opt: OptInfo): string =
|
||||||
if opt.longform.len > 0: opt.longform
|
if opt.name.len > 0: opt.name
|
||||||
else: opt.shortform
|
else: opt.abbr
|
||||||
|
|
||||||
template padding(output: string, desiredWidth: int): string =
|
template padding(output: string, desiredWidth: int): string =
|
||||||
spaces(max(desiredWidth - output.len, 0))
|
spaces(max(desiredWidth - output.len, 0))
|
||||||
|
@ -223,8 +223,8 @@ proc describeInvocation(help: var string,
|
||||||
if subCmdDiscriminator != nil: helpOutput " command"
|
if subCmdDiscriminator != nil: helpOutput " command"
|
||||||
|
|
||||||
for arg in cmd.args:
|
for arg in cmd.args:
|
||||||
helpOutput " <", arg.longform, ">"
|
helpOutput " <", arg.name, ">"
|
||||||
longestArg = max(longestArg, arg.longform.len)
|
longestArg = max(longestArg, arg.name.len)
|
||||||
|
|
||||||
helpOutput "\p"
|
helpOutput "\p"
|
||||||
|
|
||||||
|
@ -260,14 +260,14 @@ proc describeOptions(help: var string,
|
||||||
# Indent all command-line switches
|
# Indent all command-line switches
|
||||||
helpOutput " "
|
helpOutput " "
|
||||||
|
|
||||||
if opt.shortform.len > 0:
|
if opt.abbr.len > 0:
|
||||||
helpOutput fgOption, styleBright, "-", opt.shortform, ", "
|
helpOutput fgOption, styleBright, "-", opt.abbr, ", "
|
||||||
elif appInfo.hasShortforms:
|
elif appInfo.hasShortforms:
|
||||||
# Add additional indentatition, so all longforms are aligned
|
# Add additional indentatition, so all longforms are aligned
|
||||||
helpOutput " "
|
helpOutput " "
|
||||||
|
|
||||||
if opt.longform.len > 0:
|
if opt.name.len > 0:
|
||||||
let switch = "--" & opt.longform
|
let switch = "--" & opt.name
|
||||||
helpOutput fgOption, styleBright,
|
helpOutput fgOption, styleBright,
|
||||||
switch, padding(switch, appInfo.longformsWidth)
|
switch, padding(switch, appInfo.longformsWidth)
|
||||||
else:
|
else:
|
||||||
|
@ -345,8 +345,8 @@ proc noMoreArgsError(cmd: CmdInfo): string =
|
||||||
|
|
||||||
proc findOpt(opts: openarray[OptInfo], name: string): OptInfo =
|
proc findOpt(opts: openarray[OptInfo], name: string): OptInfo =
|
||||||
for opt in opts:
|
for opt in opts:
|
||||||
if cmpIgnoreStyle(opt.longform, name) == 0 or
|
if cmpIgnoreStyle(opt.name, name) == 0 or
|
||||||
cmpIgnoreStyle(opt.shortform, name) == 0:
|
cmpIgnoreStyle(opt.abbr, name) == 0:
|
||||||
return opt
|
return opt
|
||||||
|
|
||||||
proc findOpt(activeCmds: openarray[CmdInfo], name: string): OptInfo =
|
proc findOpt(activeCmds: openarray[CmdInfo], name: string): OptInfo =
|
||||||
|
@ -399,7 +399,7 @@ when defined(debugCmdTree):
|
||||||
for subcmd in opt.subCmds:
|
for subcmd in opt.subCmds:
|
||||||
printCmdTree(subcmd, indent + 2)
|
printCmdTree(subcmd, indent + 2)
|
||||||
else:
|
else:
|
||||||
echo blanks, " - ", opt.longform, ": ", opt.typename
|
echo blanks, " - ", opt.name, ": ", opt.typename
|
||||||
|
|
||||||
else:
|
else:
|
||||||
template printCmdTree(cmd: CmdInfo) = discard
|
template printCmdTree(cmd: CmdInfo) = discard
|
||||||
|
@ -611,8 +611,8 @@ macro buildCommandTree(RecordType: type): untyped =
|
||||||
let
|
let
|
||||||
isImplicitlySelectable = field.readPragma"implicitlySelectable" != nil
|
isImplicitlySelectable = field.readPragma"implicitlySelectable" != nil
|
||||||
defaultValue = field.readPragma"defaultValue"
|
defaultValue = field.readPragma"defaultValue"
|
||||||
shortform = field.readPragma"shortform"
|
abbr = field.readPragma"abbr"
|
||||||
longform = field.readPragma"longform"
|
name = field.readPragma"name"
|
||||||
desc = field.readPragma"desc"
|
desc = field.readPragma"desc"
|
||||||
optKind = if field.isDiscriminator: Discriminator
|
optKind = if field.isDiscriminator: Discriminator
|
||||||
elif field.readPragma("argument") != nil: Arg
|
elif field.readPragma("argument") != nil: Arg
|
||||||
|
@ -620,13 +620,13 @@ macro buildCommandTree(RecordType: type): untyped =
|
||||||
|
|
||||||
var opt = OptInfo(kind: optKind,
|
var opt = OptInfo(kind: optKind,
|
||||||
idx: fieldIdx,
|
idx: fieldIdx,
|
||||||
longform: $field.name,
|
name: $field.name,
|
||||||
hasDefault: defaultValue != nil,
|
hasDefault: defaultValue != nil,
|
||||||
typename: field.typ.repr)
|
typename: field.typ.repr)
|
||||||
|
|
||||||
if desc != nil: opt.desc = desc.strVal
|
if desc != nil: opt.desc = desc.strVal
|
||||||
if longform != nil: opt.longform = longform.strVal
|
if name != nil: opt.name = name.strVal
|
||||||
if shortform != nil: opt.shortform = shortform.strVal
|
if abbr != nil: opt.abbr = abbr.strVal
|
||||||
|
|
||||||
inc fieldIdx
|
inc fieldIdx
|
||||||
|
|
||||||
|
@ -733,7 +733,7 @@ proc load*(Configuration: type,
|
||||||
for opt in cmd.opts:
|
for opt in cmd.opts:
|
||||||
if fieldCounters[opt.idx] == 0:
|
if fieldCounters[opt.idx] == 0:
|
||||||
if opt.required:
|
if opt.required:
|
||||||
fail "The required option '$1' was not specified" % [opt.longform]
|
fail "The required option '$1' was not specified" % [opt.name]
|
||||||
elif opt.hasDefault:
|
elif opt.hasDefault:
|
||||||
fieldSetters[opt.idx][1](conf, none[TaintedString]())
|
fieldSetters[opt.idx][1](conf, none[TaintedString]())
|
||||||
|
|
||||||
|
@ -745,8 +745,8 @@ proc load*(Configuration: type,
|
||||||
|
|
||||||
type
|
type
|
||||||
ArgKindFilter = enum
|
ArgKindFilter = enum
|
||||||
longForm
|
argName
|
||||||
shortForm
|
argAbbr
|
||||||
|
|
||||||
when not defined(nimscript):
|
when not defined(nimscript):
|
||||||
proc showMatchingOptions(cmd: CmdInfo, prefix: string, filterKind: set[ArgKindFilter]) =
|
proc showMatchingOptions(cmd: CmdInfo, prefix: string, filterKind: set[ArgKindFilter]) =
|
||||||
|
@ -755,11 +755,11 @@ proc load*(Configuration: type,
|
||||||
if len(prefix) > 0:
|
if len(prefix) > 0:
|
||||||
# Filter the options according to the input prefix
|
# Filter the options according to the input prefix
|
||||||
for opt in cmd.opts:
|
for opt in cmd.opts:
|
||||||
if longForm in filterKind and len(opt.longform) > 0:
|
if argName in filterKind and len(opt.name) > 0:
|
||||||
if startsWithIgnoreStyle(opt.longform, prefix):
|
if startsWithIgnoreStyle(opt.name, prefix):
|
||||||
matchingOptions.add(opt)
|
matchingOptions.add(opt)
|
||||||
if shortForm in filterKind and len(opt.shortform) > 0:
|
if argAbbr in filterKind and len(opt.abbr) > 0:
|
||||||
if startsWithIgnoreStyle(opt.shortform, prefix):
|
if startsWithIgnoreStyle(opt.abbr, prefix):
|
||||||
matchingOptions.add(opt)
|
matchingOptions.add(opt)
|
||||||
else:
|
else:
|
||||||
matchingOptions = cmd.opts
|
matchingOptions = cmd.opts
|
||||||
|
@ -768,10 +768,10 @@ proc load*(Configuration: type,
|
||||||
# The trailing '=' means the switch accepts an argument
|
# The trailing '=' means the switch accepts an argument
|
||||||
let trailing = if opt.typename != "bool": "=" else: ""
|
let trailing = if opt.typename != "bool": "=" else: ""
|
||||||
|
|
||||||
if longForm in filterKind and len(opt.longform) > 0:
|
if argName in filterKind and len(opt.name) > 0:
|
||||||
stdout.writeLine("--", opt.longform, trailing)
|
stdout.writeLine("--", opt.name, trailing)
|
||||||
if shortForm in filterKind and len(opt.shortform) > 0:
|
if argAbbr in filterKind and len(opt.abbr) > 0:
|
||||||
stdout.writeLine('-', opt.shortform, trailing)
|
stdout.writeLine('-', opt.abbr, trailing)
|
||||||
|
|
||||||
let completion = splitCompletionLine()
|
let completion = splitCompletionLine()
|
||||||
# If we're not asked to complete a command line the result is an empty list
|
# If we're not asked to complete a command line the result is an empty list
|
||||||
|
@ -797,13 +797,13 @@ proc load*(Configuration: type,
|
||||||
for i in countdown(cmdStack.len - 1, 0):
|
for i in countdown(cmdStack.len - 1, 0):
|
||||||
let argFilter =
|
let argFilter =
|
||||||
if isLong:
|
if isLong:
|
||||||
{longForm}
|
{argName}
|
||||||
elif len(cur_word) > 1:
|
elif len(cur_word) > 1:
|
||||||
# If the user entered a single hypen then we show both long & short
|
# If the user entered a single hypen then we show both long & short
|
||||||
# variants
|
# variants
|
||||||
{shortForm}
|
{argAbbr}
|
||||||
else:
|
else:
|
||||||
{longForm, shortForm}
|
{argName, argAbbr}
|
||||||
|
|
||||||
showMatchingOptions(cmdStack[i], option_word, argFilter)
|
showMatchingOptions(cmdStack[i], option_word, argFilter)
|
||||||
elif (prev_word.startsWith('-') or
|
elif (prev_word.startsWith('-') or
|
||||||
|
@ -826,7 +826,7 @@ proc load*(Configuration: type,
|
||||||
else:
|
else:
|
||||||
# Full options listing
|
# Full options listing
|
||||||
for i in countdown(cmdStack.len - 1, 0):
|
for i in countdown(cmdStack.len - 1, 0):
|
||||||
showMatchingOptions(cmdStack[i], "", {longForm, shortForm})
|
showMatchingOptions(cmdStack[i], "", {argName, argAbbr})
|
||||||
|
|
||||||
stdout.flushFile()
|
stdout.flushFile()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue