ctx.flags
The ctx.flags value is a read-only dictionary of the flags Atmos parsed for the running command. Read parsed values
directly instead of interpolating them into the script source or mapping them to environment variables.
Usage
ctx.flags["name"]
ctx.flags.get("name", default)
Returns
A frozen dictionary with sorted keys. Its contents depend on the entry point:
- Custom command: one entry per flag the command declares, with the values and types Atmos parsed. A flag declared as
type: stringis a string, so convert it withint(...)before doing arithmetic. Boolean flags are booleans. An entry is present for each flag that has a value, including defaults. - Workflow step: the flags the workflow supplies, as strings. This is currently one entry,
ctx.flags["stack"], holding the stack the workflow runs against, or an empty string when there is none. - Standalone script, hook, or any entry point without declared flags: an empty dictionary. A standalone program
receives its flags as the
flagsargument of the entry function it passes tocli.command.
Steps inside parallel and matrix groups inherit the dictionary.
Examples
Read typed flags in a custom command
commands:
- name: capacity
description: Calculate a service's total worker capacity
flags:
- name: replicas
type: string
default: "2"
steps:
- name: capacity
type: script
interpreter: starlark
script: |
replicas = int(ctx.flags["replicas"])
if replicas < 1:
fail("replicas must be positive")
ui.success("{} workers".format(replicas * 4))
atmos capacity --replicas=3
✓ 12 workers
Provide a default for an optional flag
stack = ctx.flags.get("stack", "dev")
Check whether a flag was provided
if "dry-run" in ctx.flags and ctx.flags["dry-run"]:
ui.warning("Dry run: no changes will be made")
Related
ctx.argumentsholds the parsed positional arguments.cli.flagdeclares flags for a standalone script.ctxlists every context attribute.- Custom commands