To learn about scripting in Nim see NimScript
型
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. ソース 編集
変数
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. ソース 編集
version: string
- Nimble support: The package's version. ソース 編集
author: string
- Nimble support: The package's author. ソース 編集
description: string
- Nimble support: The package's description. ソース 編集
license: string
- Nimble support: The package's license. ソース 編集
srcDir: string
- Nimble support: The package's source directory. ソース 編集
binDir: string
- Nimble support: The package's binary directory. ソース 編集
backend: string
- Nimble support: The package's backend. ソース 編集
skipDirs: seq[string] = @[]
- Nimble metadata. ソース 編集
skipFiles: seq[string] = @[]
- Nimble metadata. ソース 編集
skipExt: seq[string] = @[]
- Nimble metadata. ソース 編集
installDirs: seq[string] = @[]
- Nimble metadata. ソース 編集
installFiles: seq[string] = @[]
- Nimble metadata. ソース 編集
installExt: seq[string] = @[]
- Nimble metadata. ソース 編集
bin: seq[string] = @[]
- Nimble metadata. ソース 編集
requiresData: seq[string] = @[]
- Exposes the list of requirements for read and write accesses. ソース 編集
プロシージャ
proc listDirs(dir: string): seq[string] {...}{.raises: [], tags: [].}
- Lists all the subdirectories (non-recursively) in the directory dir. ソース 編集
proc listFiles(dir: string): seq[string] {...}{.raises: [], tags: [].}
- Lists all the files (non-recursively) in the directory dir. ソース 編集
proc getCurrentDir(): string {...}{.raises: [], tags: [].}
- Retrieves the current working directory. ソース 編集
proc paramStr(i: int): string {...}{.raises: [], tags: [].}
- Retrieves the i'th command line parameter. ソース 編集
proc paramCount(): int {...}{.raises: [], tags: [].}
- Retrieves the number of command line parameters. ソース 編集
proc switch(key: string; val = "") {...}{.raises: [], tags: [].}
- Sets a Nim compiler command line switch, for example switch("checks", "on"). ソース 編集
proc warning(name: string; val: bool) {...}{.raises: [], tags: [].}
- Disables or enables a specific warning. ソース 編集
proc hint(name: string; val: bool) {...}{.raises: [], tags: [].}
- Disables or enables a specific hint. ソース 編集
proc patchFile(package, filename, replacement: string) {...}{.raises: [], tags: [].}
-
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!
用例:
patchFile("stdlib", "asyncdispatch", "patches/replacement")
ソース 編集 proc getCommand(): string {...}{.raises: [], tags: [].}
- Gets the Nim command that the compiler has been invoked with, for example "c", "js", "build", "help". ソース 編集
proc setCommand(cmd: string; project = "") {...}{.raises: [], tags: [].}
- Sets the Nim command that should be continued with after this Nimscript has finished. ソース 編集
proc cmpic(a, b: string): int {...}{.raises: [], tags: [].}
- Compares a and b ignoring case. ソース 編集
proc getEnv(key: string; default = ""): string {...}{.tags: [ReadIOEffect], raises: [].}
- Retrieves the environment variable of name key. ソース 編集
proc existsEnv(key: string): bool {...}{.tags: [ReadIOEffect], raises: [].}
- Checks for the existence of an environment variable named key. ソース 編集
proc putEnv(key, val: string) {...}{.tags: [WriteIOEffect], raises: [].}
- Sets the value of the environment variable named key to val. ソース 編集
proc delEnv(key: string) {...}{.tags: [WriteIOEffect], raises: [].}
- Deletes the environment variable named key. ソース 編集
proc fileExists(filename: string): bool {...}{.tags: [ReadIOEffect], raises: [].}
- Checks if the file exists. ソース 編集
proc dirExists(dir: string): bool {...}{.tags: [ReadIOEffect], raises: [].}
- Checks if the directory dir exists. ソース 編集
proc existsFile(filename: string): bool {...}{.raises: [], tags: [ReadIOEffect].}
- An alias for fileExists. ソース 編集
proc existsDir(dir: string): bool {...}{.raises: [], tags: [ReadIOEffect].}
- An alias for dirExists. ソース 編集
proc selfExe(): string {...}{.raises: [], tags: [].}
- Returns the currently running nim or nimble executable. ソース 編集
proc toExe(filename: string): string {...}{.raises: [], tags: [].}
- On Windows adds ".exe" to filename, else returns filename unmodified. ソース 編集
proc toDll(filename: string): string {...}{.raises: [], tags: [].}
- On Windows adds ".dll" to filename, on Posix produces "lib$filename.so". ソース 編集
proc rmDir(dir: string) {...}{.raises: [OSError], tags: [ReadIOEffect, WriteIOEffect].}
- Removes the directory dir. ソース 編集
proc rmFile(file: string) {...}{.raises: [OSError], tags: [ReadIOEffect, WriteIOEffect].}
- Removes the file. ソース 編集
proc mkDir(dir: string) {...}{.raises: [OSError], tags: [WriteIOEffect].}
- Creates the directory dir including all necessary subdirectories. If the directory already exists, no error is raised. ソース 編集
proc mvFile(`from`, to: string) {...}{.raises: [OSError], tags: [ReadIOEffect, WriteIOEffect].}
- Moves the file from to to. ソース 編集
proc mvDir(`from`, to: string) {...}{.raises: [OSError], tags: [ReadIOEffect, WriteIOEffect].}
- Moves the dir from to to. ソース 編集
proc cpFile(`from`, to: string) {...}{.raises: [OSError], tags: [ReadIOEffect, WriteIOEffect].}
- Copies the file from to to. ソース 編集
proc cpDir(`from`, to: string) {...}{.raises: [OSError], tags: [ReadIOEffect, WriteIOEffect].}
- Copies the dir from to to. ソース 編集
proc exec(command: string) {...}{.raises: [OSError], tags: [ExecIOEffect].}
-
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.
ソース 編集 proc exec(command: string; input: string; cache = "") {...}{.raises: [OSError], tags: [ExecIOEffect].}
- Executes an external process. If the external process terminates with a non-zero exit code, an OSError exception is raised. ソース 編集
proc selfExec(command: string) {...}{.raises: [OSError], tags: [ExecIOEffect].}
- Executes an external command with the current nim/nimble executable. Command must not contain the "nim " part. ソース 編集
proc put(key, value: string) {...}{.raises: [], tags: [].}
- Sets a configuration 'key' like 'gcc.options.always' to its value. ソース 編集
proc get(key: string): string {...}{.raises: [], tags: [].}
- Retrieves a configuration 'key' like 'gcc.options.always'. ソース 編集
proc exists(key: string): bool {...}{.raises: [], tags: [].}
- Checks for the existence of a configuration 'key' like 'gcc.options.always'. ソース 編集
proc nimcacheDir(): string {...}{.raises: [], tags: [].}
- Retrieves the location of 'nimcache'. ソース 編集
proc projectName(): string {...}{.raises: [], tags: [].}
- Retrieves the name of the current project Source Edit
proc projectDir(): string {...}{.raises: [], tags: [].}
- Retrieves the absolute directory of the current project Source Edit
proc projectPath(): string {...}{.raises: [], tags: [].}
- Retrieves the absolute path of the current project Source Edit
proc thisDir(): string {...}{.raises: [], tags: [].}
- Retrieves the directory of the current nims script file. Its path is obtained via currentSourcePath (although, currently, currentSourcePath resolves symlinks, unlike thisDir). Source Edit
proc cd(dir: string) {...}{.raises: [OSError], tags: [].}
-
Changes the current directory.
The change is permanent for the rest of the execution, since this is just a shortcut for os.setCurrentDir() . Use the withDir() template if you want to perform a temporary change only.
ソース 編集 proc findExe(bin: string): string {...}{.raises: [], tags: [].}
- Searches for bin in the current working directory and then in directories listed in the PATH environment variable. Returns "" if the exe cannot be found. ソース 編集
proc cppDefine(define: string) {...}{.raises: [], tags: [].}
- tell Nim that define is a C preprocessor #define and so always needs to be mangled. ソース 編集
proc readLineFromStdin(): TaintedString {...}{.raises: [IOError], tags: [ReadIOEffect].}
- Reads a line of data from stdin - blocks until n or EOF which happens when stdin is closed Source Edit
proc readAllFromStdin(): TaintedString {...}{.raises: [IOError], tags: [ReadIOEffect].}
- Reads all data from stdin - blocks until EOF which happens when stdin is closed Source Edit
proc requires(deps: varargs[string]) {...}{.raises: [], tags: [].}
- Nimble support: Call this to set the list of requirements of your Nimble package. ソース 編集
テンプレート
template `--`(key, val: untyped)
- A shortcut for switch(astToStr(key), astToStr(val)). ソース 編集
template `--`(key: untyped)
- A shortcut for switch(astToStr(key). ソース 編集
template withDir(dir: string; body: untyped): untyped
-
Changes the current directory temporarily.
If you need a permanent change, use the cd() proc. Usage example:
withDir "foo": # inside foo #back to last dir
ソース 編集 template task(name: untyped; description: string; body: untyped): untyped
-
Defines a task. Hidden tasks are supported via an empty description. 用例:
task build, "default build is via the C backend": setCommand "c"
ソース 編集