Function
How to use the function command in the Scale CLI.
The function
command is used to interact with Scale Functions locally. fn
is an alias for function
.
New
To create a new Scale Function, run the following command:
This will create a new scale function in the current directory in the Go programming language.
The scale new
command is an alias for scale function new
. You can use either command to login to the Scale API.
You can also specify the language of the function you want to create by using the --language
flag:
The following languages are currently supported:
go
- Gorust
- Rustts
- TypeScript/JavaScript
We are actively working on adding support for more languages. If you would like to see a specific language supported, please let
us know by joining the #scale
channel in our Discord.
Build
The build
subcommand is used to build a Scale Function using the toolchain for the Scale Function's source language. It can be
run from the root of the Scale Function's directory:
The --directory
flag can be used to specify the directory of the Scale Function:
The --name
, --org
, and --tag
flags can be used to specify the name, organization, and tag of the Scale Function at build time:
Because this command relies on the toolchain for the Scale Function's source language being installed on your machine, it may sometimes be necessary to tell the command where it can find the toolchain executables.
The --cargo
, --go
, and --tinygo
flags can be used to specify the path to the cargo
, go
, and tinygo
executables.
List
The list
subcommand is used to list all the compiled Scale Functions available in the local Scale Function cache.
If you'd like to specify the directory of the Scale Function cache, you can use the --cache-directory
flag:
Run
You can run your compiled scale functions locally using the run
subcommand. This command will start a local HTTP server that will
execute the Scale Function when it receives an HTTP request.
The --listen
flag can be used to specify the address and port that the local HTTP server should listen on (by default it will listen on :8080
)
It is also possible to provide multiple Scale Functions to the run
subcommand. If you do, the local HTTP server will execute the
Scale Functions in a chain, and will only execute the next function in the chain if the previous function calls .Next()
.
Remember that the --cache-directory
configuration flag can be used to specify the directory of the Scale Function cache.
If the function is not available locally, the run
command will attempt to look for it in the Scale Registry (if the CLI is authenticated).
Export
The export
subcommand is used to export a Scale Function from the local Scale Function cache to a local .scale
file.
It's helpful in situations where you want to distribute a Scale Function without using the Scale Registry, or if you want to embed it inside your Runtime or Application.
The function will be exported to the specified <path>
directory as a .scale
file. The --output
flag can be used to override
the name of the exported .scale
file:
The --raw
flag can be used to export the raw WebAssembly .wasm
binary instead of the .scale
file:
Delete
To delete a Scale Function from the local Scale Function cache, run the following command:
Last updated on