Custom Commands
This example demonstrates how to extend Atmos with custom CLI commands, making it easier for teams to use your toolchain through a single, consistent interface.
Quick Start
# View available custom commandsatmos --help# Run basic commandsatmos helloatmos ipatmos github statusatmos greet Aliceatmos weather --location LAX
Example Structure
custom-commands/
├── atmos.yaml # Basic custom commands
├── .atmos.d/
│ ├── interactive.yaml # Interactive step types (choose, confirm, input, etc.)
│ └── advanced.yaml # Boolean flags, component config, working directory
└── README.md
Basic Commands (atmos.yaml)
Hello World
The simplest custom command:
atmos hello
Get Your IP
Returns your current public IP address:
atmos ip
Nested Commands (GitHub)
Commands can be nested under parent commands:
# Check GitHub statusatmos github status# Get stargazer count for a repositoryatmos github stargazers cloudposse/atmos
Positional Arguments
Pass arguments to commands:
# Uses default "John Doe"atmos greet# Pass a custom nameatmos greet Alice
Flags
Use long or short flags:
atmos weather --location LAXatmos weather -l NYC
Interactive Commands (.atmos.d/interactive.yaml)
Interactive commands create CLI wizards using various step types.
Note: Interactive commands require a TTY (terminal) and won't work in CI/CD pipelines.
Deploy Wizard
Interactive deployment with environment selection and confirmation:
atmos deploy-wizard
Component Selection
Multi-select components with filtering:
atmos select-components
Create Ticket
Collect information with various input types:
atmos create-ticket
Collect Credentials
Secure credential collection with password masking:
atmos collect-credentials
File Selection
Interactive file picker:
atmos select-config
Show Environments
Display data in a formatted table:
atmos show-environments
Build with Progress
Show progress spinner during command execution:
atmos build-with-progress
Advanced Commands (.atmos.d/advanced.yaml)
Boolean Flags
Commands with boolean flags and conditional execution:
# Default behavior (clean=true, verbose=false)atmos build# Enable verbose outputatmos build --verbose# oratmos build -v# Disable clean stepatmos build --clean=false# Dry run modeatmos build --dry-run
Environment Variables
Commands that set environment variables:
atmos deploy-component vpc -s devatmos deploy-component eks -s prod --auto-approve
Component Configuration
Access component configuration in command steps:
# Requires stacks to be configuredatmos show-component vpc -s dev
Working Directory
Run commands from specific directories:
# Run from repository rootatmos run-from-root
Nested Subcommands
Multiple levels of command nesting:
atmos ops statusatmos ops health --verboseatmos ops restart my-service --force
Trailing Arguments
Pass additional arguments after --:
atmos run myscript.sh -- --arg1 value1 --arg2 value2
Configuration Structure
Custom commands are defined in the commands section of atmos.yaml or any file in .atmos.d/:
commands:- name: my-commanddescription: Description shown in helparguments:- name: arg-namedescription: Argument descriptionrequired: truedefault: default-valueflags:- name: flag-nameshorthand: fdescription: Flag descriptiontype: bool # or string (default)default: falseenv:- key: MY_VARvalue: "{{ .Arguments.arg-name }}"steps:- echo "Running command"- "{{ if .Flags.flag-name }}echo 'Flag enabled'{{ end }}"
Available Step Types
Custom commands support various step types for building interactive CLIs:
| Type | Description |
|---|---|
| Shell command (string) | Execute a shell command |
markdown | Display formatted markdown |
choose | Single-select dropdown |
filter | Filterable multi-select |
input | Single-line text input |
write | Multi-line text editor |
confirm | Yes/No confirmation |
file | File picker |
toast | Styled status message |
spin | Progress spinner |
table | Tabular data display |
style | Styled bordered content |
Template Variables
Steps can access various template variables:
{{ .Arguments.name }}- Positional argument value{{ .Flags.name }}- Flag value{{ .TrailingArgs }}- Arguments after--{{ .steps.step_name.value }}- Value from a previous step{{ .steps.step_name.values }}- Array of values (multi-select){{ .ComponentConfig.vars.xxx }}- Component configuration (requirescomponent_config){{ .env.VAR }}- Environment variable