ec opa fmt

Format Rego source files

Synopsis

Format Rego source files.

The 'fmt' command takes a Rego source file and outputs a reformatted version. If no file path is provided - this tool will use stdin. The format of the output is not defined specifically; whatever this tool outputs is considered correct format (with the exception of bugs).

If the '-w' option is supplied, the 'fmt' command will overwrite the source file instead of printing to stdout.

If the '-d' option is supplied, the 'fmt' command will output a diff between the original and formatted source.

If the '-l' option is supplied, the 'fmt' command will output the names of files that would change if formatted. The '-l' option will suppress any other output to stdout from the 'fmt' command.

If the '--fail' option is supplied, the 'fmt' command will return a non zero exit code if a file would be reformatted.

The 'fmt' command can be run in several compatibility modes for consuming and outputting different Rego versions:

  • opa fmt:

  • v1 Rego is formatted to v1

  • rego.v1/future.keywords imports are NOT removed

  • rego.v1/future.keywords imports are NOT added if missing

  • v0 rego is rejected

  • opa fmt --v0-compatible:

  • v0 Rego is formatted to v0

  • v1 Rego is rejected

  • opa fmt --v0-v1:

  • v0 Rego is formatted to be compatible with v0 AND v1

  • v1 Rego is rejected

  • opa fmt --v0-v1 --v1-compatible:

  • v1 Rego is formatted to be compatible with v0 AND v1

  • v0 Rego is rejected

ec opa fmt [path [...]] [flags]

Options

--capabilities

set capabilities version or capabilities.json file path

--check-result

assert that the formatted code is valid and can be successfully parsed (Default: true)

-d, --diff

only display a diff of the changes (Default: false)

--drop-v0-imports

drop v0 imports from the formatted code, such as 'rego.v1' and 'future.keywords' (Default: false)

--fail

non zero exit code on reformat (Default: false)

-h, --help

help for fmt (Default: false)

-l, --list

list all files who would change when formatted (Default: false)

--rego-v1

format module(s) to be compatible with both Rego v0 and v1 (Default: false)

--v0-compatible

opt-in to OPA features and behaviors prior to the OPA v1.0 release (Default: false)

--v0-v1

format module(s) to be compatible with both Rego v0 and v1 (Default: false)

--v1-compatible

opt-in to OPA features and behaviors that are enabled by default in OPA v1.0 (Default: false)

-w, --write

overwrite the original source file (Default: false)

Options inherited from parent commands

--debug

same as verbose but also show function names and line numbers (Default: false)

--kubeconfig

path to the Kubernetes config file to use

--logfile

file to write the logging output. If not specified logging output will be written to stderr

--quiet

less verbose output (Default: false)

--retry-duration

base duration for exponential backoff calculation (Default: 1s)

--retry-factor

exponential backoff multiplier (Default: 2)

--retry-jitter

randomness factor for backoff calculation (0.0-1.0) (Default: 0.1)

--retry-max-retry

maximum number of retry attempts (Default: 3)

--retry-max-wait

maximum wait time between retries (Default: 3s)

--timeout

max overall execution duration (Default: 5m0s)

--trace

enable trace logging, set one or more comma separated values: none,all,perf,cpu,mem,opa,log (Default: none)

--verbose

more verbose output (Default: false)