@sodacore/cli
The @sodacore/cli
package provides a command-line interface for accessing and executing defined scripts within a Sodacore application.
The CLI was meant to be a simple way to run scripts, but after some work, we realised that the uses I had specifically (registering Discord commands) and being able to kick WS users off to rebalance, were more complex and would require extra features, additionally in a lot of cases there needed to be a two way dialogue, so that the scripts could also dynamically request data from the user.
Implementation
As of right now, if the enableCli
option is enabled, and a password
is set in the root Application
config, the CLI will run a small TCP server on the port
specified, or the default: 36445
. Your CLI client will actually connect to this server to execute scripts within the live context of the application.
Usage
To use the tool, you first need to create a connection:
Once a connection is added, you can then simply select the new option: Access: <YOUR_CONNECTION_NAME>
.
This will then connect to the server and share the available scripts.
Creating scripts
To create a script you can read the Scripts documentation.
Features
The CLI tool has the ability to set a connection as default, and also allows you to bypass the interactive session and simply run a script directly from the command line, this functionality is mostly for CICD pipelines and automation.
sodacore exec <taskname> <...params>
The way it works is all given params will be passed as strings to the script, so you can automate the process of running them.
You can use the --connection
flag to define the connection to use, otherwise it will use the default connection.
sodacore exec <taskname> --connection <connectionName> <...params>