internal

package
v1.198.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: Apache-2.0 Imports: 4 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 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().

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 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.

Types

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
}

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 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.

Jump to

Keyboard shortcuts

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