linlib

Types

UnknownFlag = object of CatchableError
DuplicateName = object of CatchableError
SkipSignal = object of CatchableError
Sequence = ref object
  lin: Lin
  name: string
  help: string
  reverse: bool
  includes: seq[string]
Variable = ref object
  name: string
  help: string
  case kind*: VarKind
  of StringVar:
      strVal*: string

  of BooleanVar:
      boolVal*: bool

  
SubprocessError = object of CatchableError

Procs

proc newLin(): Lin {...}{.raises: [], tags: [].}
Make a new Lin. Typically, you should just use the singleton built-in to the library. This is mostly here for testing.
proc sequence(lin: Lin; name: string; help = ""; reverse = false;
             includes: seq[string] = @[]; default = false): Sequence {...}{.raises: [],
    tags: [].}
proc seqname(x: string): string {...}{.inline, raises: [], tags: [].}
proc collectSteps(lin: Lin; keys: openArray[string]): seq[Step] {...}{.
    raises: [KeyError, ValueError, Exception], tags: [RootEffect].}
List the steps that will be run
proc listSteps(lin: Lin; keys: openArray[string]): seq[string] {...}{.
    raises: [KeyError, ValueError, Exception], tags: [RootEffect].}
List step names that will be run
proc helptext(lin: Lin): string {...}{.raises: [ValueError], tags: [].}
Return the block of helptext for the particular context
proc strVar(lin: Lin; name: string; default = ""; help = ""): Variable {...}{.
    raises: [RegexError, ValueError, DuplicateName], tags: [].}
Define a new variable that can be used in build steps
proc boolVar(lin: Lin; name: string; help = ""): Variable {...}{.
    raises: [RegexError, ValueError, DuplicateName], tags: [].}
Define a new boolean flag
proc extractVarFlags(lin: Lin; params: openArray[string]): seq[string] {...}{.
    raises: [KeyError, UnknownFlag], tags: [].}
Remove --var-flags from a sequence of command-line args
proc fullname(s: Step): string {...}{.inline, raises: [], tags: [].}
proc run(lin: Lin; args: openArray[string]): bool {...}{.
    raises: [IOError, KeyError, ValueError, Exception],
    tags: [WriteIOEffect, RootEffect, TimeEffect].}
proc cli(lin: Lin) {...}{.raises: [ValueError, KeyError, UnknownFlag, Exception, IOError],
                  tags: [ReadIOEffect, RootEffect, WriteIOEffect, TimeEffect].}
proc run(args: seq[string]): RunResult {...}{.raises: [IOError, ValueError, OSError,
    Exception], tags: [WriteIOEffect, ExecIOEffect, ReadEnvEffect, RootEffect].}
proc sh(args: varargs[string]) {...}{.raises: [IOError, ValueError, OSError, Exception,
                                      SubprocessError], tags: [WriteIOEffect,
    ExecIOEffect, ReadEnvEffect, RootEffect].}
Run a subprocess, failing if it fails
proc shmaybe(args: varargs[string]) {...}{.raises: [IOError, ValueError, OSError, Exception], tags: [
    WriteIOEffect, ExecIOEffect, ReadEnvEffect, RootEffect].}
Run a subprocess, ignoring exit code
proc skip(reason = "") {...}{.raises: [SkipSignal], tags: [].}
proc olderThan(output: openArray[string]; input: openArray[string]): bool {...}{.
    raises: [CatchableError], tags: [].}
Returns true if any src is newer than the oldest targets.
import nake, os

let
  src = @["prog.nim", "prog2.nim"]
  dst = @["prog.out", "prog_stats.txt"]
if dst.olderThan(src):
   echo "Refreshing ..."
   # do something to generate the outputs
else:
   echo "All done!"
proc olderThan(output: string; input: openArray[string]): bool {...}{.inline,
    raises: [CatchableError], tags: [].}
proc olderThan(output: openArray[string]; input: string): bool {...}{.inline,
    raises: [CatchableError], tags: [].}
proc olderThan(output: string; input: string): bool {...}{.inline, raises: [CatchableError],
    tags: [].}

Templates

template step(s: Sequence; nm: string; fun: untyped)
template cd(newdir: string; body: untyped): untyped
Do some code within a new directory