mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2024-12-21 18:50:44 -06:00
add node to flag definition
This commit is contained in:
parent
b6a97899fc
commit
88a0bc2ffe
3 changed files with 15 additions and 6 deletions
|
@ -159,6 +159,7 @@ type
|
||||||
ident*: NimNode
|
ident*: NimNode
|
||||||
default*: NimNode
|
default*: NimNode
|
||||||
typeNode*: NimNode
|
typeNode*: NimNode
|
||||||
|
node*: NimNode
|
||||||
short*: char
|
short*: char
|
||||||
long*: string
|
long*: string
|
||||||
help*: NimNode
|
help*: NimNode
|
||||||
|
@ -256,12 +257,14 @@ func parseFlagParams(f: var CliFlag, node: NimNode) =
|
||||||
f.ident = getFlagParamNode(n).strVal.ident
|
f.ident = getFlagParamNode(n).strVal.ident
|
||||||
of "T":
|
of "T":
|
||||||
f.typeNode = n[1]
|
f.typeNode = n[1]
|
||||||
|
of "node":
|
||||||
|
f.node = n[1]
|
||||||
else:
|
else:
|
||||||
error "unexpected setting: " & n[0].strVal
|
error "unexpected setting: " & n[0].strVal
|
||||||
else:
|
else:
|
||||||
bad(n, "flag params")
|
bad(n, "flag params")
|
||||||
|
|
||||||
func startFlag(f: var CliFlag, n: NimNode) =
|
func newFlag(f: var CliFlag, n: NimNode) =
|
||||||
f.name =
|
f.name =
|
||||||
case n[0].kind
|
case n[0].kind
|
||||||
of nnkIdent, nnkStrLit: n[0].strVal
|
of nnkIdent, nnkStrLit: n[0].strVal
|
||||||
|
@ -280,7 +283,7 @@ func parseCliFlag(n: NimNode): CliFlag =
|
||||||
if n.kind notin [nnkCommand, nnkCall]:
|
if n.kind notin [nnkCommand, nnkCall]:
|
||||||
bad(n, "flags")
|
bad(n, "flags")
|
||||||
|
|
||||||
startFlag(result, n)
|
newFlag(result, n)
|
||||||
# option "some help desc"
|
# option "some help desc"
|
||||||
if n.kind == nnkCommand:
|
if n.kind == nnkCommand:
|
||||||
result.help = n[1]
|
result.help = n[1]
|
||||||
|
@ -761,9 +764,11 @@ func shortLongCaseStmt(cfg: CliCfg, printHelpName: NimNode, version: NimNode): N
|
||||||
if f.short != '\x00': branch.add(newLit($f.short))
|
if f.short != '\x00': branch.add(newLit($f.short))
|
||||||
let varName = f.ident
|
let varName = f.ident
|
||||||
let name = newLit(f.name)
|
let name = newLit(f.name)
|
||||||
branch.add quote do:
|
branch.add nnkStmtList.newTree(
|
||||||
flagSet.incl `name`
|
nnkCall.newTree(ident("incl"),ident("flagSet"),name),
|
||||||
parse(p, `varName`)
|
if f.node == nil: nnkCall.newTree(ident"parse", ident"p", varName)
|
||||||
|
else: f.node
|
||||||
|
)
|
||||||
|
|
||||||
caseStmt.add branch
|
caseStmt.add branch
|
||||||
|
|
||||||
|
|
4
test.nim
Normal file
4
test.nim
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import std/macros
|
||||||
|
|
||||||
|
dumpAstGen:
|
||||||
|
incl(flagSet, name)
|
2
todo.md
2
todo.md
|
@ -25,7 +25,7 @@
|
||||||
- [ ] add flag overlap check before case statement generation (after parsing?)
|
- [ ] add flag overlap check before case statement generation (after parsing?)
|
||||||
- [ ] add key-value flag support -> `--setting:a:off`
|
- [ ] add key-value flag support -> `--setting:a:off`
|
||||||
- [ ] add defaultFlagType CliCfg setting
|
- [ ] add defaultFlagType CliCfg setting
|
||||||
- [ ] add node to flagDef to override builtin `parse(p, varName)`
|
- [x] add node to flagDef to override builtin `parse(p, varName)`
|
||||||
|
|
||||||
## features
|
## features
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue