Documentation
¶
Index ¶
Constants ¶
const IoContextKey contextKey = "ioContext"
IoContextKey is the key for storing io.Context in cobra command context.
Variables ¶
This section is empty.
Functions ¶
func Count ¶
func Count() int
Count returns the number of registered built-in providers.
This function is primarily used for testing and diagnostics.
func ListProviders ¶
func ListProviders() map[string][]CommandProvider
ListProviders returns all registered providers grouped by category.
This function is useful for generating help text and diagnostics. The returned map uses group names as keys and slices of providers as values.
Example output:
{
"Core Stack Commands": [terraform, helmfile, workflow],
"Stack Introspection": [describe, list, validate],
...
}
func Register ¶
func Register(provider CommandProvider)
Register adds a built-in command provider to the registry.
This function is typically called during package initialization via init():
func init() {
internal.Register(&AboutCommandProvider{})
}
If a provider with the same name is already registered, the new provider replaces the existing one. This allows for plugin override functionality in the future and makes testing easier.
func RegisterAll ¶
RegisterAll registers all built-in commands with the root command.
This function should be called once during application initialization in cmd/root.go init(). It registers all commands that have been added to the registry via Register().
This function performs registration in two phases: 1. Register all primary commands to the root command 2. Register command aliases to their respective parent commands
Custom commands from atmos.yaml are processed AFTER this function via processCustomCommands(), allowing custom commands to extend or override built-in commands.
Example usage in cmd/root.go:
func init() {
// Register built-in commands
if err := internal.RegisterAll(RootCmd); err != nil {
log.Error("Failed to register built-in commands", "error", err)
}
}
Types ¶
type CommandAlias ¶ added in v1.199.0
type CommandAlias struct {
// Subcommand is the name of the subcommand to alias (empty string for the parent command).
// For example, "list" to alias "atmos profile list" as "atmos list profiles".
Subcommand string
// ParentCommand is the name of the parent command to add the alias under.
// For example, "list" to create "atmos list profiles" as an alias for "atmos profile list".
ParentCommand string
// Name is the alias command name (e.g., "profiles" for "atmos list profiles").
Name string
// Short is the short description for the alias command.
Short string
// Long is the long description for the alias command.
Long string
// Example is the usage example for the alias command.
Example string
}
CommandAlias represents an alias for a command or subcommand under a different parent.
type CommandProvider ¶
type CommandProvider interface {
// GetCommand returns the cobra.Command for this provider.
// This is the command that will be registered with the root command.
// For commands with subcommands, this should return the parent command
// with all subcommands already attached.
GetCommand() *cobra.Command
// GetName returns the command name (e.g., "about", "terraform").
// This name is used for registry lookups and must be unique.
GetName() string
// GetGroup returns the command group for help organization.
// Standard groups are:
// - "Core Stack Commands" (terraform, helmfile, workflow, packer)
// - "Stack Introspection" (describe, list, validate)
// - "Configuration Management" (vendor, docs)
// - "Cloud Integration" (aws, atlantis)
// - "Pro Features" (auth, pro)
// - "Other Commands" (about, completion, version, support)
GetGroup() string
// GetAliases returns a list of command aliases to register.
// Aliases allow the same command to be accessible under different parent commands.
// Return nil or an empty slice if the command has no aliases.
//
// Example: "atmos profile list" can be aliased as "atmos list profiles":
// return []CommandAlias{{
// ParentCommand: "list",
// Name: "profiles",
// Short: "List available configuration profiles",
// Long: `This is an alias for "atmos profile list".`,
// }}
GetAliases() []CommandAlias
}
CommandProvider is the interface that built-in command packages implement to register themselves with the Atmos command registry.
Commands implementing this interface can be automatically discovered and registered with the root command during application initialization.
Example usage:
type AboutCommandProvider struct{}
func (a *AboutCommandProvider) GetCommand() *cobra.Command {
return aboutCmd
}
func (a *AboutCommandProvider) GetName() string {
return "about"
}
func (a *AboutCommandProvider) GetGroup() string {
return "Other Commands"
}
func (a *AboutCommandProvider) GetAliases() []CommandAlias {
return nil // No aliases
}
func init() {
internal.Register(&AboutCommandProvider{})
}
func GetProvider ¶
func GetProvider(name string) (CommandProvider, bool)
GetProvider returns a built-in command provider by name.
This function is primarily used for testing and diagnostics. Returns the provider and true if found, nil and false otherwise.
type CommandRegistry ¶
type CommandRegistry struct {
// contains filtered or unexported fields
}
CommandRegistry manages built-in command registration.
This registry is for BUILT-IN commands only. Custom commands from atmos.yaml are processed separately via processCustomCommands() in cmd/cmd_utils.go.
The registry uses a singleton pattern with package-level registration functions for convenience. Commands register themselves during package initialization via init() functions.