The "sanic run" command
The purpose of
sanic run is to allow you to define shell scripts in a centralized, environment-friendly way.
In particular, a command like
sanic run test should be standardized across projects at your organization, to easily allow developers the ability to run tests on the current running environment.
Sanic allows you to refer to arguments in your scripts with shell variable placeholders. Consider the following sanic.yaml:
- name: use_args
command: echo "the first few args are $1 $2 $3, the fourth is '$4'"
See what happens when we enter the "demo" environment in sanic:
For convenience, sanic passes numerous environment variables to commands run
- SANIC_ROOT - the directory which contains the
- SANIC_ENV - the name of the environment the user is currently in.
- SANIC_CONFIG - the location of the
Consider the following sanic.yaml, which prints the current environment and sanic root:
- name: print_env
command: echo "The current environment is $SANIC_ENV."
- name: print_root
command: echo "The project root is $SANIC_ROOT."
Using another programming language for scripting
You can easily use another scripting language to define sanic scripts. Consider the following sanic.yaml:
environments: demo: commands: - name: tests command: exec python3 scripts/tests.py [email protected]
This will run scripts/tests.py with the arguments given to "sanic run". The python script will be able to use the sanic environment variables