To learn about scripting in Nim see NimScript
Types
ScriptMode {.pure.} = enum Silent, ## Be silent. Verbose, ## Be verbose. Whatif ## Do not run commands, instead just echo what ## would have been done.
- Controls the behaviour of the script. Source Edit
Vars
description: string
- Nimble support: The package's description. Source Edit
installDirs: seq[string] = @[]
- Nimble metadata. Source Edit
installExt: seq[string] = @[]
- Nimble metadata. Source Edit
installFiles: seq[string] = @[]
- Nimble metadata. Source Edit
mode: ScriptMode
- Set this to influence how mkDir, rmDir, rmFile etc. behave Source Edit
packageName = ""
- Nimble support: Set this to the package name. It is usually not required to do that, nims' filename is the default. Source Edit
requiresData: seq[string] = @[]
- Exposes the list of requirements for read and write accesses. Source Edit
Procs
proc delEnv(key: string) {....tags: [WriteIOEffect], raises: [], forbids: [].}
- Deletes the environment variable named key. Source Edit
proc exec(command: string) {....raises: [OSError], tags: [ExecIOEffect, WriteIOEffect], forbids: [].}
-
Executes an external process. If the external process terminates with a non-zero exit code, an OSError exception is raised.
Note: If you need a version of exec that returns the exit code and text output of the command, you can use system.gorgeEx.
Source Edit proc exec(command: string; input: string; cache = "") {....raises: [OSError], tags: [ExecIOEffect, WriteIOEffect], forbids: [].}
- Executes an external process. If the external process terminates with a non-zero exit code, an OSError exception is raised. Source Edit
proc fileExists(filename: string): bool {....tags: [ReadIOEffect], raises: [], forbids: [].}
- Checks if the file exists. Source Edit
proc getCommand(): string {....raises: [], tags: [], forbids: [].}
- Gets the Nim command that the compiler has been invoked with, for example "c", "js", "build", "help". Source Edit
proc getCurrentDir(): string {....raises: [], tags: [], forbids: [].}
- Retrieves the current working directory. Source Edit
proc nimcacheDir(): string {....raises: [], tags: [], forbids: [].}
- Retrieves the location of 'nimcache'. Source Edit
proc paramCount(): int {....raises: [], tags: [], forbids: [].}
- Retrieves the number of command line parameters. Source Edit
proc patchFile(package, filename, replacement: string) {....raises: [], tags: [], forbids: [].}
-
Overrides the location of a given file belonging to the passed package. If the replacement is not an absolute path, the path is interpreted to be local to the Nimscript file that contains the call to patchFile, Nim's --path is not used at all to resolve the filename! The compiler also performs path substitution on replacement.
Example:
patchFile("stdlib", "asyncdispatch", "patches/replacement")
Source Edit proc projectDir(): string {....raises: [], tags: [], forbids: [].}
- Retrieves the absolute directory of the current project Source Edit
proc projectName(): string {....raises: [], tags: [], forbids: [].}
- Retrieves the name of the current project Source Edit
proc projectPath(): string {....raises: [], tags: [], forbids: [].}
- Retrieves the absolute path of the current project Source Edit
proc putEnv(key, val: string) {....tags: [WriteIOEffect], raises: [], forbids: [].}
- Sets the value of the environment variable named key to val. Source Edit
proc readAllFromStdin(): string {....raises: [IOError], tags: [ReadIOEffect], forbids: [].}
- Reads all data from stdin - blocks until EOF which happens when stdin is closed Source Edit
proc readLineFromStdin(): string {....raises: [IOError], tags: [ReadIOEffect], forbids: [].}
- Reads a line of data from stdin - blocks until n or EOF which happens when stdin is closed Source Edit
proc selfExec(command: string) {....raises: [OSError], tags: [ExecIOEffect, WriteIOEffect], forbids: [].}
- Executes an external command with the current nim/nimble executable. Command must not contain the "nim " part. Source Edit
proc setCommand(cmd: string; project = "") {....raises: [], tags: [], forbids: [].}
- Sets the Nim command that should be continued with after this Nimscript has finished. Source Edit
Templates
template task(name: untyped; description: string; body: untyped): untyped
-
Defines a task. Hidden tasks are supported via an empty description.
Example:
task build, "default build is via the C backend": setCommand "c"
For a task named foo, this template generates a proc named fooTask. This is useful if you need to call one task in another in your Nimscript.
Example:
task foo, "foo": # > nim foo echo "Running foo" # Running foo task bar, "bar": # > nim bar echo "Running bar" # Running bar fooTask() # Running foo
Source Edit