This is a module of utility procs that might be more broadly useful than only cligen.nim activity.
Procs
proc collectComments(buf: var string; n: NimNode; depth: int = 0) {....raises: [], tags: [], forbids: [].}
- Extract doc comments from the return value of .getImpl
proc findByName(parId: NimNode; fpars: NimNode): int {....raises: [], tags: [], forbids: [].}
- formal param slot of named parameter
proc fromNimble(nimbleContents: string; field: string): string {....raises: [], tags: [], forbids: [].}
- const x=staticRead "relPathToNimbleFile"; use fromNimble(x, "version")
proc has(ns: seq[NimNode]; n: NimNode): bool {....raises: [], tags: [], forbids: [].}
proc maybeDestrop(id: NimNode): NimNode {....raises: [], tags: [], forbids: [].}
- Used to remove stropping backticks ``, if present, from an ident node
proc newParam(id: string; rhs: NimNode): NimNode {....raises: [], tags: [], forbids: [].}
- Construct a keyword argument/named parameter expression for passing
proc paramPresent(n: NimNode; kwArg: string): bool {....raises: [], tags: [], forbids: [].}
- Check if a particular keyword argument parameter is present
proc paramVal(n: NimNode; kwArg: string): NimNode {....raises: [], tags: [], forbids: [].}
- Get the FIRST RHS/value of a keyword argument/named parameter
proc srcBaseName(n: NimNode; sfx = ".nim"): NimNode {....raises: [], tags: [], forbids: [].}
- Get the base name of the source file being compiled as an nnkStrLit
proc srcData(n: NimNode): string {....raises: [], tags: [], forbids: [].}
- The entire file contents of source defining n.
proc srcPath(n: NimNode): string {....raises: [], tags: [], forbids: [].}
proc summaryOfModule(n: NimNode): string {....raises: [], tags: [], forbids: [].}
proc summaryOfModule(sourceContents: string): string {....raises: [], tags: [], forbids: [].}
- First paragraph of doc comment for module defining sourceContents (or empty string); Used to default ["multi",doc].
proc toIdSeq(strSeqInitializer: NimNode): seq[NimNode] {....raises: [], tags: [], forbids: [].}
- Get a compile-time seq[ident] from a symbol or literal @[ "a", .. ].
proc toInt(n: NimNode): int {....raises: [], tags: [], forbids: [].}
- Get compile-time int from a symbol or literal.
proc toString(n: NimNode): string {....raises: [], tags: [], forbids: [].}
- Get compile-time string from a symbol or literal.
proc toStrIni(c: range[0 .. 255]): NimNode {....raises: [], tags: [], forbids: [].}
- Transform a literal 'x' into string literal initializer "x"
proc toStrSeq(strSeqInitializer: NimNode): seq[string] {....raises: [], tags: [], forbids: [].}
- Transform a literal @[ "a", .. ] into compile-time seq[string]
proc versionFromNimble(nimbleContents: string): string {....deprecated: "Deprecated since v0.9.31; use fromNimble(...,\"version\") instead.", raises: [], tags: [], forbids: [].}
- const foo = staticRead "relPathToDotNimbleFile"; use versionFromNimble(foo)
Macros
macro callsOn(routineFirstsRest: varargs[untyped]): untyped
- callsOn f, [a, b,..], y, z, .. generates f(a,y,z,..); f(b,y,z,..); ... You can use (), [], or {} for the list of first arguments.
macro docCommentAdd(s: static string): untyped
- This can be used to add doc comment nodes from compile-time computations. E.g., if const vsn=staticExec("git describe --tags HEAD") somewhere then you can say docCommentAdd(vsn) before|after the top-of-proc doc comment to get a version string into the main help text for a cligen-wrapped proc.
macro docFromModuleOf(sym: typed{nkSym}): untyped
- Used to default ["multi",doc=docFromModuleOf(mySymbol)].
macro docFromProc(sym: typed{nkSym}): untyped
macro with(ob: typed; fields: untyped; body: untyped): untyped
- Usage with(ob, [ f1, f2, ... ]): body where ob is any expression with (unquoted) fields f1, f2, ... and body is a code block which will be given templates named f1, f2, ... providing abbreviated access to ob.