clc script run
Runs the script in the given location.
Runs the given script.
Two kinds of scripts are supported:
- Shell scripts: CLC commands or SQL
- Advanced scripts: a Python-like language
The scripts may be in the following location:
- Filesystem path: The path may optionally have the file:// prefix.
Shell Script
The script can contain:
- SQL statements
- CLC commands prefixed with backslash.
- Comments starting with
--(double dash)
The script should have either .clc or .sql extension. Files with one of these two extensions are interpreted equivalently.
Advanced Script (BETA)
Advanced scripts are written in a Python-like language called Starlark. See this document for the language reference: https://github.com/google/starlark-go/blob/master/doc/spec.md
CLC commands are mapped to functions using a few straightforward rules:
- If the command is a top level command, it is mapped as is. E.g.,
homecommand is mapped to thehome()function. - Positional arguments are mapped to positional arguments in the function signature.
- Flags are mapped to keyword arguments in the function signature.
Examples:
clc map set -n mymap foo bar⇒map_set("foo", "bar", name="mymap")
The script should have the .star extension. Only the filesystem is supported as a source for advanced scripts.
The following values are available for advanced scripts:
| Value | Description |
|---|---|
NANOSECOND | 1 nanoscond. |
MICROSECOND | 1 microsecond in nanoseconds. |
MILLISECOND | 1 millisecond in nanoseconds. |
SECOND | 1 second in nanoseconds. |
MINUTE | 1 minute in nanoseconds. |
HOUR | 1 hour in nanoseconds. |
DAY | 1 day in nanoseconds. |
The following functions are available for advanced scripts:
| Function | Description |
|---|---|
ARGS_ | Returns the arguments passed to the script as a list. 0th item in the list is the script name. |
DATA_ | Returns the type name of the given data value. |
VALUE = `decode_ | Attempts to convert the data value to the corresponding script value. |
ERROR = last_ | Returns the last error or None. This function should be used together with the --ignore- flag. |
log_ | Adds a DEBUG message to the CLC log. |
log_ | Adds an ERROR message to the CLC log. You can pass a string message or an error. |
log_ | Adds a WARN message to the CLC log. |
map_ | Clears the given Map. |
map_ | Deletes the given Map. |
LIST_ | Returns a list of tuples that has the key in index 0 and the value in index 1. Keys and values are `data_value`s. |
ENTRY_ |
|
VALUE = map_ | Returns the data_ for the given key. |
KEYS_ | Returns a list of keys as data_. |
map_ | Locks a key in the Map. |
map_ | Loads the given keys or all keys in the MapStore if no key was specifed. |
VALUE = map_ | Deletes the given key from the Map and returns the corresponding value. |
map_ | Sets the given value for the given key. |
SIZE = map_ | Returns the size of the Map. |
BOOL = map_ | Attempts to lock the entry for the given key. Returns True if successful. |
map_ | Unlocks the entry for the given key. |
VALUES_ | Returns the values in the Map as a list. |
BOOL = cpmap_ | Sets the value for the given key if it has the expected value. |
cpmap_ | Deletes the value of a given key in a CPMap. |
cpmap_ | Deletes the CPMap and all the data in it. |
cpmap_ | Gets a value from the given CPMap. |
OLD_ | Puts the given value in the given CPMap and returns the old value. |
VALUE = cpmap_ | Removes the value of a given key in a CPMap and returns the old value. |
cpmap_ | Sets a value in the given CPMap. |
TIME = now() | Returns the current time in nanoseconds. |
LIST_ | Returns the data structure objects in the |
sleep(TIME) | Sleeps for the given nanoseconds. For example, to sleep for 10 seconds: sleep(10*SECOND). |
Usage:
clc script run [path/location] [flags] -- [parameter, ...]
Parameters:
| Parameter | Required | Description | Default |
|---|---|---|---|
parameter | Optional | Arguments to be passed to an advanced script. The arguments can be retrieved using the argv() function. | |
--echo | Optional | Print the executed command. Not used in advanced script. | false |
--ignore- | Optional | Ignore errors during script execution | false |
--debug | Optional | Enable the debug mode for advanced scripts. | false |
Global parameters
| Parameter | Description | Default |
|---|---|---|
--config, -c | Name of the configuration or path to the configuration file in YAML format. | The following locations are tried in order for the existence of
|
--format, -f | Set the output format
|
|
--log. | Set the log level, one of:
| info |
--log. | Set the log path. Use stderr to log to the screen (stderr). | $CLC_ |
--quiet, -q | Prevent displaying unnecessary output. | false |
--verbose | Enable output with more information. | false |
--timeout | Timeout for operation to complete. The duration is a string in the form of
Underscore (_) character is ignored in the The following are a few of the valid DURATIONs:
warning This is a client-side timeout, the operation you started maybe in progress on the server-side even if the given timeout is exceeded. |