internal

package
v1.202.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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 GetCompatFlagsForCommand added in v1.202.0

func GetCompatFlagsForCommand(providerName string) map[string]compat.CompatibilityFlag

GetCompatFlagsForCommand returns compatibility flags for a command provider. The providerName should match the top-level command (e.g., "terraform"). Returns nil if the provider is not found or has no compatibility flags.

This is used during arg preprocessing in Execute() to separate Atmos flags from pass-through flags before Cobra parses.

func GetSubcommandCompatFlags added in v1.202.0

func GetSubcommandCompatFlags(providerName, subcommand string) map[string]compat.CompatibilityFlag

GetSubcommandCompatFlags returns compatibility flags for a specific subcommand. The providerName should match the top-level command (e.g., "terraform"). The subcommand is the name of the subcommand (e.g., "apply", "plan"). Returns nil if no flags are registered for the provider/subcommand combination.

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

func RegisterAll(root *cobra.Command) error

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)
    }
}

func RegisterCommandCompatFlags added in v1.202.0

func RegisterCommandCompatFlags(providerName, subcommand string, flags map[string]compat.CompatibilityFlag)

RegisterCommandCompatFlags registers compat flags for a specific command. The providerName is the top-level command (e.g., "terraform"). The subcommand is the specific command (e.g., "plan", "apply", or "terraform" for the parent). Each subcommand registers its own flags in init(), eliminating the need for switch statements.

func Reset

func Reset()

Reset clears the registry, removing all registered providers.

WARNING: This function is for TESTING ONLY. It should never be called in production code. It allows tests to start with a clean registry state.

func ValidateAtmosConfig added in v1.202.0

func ValidateAtmosConfig(opts ...ValidateOption) error

ValidateAtmosConfig checks the Atmos configuration and returns an error instead of exiting. This makes the function testable by allowing errors to be handled by the caller.

This function validates that the required Atmos configuration exists: - By default, checks that the stacks directory exists - Can be configured to skip stack validation using WithStackValidation(false)

Returns specific, actionable errors (e.g., "directory for Atmos stacks does not exist") instead of generic errors, making it easier for users to diagnose configuration issues.

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

	// GetFlagsBuilder returns the flags builder for this command.
	// Return nil if the command has no flags.
	GetFlagsBuilder() flags.Builder

	// GetPositionalArgsBuilder returns the positional args builder for this command.
	// Return nil if the command has no positional arguments.
	GetPositionalArgsBuilder() *flags.PositionalArgsBuilder

	// GetCompatibilityFlags returns compatibility flags for this command.
	// Return nil if the command has no compatibility flags.
	GetCompatibilityFlags() map[string]compat.CompatibilityFlag

	// 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) GetFlagsBuilder() flags.Builder {
    return nil
}

func (a *AboutCommandProvider) GetPositionalArgsBuilder() *flags.PositionalArgsBuilder {
    return nil
}

func (a *AboutCommandProvider) GetCompatibilityFlags() map[string]compat.CompatibilityFlag {
    return nil
}

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.

type ValidateConfig added in v1.202.0

type ValidateConfig struct {
	CheckStack bool
	ConfigInfo schema.ConfigAndStacksInfo
}

ValidateConfig holds configuration options for Atmos config validation.

type ValidateOption added in v1.202.0

type ValidateOption func(*ValidateConfig)

ValidateOption is a functional option for configuring validation.

func WithConfigInfo added in v1.202.0

func WithConfigInfo(info *schema.ConfigAndStacksInfo) ValidateOption

WithConfigInfo sets the config info for validation, respecting config selection flags.

func WithStackValidation added in v1.202.0

func WithStackValidation(check bool) ValidateOption

WithStackValidation sets whether to check the stacks directory exists.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL