Documentation
¶
Overview ¶
Package utils provides markdown utilities for error handling and output formatting in the Atmos CLI application.
Index ¶
- Constants
- Variables
- func AppendJSONPathIndex(basePath string, index int) string
- func AppendJSONPathKey(basePath, key string) string
- func CleanDuplicatedPath(path string) string
- func CleanupArrayIndexKeys(data interface{}) interface{}
- func ClearInternPool()
- func ConvertFromJSON(jsonString string) (any, error)
- func ConvertToHclAst(data any) (ast.Node, error)
- func ConvertToJSON(data any) (string, error)
- func ConvertToJSONFast(data any) (string, error)
- func ConvertToYAML(data any, opts ...YAMLOptions) (string, error)
- func DefaultHighlightSettings() *schema.SyntaxHighlighting
- func DisplayDocs(componentDocs string, usePager bool) error
- func EnsureDir(fileName string) error
- func EvaluateYqExpression(atmosConfig *schema.AtmosConfiguration, data any, yq string) (any, error)
- func EvaluateYqExpressionWithType[T any](atmosConfig *schema.AtmosConfiguration, data T, yq string) (*T, error)
- func ExecuteShellAndReturnOutput(command string, name string, dir string, env []string, dryRun bool) (string, error)
- func ExtractAppendListValue(value any) ([]any, bool)
- func FileExists(filename string) bool
- func FileOrDirExists(filename string) bool
- func FormatList(items []string) string
- func GetAllFilesInDir(dir string) ([]string, error)
- func GetAllYamlFilesInDir(dir string) ([]string, error)
- func GetComponentBasePath(atmosConfig *schema.AtmosConfiguration, componentType string) (string, error)
- func GetComponentPath(atmosConfig *schema.AtmosConfiguration, componentType string, ...) (string, error)
- func GetFileNameFromURL(rawURL string) (string, error)
- func GetGlobMatches(pattern string) ([]string, error)
- func GetHighlightSettings(config *schema.AtmosConfiguration) *schema.SyntaxHighlighting
- func GetHighlightedJSON(atmosConfig *schema.AtmosConfiguration, data any) (string, error)
- func GetHighlightedYAML(atmosConfig *schema.AtmosConfiguration, data any) (string, error)
- func GetLatestGitHubRepoRelease(owner string, repo string) (string, error)
- func GetLineEnding() string
- func GetNextShellLevel() (int, error)
- func GoToCty(value any) cty.Value
- func HasAppendTag(value any) bool
- func HasYAMLPosition(positions PositionMap, path string) bool
- func HighlightCodeWithConfig(config *schema.AtmosConfiguration, code string, format ...string) (string, error)
- func InitializeMarkdown(atmosConfig *schema.AtmosConfiguration)
- func Intern(_ *schema.AtmosConfiguration, s string) string
- func InternStringsInMap(atmosConfig *schema.AtmosConfiguration, data any) any
- func IsDirectory(path string) (bool, error)
- func IsPathAbsolute(path string) bool
- func IsSocket(path string) (bool, error)
- func IsTemplateFile(filePath string) bool
- func IsURL(s string) bool
- func IsValidScheme(scheme string) bool
- func IsYaml(file string) bool
- func JoinPath(basePath string, providedPath string) string
- func JoinPathAndValidate(basePath string, providedPath string) (string, error)
- func JoinPaths(basePath string, paths []string) ([]string, error)
- func MapKeyExists(m map[string]any, key string) bool
- func MatchWildcard(pattern, str string) (bool, error)
- func PathMatch(pattern, name string) (bool, error)
- func PrintAsJSON(atmosConfig *schema.AtmosConfiguration, data any) error
- func PrintAsJSONSimple(atmosConfig *schema.AtmosConfiguration, data any) error
- func PrintAsYAML(atmosConfig *schema.AtmosConfiguration, data any) error
- func PrintAsYAMLSimple(atmosConfig *schema.AtmosConfiguration, data any) error
- func PrintAsYAMLToFileDescriptor(atmosConfig *schema.AtmosConfiguration, data any) error
- func PrintMessage(message string)
- func PrintMessageToUpgradeToAtmosLatestRelease(latestVersion string)
- func PrintfMarkdown(format string, a ...interface{})
- func PrintfMarkdownToTUI(format string, a ...interface{})
- func PrintfMessageToTUI(message string, args ...any)
- func ProcessIncludeRawTag(atmosConfig *schema.AtmosConfiguration, node *yaml.Node, val string, ...) error
- func ProcessIncludeTag(atmosConfig *schema.AtmosConfiguration, node *yaml.Node, val string, ...) error
- func ProcessTagCwd(input string) (string, error)
- func ProcessTagEnv(input string, envContext EnvVarContext) (string, error)
- func ProcessTagExec(input string) (any, error)
- func ProcessTagGitRoot(input string) (string, error)
- func ProcessTagRandom(input string) (int, error)
- func ResetInternStats()
- func ResolveRelativePath(path string, basePath string) string
- func SearchConfigFile(path string) (string, bool)
- func ShellRunner(command string, name string, dir string, env []string, out io.Writer) error
- func SliceContainsInt(s []int, i int) bool
- func SliceOfInterfacesToSliceOfStrings(input []any) []string
- func SliceRemoveFlag(slice []string, flagName string) []string
- func SortMapByKeysAndValuesUniq(m map[string][]string) map[string][]string
- func SplitStringByDelimiter(str string, delimiter rune) ([]string, error)
- func StringKeysFromMap(m map[string]any) []string
- func TrimBasePathFromPath(basePath string, path string) string
- func UniqueStrings(input []string) []string
- func UnmarshalYAML[T any](input string) (T, error)
- func UnmarshalYAMLFromFile[T any](atmosConfig *schema.AtmosConfiguration, input string, file string) (T, error)
- func ValidateURI(uri string) error
- func WrapLongStrings(data any, maxLength int) any
- func WrapWithAppendTag(list []any) map[string]any
- func WriteTerraformBackendConfigToFileAsHcl(filePath string, backendType string, backendConfig map[string]any) error
- func WriteToFileAsHcl(filePath string, data any, fileMode os.FileMode) error
- func WriteToFileAsJSON(filePath string, data any, fileMode os.FileMode) error
- func WriteToFileAsYAML(filePath string, data any, fileMode os.FileMode) error
- func WriteToFileAsYAMLWithConfig(atmosConfig *schema.AtmosConfiguration, filePath string, data any, ...) error
- type ComponentInfo
- type EnvVarContext
- type InternStats
- type LongString
- type Position
- type PositionMap
- type YAMLOptions
Constants ¶
const ( DefaultStackConfigFileExtension = ".yaml" YamlFileExtension = ".yaml" YmlFileExtension = ".yml" YamlTemplateExtension = ".yaml.tmpl" YmlTemplateExtension = ".yml.tmpl" TemplateExtension = ".tmpl" )
const ( LogLevelTrace = "Trace" LogLevelDebug = "Debug" )
const ( // Atmos YAML functions. AtmosYamlFuncExec = "!exec" AtmosYamlFuncSecret = "!secret" AtmosYamlFuncStore = "!store" AtmosYamlFuncStoreGet = "!store.get" AtmosYamlFuncTemplate = "!template" AtmosYamlFuncTerraformOutput = "!terraform.output" AtmosYamlFuncTerraformState = "!terraform.state" AtmosYamlFuncEnv = "!env" AtmosYamlFuncInclude = "!include" AtmosYamlFuncIncludeRaw = "!include.raw" AtmosYamlFuncGitRoot = atmosGit.YAMLFuncRepoRoot AtmosYamlFuncGitRootAlias = atmosGit.YAMLFuncRoot AtmosYamlFuncGitSha = atmosGit.YAMLFuncSHA AtmosYamlFuncGitBranch = atmosGit.YAMLFuncBranch AtmosYamlFuncGitRef = atmosGit.YAMLFuncRef AtmosYamlFuncGitRepository = atmosGit.YAMLFuncRepository AtmosYamlFuncGitOwner = atmosGit.YAMLFuncOwner AtmosYamlFuncGitName = atmosGit.YAMLFuncName AtmosYamlFuncGitHost = atmosGit.YAMLFuncHost AtmosYamlFuncGitUrl = atmosGit.YAMLFuncURL AtmosYamlFuncAppend = "!append" AtmosYamlFuncCwd = "!cwd" AtmosYamlFuncUnset = "!unset" AtmosYamlFuncRandom = "!random" AtmosYamlFuncLiteral = "!literal" AtmosYamlFuncAwsAccountID = "!aws.account_id" AtmosYamlFuncAwsCallerIdentityArn = "!aws.caller_identity_arn" AtmosYamlFuncAwsCallerIdentityUserID = "!aws.caller_identity_user_id" AtmosYamlFuncAwsRegion = "!aws.region" AtmosYamlFuncAwsOrganizationID = "!aws.organization_id" DefaultYAMLIndent = 2 )
const AppendTagMetadataKey = "__atmos_append__"
AppendTagMetadataKey is the reserved map key used to wrap a list that carries the !append directive. The YAML parsing phase (atmos.yaml via handleAppend and stack manifests via processCustomTagsInner) wraps !append-tagged sequences as map[string]any{AppendTagMetadataKey: list}; the merge phase (pkg/merge) detects this wrapper and appends the list to the inherited value instead of replacing it.
const MaxShellDepth = 10
MaxShellDepth is the maximum number of nested shell commands that can be executed .
const MaxURISize = 2048
const (
// Newline is the newline character constant.
Newline = "\n"
)
Variables ¶
var ( ErrURIEmpty = errors.New("URI cannot be empty") ErrURIExceedsMaxLength = errors.New("URI exceeds maximum length of 2048 characters") ErrURICannotContainPathTraversal = errors.New("URI cannot contain path traversal sequences") ErrURICannotContainSpaces = errors.New("URI cannot contain spaces") ErrUnsupportedURIScheme = errors.New("unsupported URI scheme") ErrInvalidOCIURIFormat = errors.New("invalid OCI URI format") )
var ( ErrMaxShellDepthExceeded = errors.New("ATMOS_SHLVL exceeds maximum allowed depth. Infinite recursion?") ErrConvertingShellLevel = errors.New("converting ATMOS_SHLVL to number error") ErrBindingShellLevelEnv = errors.New("binding ATMOS_SHLVL env var error") )
var ( AtmosYamlTags = []string{ AtmosYamlFuncExec, AtmosYamlFuncSecret, AtmosYamlFuncStore, AtmosYamlFuncStoreGet, AtmosYamlFuncTemplate, AtmosYamlFuncTerraformOutput, AtmosYamlFuncTerraformState, AtmosYamlFuncEnv, AtmosYamlFuncGitRoot, AtmosYamlFuncGitRootAlias, AtmosYamlFuncGitSha, AtmosYamlFuncGitBranch, AtmosYamlFuncGitRef, AtmosYamlFuncGitRepository, AtmosYamlFuncGitOwner, AtmosYamlFuncGitName, AtmosYamlFuncGitHost, AtmosYamlFuncGitUrl, AtmosYamlFuncAppend, AtmosYamlFuncCwd, AtmosYamlFuncUnset, AtmosYamlFuncRandom, AtmosYamlFuncLiteral, AtmosYamlFuncAwsAccountID, AtmosYamlFuncAwsCallerIdentityArn, AtmosYamlFuncAwsCallerIdentityUserID, AtmosYamlFuncAwsRegion, AtmosYamlFuncAwsOrganizationID, } ErrIncludeYamlFunctionInvalidArguments = errors.New("invalid number of arguments in the !include function") ErrIncludeYamlFunctionInvalidFile = errors.New("the !include function references a file that does not exist") ErrIncludeYamlFunctionInvalidAbsPath = errors.New("failed to convert the file path to an absolute path in the !include function") ErrIncludeYamlFunctionFailedStackManifest = errors.New("failed to process the stack manifest with the !include function") ErrNilAtmosConfig = errors.New("atmosConfig cannot be nil") )
var ErrFailedToProcessHclFile = errors.New("failed to process HCL file")
var ErrInvalidAtmosYAMLFunction = errors.New("invalid Atmos YAML function")
var (
ErrUnknownComponentType = errors.New("unknown component type")
)
Static errors for component path resolution.
var OsExit = os.Exit
OsExit is a variable for testing, so we can mock os.Exit.
var TestHTTPClient *http.Client
TestHTTPClient allows tests to inject a custom HTTP client for remote file fetching. This is used to mock GitHub requests in tests.
Functions ¶
func AppendJSONPathIndex ¶ added in v1.194.0
AppendJSONPathIndex appends an array index to an existing JSONPath. Examples:
AppendJSONPathIndex("vars.zones", 0) -> "vars.zones[0]"
AppendJSONPathIndex("", 0) -> "[0]"
func AppendJSONPathKey ¶ added in v1.194.0
AppendJSONPathKey appends a key to an existing JSONPath. Examples:
AppendJSONPathKey("vars", "name") -> "vars.name"
AppendJSONPathKey("", "vars") -> "vars"
func CleanDuplicatedPath ¶ added in v1.201.0
CleanDuplicatedPath removes duplicate path segments that sometimes occur due to symlink resolution or path joining issues. For example: /foo/bar/foo/bar/baz becomes /foo/bar/baz.
func CleanupArrayIndexKeys ¶ added in v1.221.0
func CleanupArrayIndexKeys(data interface{}) interface{}
CleanupArrayIndexKeys removes duplicate indexed keys from maps that also contain arrays. Viper sometimes creates both array entries and indexed map keys (e.g., both "steps" array and "steps[0]", "steps[1]" keys). This function removes the indexed keys when an array exists.
This function only processes map[string]interface{} types and preserves all other types as-is. It does NOT convert structs to maps, which would lose YAML features like anchors and tags.
func ClearInternPool ¶ added in v1.195.0
func ClearInternPool()
ClearInternPool clears the intern pool. Should only be used in tests.
func ConvertFromJSON ¶ added in v1.9.0
ConvertFromJSON converts the provided JSON-encoded string to Go data types
func ConvertToHclAst ¶ added in v1.6.0
ConvertToHclAst converts the provided value to an HCL abstract syntax tree.
func ConvertToJSON ¶ added in v1.6.0
ConvertToJSON converts the provided value to a JSON-encoded string
func ConvertToJSONFast ¶ added in v1.6.0
ConvertToJSONFast converts the provided value to a JSON-encoded string using 'ConfigFastest' config and json.Marshal without indents
func ConvertToYAML ¶ added in v1.6.0
func ConvertToYAML(data any, opts ...YAMLOptions) (string, error)
func DefaultHighlightSettings ¶ added in v1.148.0
func DefaultHighlightSettings() *schema.SyntaxHighlighting
DefaultHighlightSettings returns the default syntax highlighting settings
func DisplayDocs ¶ added in v1.124.0
DisplayDocs displays component documentation directly through the terminal or through a pager (like less). The use of a pager is determined by the pagination value set in the CLI Settings for Atmos.
func EnsureDir ¶ added in v1.5.0
EnsureDir accepts a file path and creates all the intermediate subdirectories
func EvaluateYqExpression ¶ added in v1.140.0
func EvaluateYqExpressionWithType ¶ added in v1.175.0
func EvaluateYqExpressionWithType[T any](atmosConfig *schema.AtmosConfiguration, data T, yq string) (*T, error)
func ExecuteShellAndReturnOutput ¶ added in v1.173.0
func ExecuteShellAndReturnOutput( command string, name string, dir string, env []string, dryRun bool, ) (string, error)
ExecuteShellAndReturnOutput runs a shell script and capture its standard output .
func ExtractAppendListValue ¶ added in v1.221.0
ExtractAppendListValue extracts the actual list value from an append-tagged structure.
func FileExists ¶
FileExists checks if the file exists and is not a directory.
func FileOrDirExists ¶ added in v1.11.3
FileOrDirExists checks if the file or directory exists.
func FormatList ¶ added in v1.202.0
FormatList formats a list of strings into a markdown bullet list. Each item is formatted as a backtick-quoted bullet point.
func GetAllFilesInDir ¶ added in v1.55.0
GetAllFilesInDir returns all files in the provided directory and all subdirectories.
func GetAllYamlFilesInDir ¶ added in v1.55.0
GetAllYamlFilesInDir returns all YAML files in the provided directory and all subdirectories.
func GetComponentBasePath ¶ added in v1.192.0
func GetComponentBasePath(atmosConfig *schema.AtmosConfiguration, componentType string) (string, error)
GetComponentBasePath returns just the base path for a component type. Useful when you need the base directory without a specific component.
func GetComponentPath ¶ added in v1.192.0
func GetComponentPath(atmosConfig *schema.AtmosConfiguration, componentType string, componentFolderPrefix string, component string) (string, error)
GetComponentPath returns the absolute path to a component, respecting all configuration and overrides. Priority order: 1. Environment variables (if set, these completely override config) 2. Already-resolved absolute paths in atmosConfig 3. Constructed from BasePath + configured component paths
This function makes NO assumptions about directory names - it only uses what's configured.
func GetFileNameFromURL ¶ added in v1.97.0
GetFileNameFromURL extracts the file name from a URL.
func GetGlobMatches ¶ added in v1.4.21
GetGlobMatches tries to read and return the Glob matches content from the sync map if it exists in the map, otherwise it finds and returns all files matching the pattern, stores the files in the map and returns the files.
Note: unlike pkg/filesystem.GetGlobMatches, this function returns an error when no files match the pattern (consistent with its use as an import-path resolver). The returned slice may be nil when an error is returned. See pkg/filesystem.GetGlobMatches for the variant that returns ([]string{}, nil) instead of an error when no files match.
Caching contract: only non-empty result sets are cached. The cache stores []string directly (not a comma-joined string) so that paths containing commas are preserved correctly on cache hits. Cached slices are cloned before being returned, so callers may safely mutate the returned slice without affecting the cache.
func GetHighlightSettings ¶ added in v1.148.0
func GetHighlightSettings(config *schema.AtmosConfiguration) *schema.SyntaxHighlighting
GetHighlightSettings returns the syntax highlighting settings from the config or defaults
func GetHighlightedJSON ¶ added in v1.176.0
func GetHighlightedJSON(atmosConfig *schema.AtmosConfiguration, data any) (string, error)
func GetHighlightedYAML ¶ added in v1.176.0
func GetHighlightedYAML(atmosConfig *schema.AtmosConfiguration, data any) (string, error)
func GetLatestGitHubRepoRelease ¶ added in v1.60.0
GetLatestGitHubRepoRelease returns the latest release tag for a GitHub repository. Deprecated: Use github.GetLatestRelease instead.
func GetLineEnding ¶ added in v1.155.0
func GetLineEnding() string
GetLineEnding returns the appropriate line ending for the current platform.
func GetNextShellLevel ¶ added in v1.173.0
GetNextShellLevel increments the ATMOS_SHLVL and returns the new value or an error if maximum depth is exceeded.
func HasAppendTag ¶ added in v1.221.0
HasAppendTag reports whether a value carries the !append metadata wrapper produced during YAML parsing.
func HasYAMLPosition ¶ added in v1.194.0
func HasYAMLPosition(positions PositionMap, path string) bool
HasYAMLPosition checks if a position exists for a specific JSONPath.
func HighlightCodeWithConfig ¶ added in v1.148.0
func HighlightCodeWithConfig(config *schema.AtmosConfiguration, code string, format ...string) (string, error)
HighlightCodeWithConfig highlights the given code using the provided configuration.
func InitializeMarkdown ¶ added in v1.162.0
func InitializeMarkdown(atmosConfig *schema.AtmosConfiguration)
InitializeMarkdown initializes a new Markdown renderer.
func Intern ¶ added in v1.195.0
func Intern(_ *schema.AtmosConfiguration, s string) string
Intern returns a canonical representation of the string. If the string already exists in the intern pool, returns the existing instance. Otherwise, adds the string to the pool and returns it. This reduces memory usage by deduplicating common strings across YAML files.
Common interned strings in Atmos:
- YAML keys: "vars", "settings", "metadata", "env", "backend", "terraform", "helmfile".
- Stack names, component names, file paths.
- Common values: "true", "false", "default", region names.
Thread-safe for concurrent use. Note: perf.Track removed from this critical path function as it's called millions of times. Statistics use atomic operations instead of locks to avoid contention in the hot path.
func InternStringsInMap ¶ added in v1.195.0
func InternStringsInMap(atmosConfig *schema.AtmosConfiguration, data any) any
InternStringsInMap recursively interns all string keys and string values in a map[string]any. This reduces memory usage by deduplicating common strings across YAML files. Common interned values: component names, stack names, "true"/"false", region names, etc. Note: perf.Track removed from this critical path function as it's called recursively many times.
func IsDirectory ¶
IsDirectory checks if the path is a directory.
func IsPathAbsolute ¶ added in v1.4.0
IsPathAbsolute checks if the provided file path is absolute.
func IsTemplateFile ¶ added in v1.193.0
IsTemplateFile returns true if the file path has a .yaml.tmpl or .yml.tmpl extension.
func IsValidScheme ¶ added in v1.169.0
IsValidScheme checks if the URL scheme is valid.
func IsYaml ¶
IsYaml checks if the file has YAML extension (does not check file schema, nor validates the file).
func JoinPath ¶ added in v1.193.0
JoinPath joins two paths handling absolute paths correctly. If the second path is absolute, it returns the second path. Otherwise, it joins the paths using filepath.Join which:
- Normalizes path separators to the OS-specific separator
- Cleans the resulting path (removes . and .. elements)
- Handles empty paths appropriately
This function follows standard Go path behavior and does NOT check if the path exists on the filesystem.
func JoinPathAndValidate ¶ added in v1.193.0
JoinPathAndValidate joins paths and validates the result exists in filesystem. It builds on JoinPath for path construction and adds filesystem validation.
func JoinPaths ¶ added in v1.193.0
JoinPaths joins a base path with each item in the path slice and returns a slice of joined paths. This is a pure path construction function without filesystem validation.
func MapKeyExists ¶ added in v1.4.1
MapKeyExists checks if a key already defined in a map
func MatchWildcard ¶ added in v1.170.0
MatchWildcard checks if a string matches a wildcard pattern. The pattern can include glob patterns: - '*' matches any sequence of non-separator characters. - '?' matches any single non-separator character. - '[abc]' matches any character within the brackets. - '[a-z]' matches any character in the range. - '**' matches any number of directories or files recursively. - '{abc,xyz}` matches the string "abc" or "xyz".
func PathMatch ¶ added in v1.4.21
PathMatch returns true if `name` matches the file name `pattern`. PathMatch normalizes both pattern and name to use forward slashes for cross-platform compatibility, then uses doublestar.Match (not PathMatch) which expects Unix-style paths. This ensures patterns work consistently on Windows, Linux, and macOS.
Note: perf.Track() removed from this hot path to reduce overhead (called 2M+ times). Results are cached to avoid redundant pattern matching during affected detection.
func PrintAsJSON ¶
func PrintAsJSON(atmosConfig *schema.AtmosConfiguration, data any) error
PrintAsJSON prints the provided value as a JSON document to the console with syntax highlighting. Use PrintAsJSONSimple for non-TTY output (pipes, redirects) to avoid expensive highlighting.
func PrintAsJSONSimple ¶ added in v1.195.0
func PrintAsJSONSimple(atmosConfig *schema.AtmosConfiguration, data any) error
PrintAsJSONSimple prints the provided value as JSON document without syntax highlighting. This is a fast-path for non-TTY output (files, pipes, redirects) that skips expensive syntax highlighting, reducing output time significantly for large configurations.
func PrintAsYAML ¶
func PrintAsYAML(atmosConfig *schema.AtmosConfiguration, data any) error
PrintAsYAML prints the provided value as YAML document to the console with syntax highlighting. Use PrintAsYAMLSimple for non-TTY output (pipes, redirects) to avoid expensive highlighting.
func PrintAsYAMLSimple ¶ added in v1.195.0
func PrintAsYAMLSimple(atmosConfig *schema.AtmosConfiguration, data any) error
PrintAsYAMLSimple prints the provided value as YAML document without syntax highlighting. This is a fast-path for non-TTY output (files, pipes, redirects) that skips expensive syntax highlighting, reducing output time from ~6s to <1s for large configurations.
func PrintAsYAMLToFileDescriptor ¶ added in v1.74.0
func PrintAsYAMLToFileDescriptor(atmosConfig *schema.AtmosConfiguration, data any) error
PrintAsYAMLToFileDescriptor prints the provided value as YAML document to a file descriptor.
func PrintMessage ¶ added in v1.5.0
func PrintMessage(message string)
PrintMessage prints the message to the console with automatic secret masking.
func PrintMessageToUpgradeToAtmosLatestRelease ¶ added in v1.119.0
func PrintMessageToUpgradeToAtmosLatestRelease(latestVersion string)
PrintMessageToUpgradeToAtmosLatestRelease prints info on how to upgrade Atmos to the latest version.
func PrintfMarkdown ¶ added in v1.162.0
func PrintfMarkdown(format string, a ...interface{})
PrintfMarkdown prints a message in Markdown format.
func PrintfMarkdownToTUI ¶ added in v1.194.0
func PrintfMarkdownToTUI(format string, a ...interface{})
PrintfMarkdownToTUI prints a message in Markdown format to stderr. This is useful for notices, warnings, and other messages that should not interfere with stdout when piping command output.
func PrintfMessageToTUI ¶ added in v1.166.0
PrintfMessageToTUI prints the message to the stderr with automatic secret masking.
func ProcessIncludeRawTag ¶ added in v1.191.0
func ProcessIncludeRawTag( atmosConfig *schema.AtmosConfiguration, node *yaml.Node, val string, file string, ) error
ProcessIncludeRawTag processes the !include.raw tag. It always returns the file content as a raw string, regardless of extension.
func ProcessIncludeTag ¶ added in v1.191.0
func ProcessIncludeTag( atmosConfig *schema.AtmosConfiguration, node *yaml.Node, val string, file string, ) error
ProcessIncludeTag processes the !include tag with extension-based parsing. It parses files based on their extension, not their content.
func ProcessTagCwd ¶ added in v1.202.0
ProcessTagCwd returns the current working directory. If a path argument is provided after the tag, it is joined with CWD. Format: "!cwd" or "!cwd <path>".
func ProcessTagEnv ¶ added in v1.173.0
func ProcessTagEnv( input string, envContext EnvVarContext, ) (string, error)
func ProcessTagExec ¶ added in v1.173.0
func ProcessTagGitRoot ¶ added in v1.173.0
ProcessTagGitRoot returns the root directory of the Git repository using go-git.
func ProcessTagRandom ¶ added in v1.201.0
ProcessTagRandom processes the !random YAML function and returns a random integer within the specified range. Usage:
!random - Generate random number between 0 and 65535 !random max - Generate random number between 0 and max !random min max - Generate random number between min and max
Examples:
!random -> random number 0-65535 !random 100 -> random number 0-100 !random 1024 65535 -> random number 1024-65535
func ResetInternStats ¶ added in v1.195.0
func ResetInternStats()
ResetInternStats resets interning statistics. Primarily for testing. Uses atomic stores for lock-free access.
func ResolveRelativePath ¶ added in v1.153.0
ResolveRelativePath checks if a path is relative to the current directory and if so, resolves it relative to the current file's directory. It ensures the resolved path exists within the base path.
func SearchConfigFile ¶ added in v1.94.0
SearchConfigFile searches for a config file in the provided path. If the path has a file extension, it checks if the file exists. If the path does not have a file extension, it checks for the existence of the file with the provided path and the possible config file extensions.
func ShellRunner ¶ added in v1.173.0
ShellRunner uses mvdan.cc/sh/v3's parser and interpreter to run a shell script and divert its stdout .
func SliceContainsInt ¶
SliceContainsInt checks if an int is present in a slice.
func SliceOfInterfacesToSliceOfStrings ¶ added in v1.88.0
SliceOfInterfacesToSliceOfStrings converts a slice of any to a slice of strings. Each element is converted to a string using fmt.Sprintf with the "%v" format.
func SliceRemoveFlag ¶ added in v1.192.0
SliceRemoveFlag removes all occurrences of a flag from a slice, handling both "--flag" and "--flag=value" forms. This function safely handles multiple occurrences and returns a new slice with all flag instances removed. The function preserves the original slice and returns a new slice with the flags removed.
func SortMapByKeysAndValuesUniq ¶ added in v1.54.0
SortMapByKeysAndValuesUniq sorts the provided map by the keys, sorts the map values (lists of strings), and makes the values unique
func SplitStringByDelimiter ¶ added in v1.153.0
SplitStringByDelimiter splits a string by the delimiter, not splitting inside quotes.
func StringKeysFromMap ¶
StringKeysFromMap returns a slice of sorted string keys from the provided map
func TrimBasePathFromPath ¶
TrimBasePathFromPath trims the base path prefix from the path.
func UniqueStrings ¶
UniqueStrings returns a unique subset of the string slice provided.
func UnmarshalYAML ¶ added in v1.88.0
UnmarshalYAML unmarshals YAML into a Go type.
func UnmarshalYAMLFromFile ¶ added in v1.153.0
func UnmarshalYAMLFromFile[T any](atmosConfig *schema.AtmosConfiguration, input string, file string) (T, error)
UnmarshalYAMLFromFile unmarshals YAML downloaded from a file into a Go type.
func WrapLongStrings ¶ added in v1.194.0
WrapLongStrings walks a data structure and converts strings longer than maxLength to LongString type, which will be encoded as YAML folded scalars (>) for better readability.
func WrapWithAppendTag ¶ added in v1.221.0
WrapWithAppendTag wraps a list value with append metadata. This metadata is used during merging to identify lists that should be appended.
func WriteTerraformBackendConfigToFileAsHcl ¶ added in v1.7.0
func WriteTerraformBackendConfigToFileAsHcl( filePath string, backendType string, backendConfig map[string]any, ) error
WriteTerraformBackendConfigToFileAsHcl writes the provided Terraform backend config to the specified file. https://dev.to/pdcommunity/write-terraform-files-in-go-with-hclwrite-2e1j https://pkg.go.dev/github.com/hashicorp/hcl/v2/hclwrite
func WriteToFileAsHcl ¶ added in v1.6.0
WriteToFileAsHcl converts the provided value to HCL (HashiCorp Language) and writes it to the specified file.
func WriteToFileAsJSON ¶
WriteToFileAsJSON converts the provided value to JSON and writes it to the specified file
func WriteToFileAsYAML ¶
WriteToFileAsYAML converts the provided value to YAML and writes it to the specified file.
func WriteToFileAsYAMLWithConfig ¶ added in v1.176.0
Types ¶
type ComponentInfo ¶ added in v1.201.0
type ComponentInfo struct {
ComponentType string // "terraform", "helmfile", "packer"
FolderPrefix string // "vpc", "networking/vpc", etc. (empty if component is at base)
ComponentName string // "security-group", "vpc", etc.
FullComponent string // Full component path as it appears in stack config (folder_prefix/component or just component)
}
ComponentInfo represents extracted component information from a filesystem path.
func ExtractComponentInfoFromPath ¶ added in v1.201.0
func ExtractComponentInfoFromPath( atmosConfig *schema.AtmosConfiguration, path string, ) (*ComponentInfo, error)
ExtractComponentInfoFromPath extracts component information from an absolute filesystem path. Returns error if path is not within configured component directories.
Examples:
- /project/components/terraform/vpc/security-group → {terraform, vpc, security-group, vpc/security-group}
- /project/components/terraform/vpc → {terraform, "", vpc, vpc}
- /project/components/helmfile/app → {helmfile, "", app, app}
type EnvVarContext ¶ added in v1.199.0
type EnvVarContext interface {
// GetComponentEnvSection returns the component's env section map, or nil if not available.
GetComponentEnvSection() map[string]any
}
EnvVarContext provides context for environment variable lookup. It allows !env to check stack manifest env sections before falling back to OS environment.
type InternStats ¶ added in v1.195.0
type InternStats struct {
Requests int64 // Total intern requests.
Hits int64 // Cache hits (string already interned).
Misses int64 // Cache misses (new string added).
SavedBytes int64 // Estimated memory saved (bytes).
}
InternStats represents string interning statistics.
func GetInternStats ¶ added in v1.195.0
func GetInternStats() InternStats
GetInternStats returns current interning statistics. Useful for debugging and performance analysis. Uses atomic loads for lock-free access.
type LongString ¶ added in v1.194.0
type LongString string
LongString is a string type that encodes as a YAML folded scalar (>). This is used to wrap long strings across multiple lines for better readability.
func (LongString) MarshalYAML ¶ added in v1.194.0
func (s LongString) MarshalYAML() (interface{}, error)
MarshalYAML implements yaml.Marshaler to encode as a folded scalar.
type Position ¶ added in v1.194.0
Position represents a line and column position in a YAML file.
func GetYAMLPosition ¶ added in v1.194.0
func GetYAMLPosition(positions PositionMap, path string) Position
GetYAMLPosition gets the position for a specific JSONPath from the position map. Returns Position{0, 0} if not found.
type PositionMap ¶ added in v1.194.0
PositionMap maps JSONPath-style paths to their positions in a YAML file.
func ExtractYAMLPositions ¶ added in v1.194.0
func ExtractYAMLPositions(node *yaml.Node, enabled bool) PositionMap
ExtractYAMLPositions extracts line/column positions from a YAML node tree. Returns a map of JSONPath -> Position for all values in the YAML. If enabled is false, returns an empty map immediately (zero overhead).
func UnmarshalYAMLFromFileWithPositions ¶ added in v1.194.0
func UnmarshalYAMLFromFileWithPositions[T any](atmosConfig *schema.AtmosConfiguration, input string, file string) (T, PositionMap, error)
UnmarshalYAMLFromFileWithPositions unmarshals YAML and returns position information. The positions map contains line/column information for each value in the YAML. If atmosConfig.TrackProvenance is false, returns an empty position map. Uses caching with content-aware keys to correctly handle template-processed files. The cache key includes both file path and content hash, ensuring that: - Static files are cached by path (same content = cache hit) - Template files with same context get cache hits - Template files with different contexts get separate cache entries (correct behavior).
type YAMLOptions ¶ added in v1.176.0
type YAMLOptions struct {
Indent int
}
Source Files
¶
- array_cleanup.go
- component_path_utils.go
- component_reverse_path_utils.go
- cty_utils.go
- doc_utils.go
- file_extensions.go
- file_utils.go
- git.go
- github_utils.go
- glob_utils.go
- go_getter_utils.go
- hcl_utils.go
- highlight_utils.go
- json_utils.go
- jsonpath.go
- log_utils.go
- map_utils.go
- markdown_utils.go
- shell_utils.go
- slice_utils.go
- string_utils.go
- version_utils.go
- wildcard.go
- yaml_func_append.go
- yaml_func_env.go
- yaml_func_exec.go
- yaml_func_random.go
- yaml_include_by_extension.go
- yaml_position.go
- yaml_utils.go
- yq_utils.go