The "sanic run" command

Purpose

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.

Arguments

Sanic allows you to refer to arguments in your scripts with shell variable placeholders. Consider the following sanic.yaml: environments: demo: commands: - 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:

Environment Variables

For convenience, sanic passes numerous environment variables to commands run by sanic run:

Consider the following sanic.yaml, which prints the current environment and sanic root: environments: demo: commands: - 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 $@

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