Skip to content
Docs
Getting Started

Getting Started

Risor can be used as a CLI or included as a library in your Go program. It's easiest to try it out using the CLI. See the instructions below for installing using Homebrew or Go.

This page includes a number of examples of using the CLI with different options, to evaluate code passed on stdin or from a file.

Install the CLI

brew install risor
risor version

Start the REPL

Running risor with no options starts the REPL:

risor

Press ctrl+c to exit the REPL.

Evaluate a Code Snippet

Use the -c option to pass in code as a command line option:

risor -c "time.now()"

Evaluate a Script

Pass the path to a Risor script as an argument:

risor hello.risor

In hello.risor:

hello.risor
print("hello")

Use a Risor Library

Use the --modules option to specify a path to a directory containing Risor library modules. These can then be imported using an import statement.

mylibraries/lib.risor
func add(x, y) { x + y }
risor --modules mylibraries -c "import lib; lib.add(1, 2)"

Pass Code via Stdin

Use the --stdin option to pass code via stdin:

echo "time.now()" | risor --stdin

Show Timing Information

Use the --timing option to print the execution time after the script completes:

risor --timing --code "time.sleep(2)"

Set the Output Format

The Risor CLI prints the result of the last expression run in the script. By default, it attempts to print the result as JSON, but if the value is not JSON-serializable, it will print the result as a string. This behavior may be overriden using the --output option, which accepts json or text as values.

risor -c "'Greetings!'" --output text
risor -c "'Greetings!'" --output json

Disable Color Output

Use the --no-color option to disable color output:

risor -c "time.now()" --no-color

Read from Stdin

Stdin is available as os.stdin:

echo test | risor -c "os.stdin.read()"