cmd

package
v1.181.0-test.2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrFmtWrapErr = "%w: %v" // Format for wrapping errors.
)

Error format strings.

Variables

View Source
var (
	ErrInvalidOutputType = fmt.Errorf("invalid output type specified. Valid values are 'list', 'map', and 'all'")
	ErrInvalidFormat     = fmt.Errorf("invalid format specified. Valid values are 'yaml' and 'json'")
)
View Source
var (
	ErrGettingCommonFlags    = pkgerrors.New("error getting common flags")
	ErrGettingAbstractFlag   = pkgerrors.New("error getting abstract flag")
	ErrGettingVarsFlag       = pkgerrors.New("error getting vars flag")
	ErrInitializingCLIConfig = pkgerrors.New("error initializing CLI config")
	ErrDescribingStacks      = pkgerrors.New("error describing stacks")
	ErrComponentNameRequired = pkgerrors.New("component name is required")
	ErrInvalidArguments      = pkgerrors.New("invalid arguments: the command requires one argument 'component'")
)
View Source
var ErrRepoPathConflict = errors.New("if the '--repo-path' flag is specified, the '--ref', '--sha', '--ssh-key' and '--ssh-key-password' flags can't be used")
View Source
var RootCmd = &cobra.Command{
	Use:                "atmos",
	Short:              "Universal Tool for DevOps and Cloud Automation",
	Long:               `Atmos is a universal tool for DevOps and cloud automation used for provisioning, managing and orchestrating workflows across various toolchains`,
	FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},
	PersistentPreRun: func(cmd *cobra.Command, args []string) {

		isHelpCommand := cmd.Name() == "help"
		helpFlag := cmd.Flags().Changed("help")

		isHelpRequested := isHelpCommand || helpFlag

		if isHelpRequested {

			cmd.SilenceUsage = false
			cmd.SilenceErrors = false
		} else {
			cmd.SilenceUsage = true
			cmd.SilenceErrors = true
		}
		configAndStacksInfo := schema.ConfigAndStacksInfo{}

		_, err := cfg.InitCliConfig(configAndStacksInfo, false)
		if err != nil {
			if errors.Is(err, cfg.NotFound) {

				if !isHelpRequested {
					u.LogWarning(err.Error())
				}
			} else {
				u.LogErrorAndExit(err)
			}
		}
	},
	Run: func(cmd *cobra.Command, args []string) {

		checkAtmosConfig()

		fmt.Println()
		err := tuiUtils.PrintStyledText("ATMOS")
		if err != nil {
			u.PrintErrorMarkdownAndExit("", err, "")
		}

		err = e.ExecuteAtmosCmd()
		if err != nil {
			u.LogErrorAndExit(err)
		}
	},
}

RootCmd represents the base command when called without any subcommands

View Source
var ValidateSchemaCmd = &cobra.Command{
	Use:   "schema",
	Short: "Validate YAML files against JSON schemas defined in atmos.yaml",
	Long: `The validate schema command reads the ` + "`" + `schemas` + "`" + ` section of the atmos.yaml file 
and validates matching YAML files against their corresponding JSON schemas.

Each entry under ` + "`" + `schemas` + "`" + ` should define:
  - ` + "`" + `schema` + "`" + `: The path to the JSON schema file.
  - ` + "`" + `matches` + "`" + `: A glob pattern that specifies which YAML files to validate.

For every schema entry:
  - The JSON schema is loaded from the specified path.
  - All files matching the glob pattern are collected.
  - Each matching YAML file is parsed and converted to JSON.
  - The converted YAML is validated against the schema.

This command helps ensure that configuration files follow a defined structure 
and are compliant with expected formats, reducing configuration drift and runtime errors.
`,
	FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
	Args:               cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		checkAtmosConfig()
		schema := ""
		key := ""
		if len(args) > 0 {
			key = args[0]
		}

		if cmd.Flags().Changed("schemas-atmos-manifest") {
			schema, _ = cmd.Flags().GetString("schemas-atmos-manifest")
		}

		if key == "" && schema != "" {
			log.Error("key not provided for the schema to be used")
			u.OsExit(1)
		}

		if err := exec.NewAtmosValidatorExecutor(&atmosConfig).ExecuteAtmosValidateSchemaCmd(key, schema); err != nil {
			if errors.Is(err, exec.ErrInvalidYAML) {
				u.OsExit(1)
			}
			u.PrintErrorMarkdownAndExit("", err, "")
		}
	},
}

ValidateSchemaCmd represents the 'atmos validate schema' command.

This command reads the 'schemas' section from the atmos.yaml configuration file, where each schema entry specifies a JSON schema path and a glob pattern for matching YAML files.

For each entry:

  • The JSON schema is loaded.
  • All YAML files matching the glob pattern are discovered.
  • Each YAML file is converted to JSON and validated against the schema.

This command ensures that configuration files conform to expected structures and helps catch errors early in the development or deployment process.

View Source
var ValidateStacksCmd = &cobra.Command{
	Use:                "stacks",
	Short:              "Validate stack manifest configurations",
	Long:               "This command validates the configuration of stack manifests in Atmos to ensure proper setup and compliance.",
	Example:            "validate stacks",
	FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
	Args:               cobra.NoArgs,
	Run: func(cmd *cobra.Command, args []string) {

		checkAtmosConfig()

		err := e.ExecuteValidateStacksCmd(cmd, args)
		if err != nil {
			u.PrintErrorMarkdownAndExit("", err, "")
		}

		u.PrintMessageInColor("all stacks validated successfully\n", theme.Colors.Success)
	},
}

ValidateStacksCmd validates stacks

Functions

func AddStackCompletion added in v1.161.0

func AddStackCompletion(cmd *cobra.Command)

func CheckForAtmosUpdateAndPrintMessage added in v1.127.0

func CheckForAtmosUpdateAndPrintMessage(atmosConfig schema.AtmosConfiguration)

CheckForAtmosUpdateAndPrintMessage checks if a version update is needed and prints a message if a newer version is found. It loads the cache, decides if it's time to check for updates, compares the current version to the latest available release, and if newer, prints the update message. It also updates the cache's timestamp after printing.

func ComponentsArgCompletion added in v1.161.0

func ComponentsArgCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

func Contains added in v1.137.0

func Contains(slice []string, target string) bool

Contains checks if a slice of strings contains an exact match for the target string.

func Execute

func Execute() error

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the RootCmd.

func ExecuteListDeploymentsCmd

func ExecuteListDeploymentsCmd(cmd *cobra.Command, args []string) error

Types

type AtmosValidateOption added in v1.97.0

type AtmosValidateOption func(*ValidateConfig)

func WithStackValidation added in v1.97.0

func WithStackValidation(check bool) AtmosValidateOption

type ExampleContent added in v1.162.0

type ExampleContent struct {
	Content    string
	Suggestion string
}

type MetadataParams added in v1.170.0

type MetadataParams struct {
	CommonFlags     *fl.CommonFlags
	ProcessingFlags *fl.ProcessingFlags
	ComponentFilter string
}

MetadataParams contains the parameters needed for listing metadata.

type ProcessingOptions added in v1.170.0

type ProcessingOptions struct {
	Templates bool
	Functions bool
}

ProcessingOptions holds flags for processing templates and YAML functions.

type SettingsParams added in v1.170.0

type SettingsParams struct {
	CommonFlags     *fl.CommonFlags
	ProcessingFlags *fl.ProcessingFlags
	ComponentFilter string
}

SettingsParams contains all parameters needed for the list settings command.

type ValidateConfig added in v1.97.0

type ValidateConfig struct {
	CheckStack bool
}

ValidateConfig holds configuration options for Atmos validation. CheckStack determines whether stack configuration validation should be performed.

Jump to

Keyboard shortcuts

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