The Atlas CLI supports plugins that let you extend its functionality with custom commands. You can develop plugins in any programming language that compiles to a standalone binary.
This tutorial walks you through creating your first Atlas CLI plugin using Go and the Cobra library.
To learn more about installing and managing existing plugins, see atlas plugin.
How Plugins Work
Each Atlas CLI plugin consists of two components:
A
manifest.ymlfile that describes the plugin and its commandsAn executable binary that the Atlas CLI invokes when a user runs a plugin command
When you run a plugin command, the Atlas CLI reads the manifest file, identifies the correct binary, and executes it with the appropriate arguments. The plugin binary handles all command logic independently.
Prerequisites
Before you begin, ensure you have the following installed:
Go 1.21 or later
The Atlas CLI. See Install or Update the Atlas CLI.
Create Your First Plugin
Explore the project structure.
The example plugin has the following structure:
atlas-cli-plugin-example/ ├── cmd/ │ └── plugin/ │ └── main.go ├── internal/ ├── manifest.template.yml ├── go.mod ├── go.sum ├── Makefile ├── .goreleaser.yaml └── .github/ └── workflows/ └── release.yml
Review the manifest file.
Open manifest.template.yml to see the plugin configuration:
name: atlas-cli-plugin-example description: this is an example plugin version: $VERSION github: owner: $GITHUB_REPOSITORY_OWNER name: $GITHUB_REPOSITORY_NAME binary: $BINARY commands: example: description: Root command of the atlas cli plugin example aliases: - example-alias-1 - example-alias-2
manifest.template.yml defines the manifest file for the plugin.
The manifest tells the Atlas CLI which commands the plugin
provides and which binary to execute.
Review the plugin code.
Open cmd/plugin/main.go to see the plugin implementation:
package main import ( "fmt" "os" "github.com/spf13/cobra" ) func main() { rootCmd := &cobra.Command{ Use: "example", Short: "An example Atlas CLI plugin", Run: func(cmd *cobra.Command, args []string) { fmt.Println("Hello from the Atlas CLI plugin!") }, } if err := rootCmd.Execute(); err != nil { os.Exit(1) } }
The plugin uses Cobra to define commands. When the Atlas CLI runs the plugin, it passes the command name and arguments to the binary.
Build and install the plugin.
From the root of the repository, build the plugin binary and generate the manifest file:
go build -o bin/binary ./cmd/plugin BINARY=binary VERSION=1.0.0 \ GITHUB_REPOSITORY_OWNER=$(git remote get-url origin | sed 's/.*[:/]\(.*\)\/.*/\1/') \ GITHUB_REPOSITORY_NAME=$(basename -s .git $(git remote get-url origin)) \ envsubst < manifest.template.yml > manifest.yml
Create the plugin directory and copy the files. The default plugin directory depends on your operating system:
PLUGIN_DIR=~/Library/Application\ Support/atlascli/plugins/atlas-cli-plugin-example mkdir -p "$PLUGIN_DIR" cp manifest.yml bin/binary "$PLUGIN_DIR/"
PLUGIN_DIR=~/.config/atlascli/plugins/atlas-cli-plugin-example mkdir -p "$PLUGIN_DIR" cp manifest.yml bin/binary "$PLUGIN_DIR/"
Customize Your Plugin
To create your own plugin, modify the example or start from scratch:
Update
manifest.template.ymlwith your plugin's name, description, and commands.Implement your command logic in Go (or any language that compiles to a standalone binary).
Ensure your binary name matches the
binaryfield inmanifest.template.yml.
Important
Command names in your manifest must not conflict with existing Atlas CLI commands or commands from other installed plugins.
Distribute Your Plugin
To distribute your plugin so that others can install it with the
atlas plugin install command, follow these steps:
Host your plugin in a GitHub repository.
Use GoReleaser or a similar tool to create GitHub releases with compiled binaries for multiple platforms. The example repository includes a
.goreleaser.yamlconfiguration and a GitHub Actions workflow for automated releases.Create a release tag following semantic versioning (for example,
v1.0.0).
After you create a GitHub release, users can install your plugin:
atlas plugin install <github-owner>/<repository-name>
Use a Different Programming Language
While we recommend Go with Cobra, you can write plugins in any language that compiles to a standalone executable binary. For an example of a plugin written in a different language, see the example Rust plugin repository on GitHub.
Your plugin must meet the following requirements:
Your binary must accept the command name as the first argument.
Your binary must be a standalone executable (no external runtime dependencies).
The
binaryfield inmanifest.ymlmust match the binary filename.
Learn More
atlas plugin - Manage Atlas CLI plugins.
atlas plugin install - Install a plugin.
atlas plugin update - Update a plugin.
atlas plugin uninstall - Uninstall a plugin.