Documentation
¶
Overview ¶
Package utils provides markdown utilities for error handling and output formatting in the Atmos CLI application.
Index ¶
- Constants
- Variables
- func Coalesce[T comparable](v ...T) (result T)
- func ConvertEnvVars(envVarsMap map[string]any) []string
- func ConvertFromJSON(jsonString string) (any, error)
- func ConvertPathsToAbsolutePaths(paths []string) ([]string, error)
- func ConvertToHclAst(data any) (ast.Node, error)
- func ConvertToJSON(data any) (string, error)
- func ConvertToJSONFast(data any) (string, error)
- func ConvertToYAML(data any) (string, error)
- func DefaultHighlightSettings() *schema.SyntaxHighlighting
- func DetectFormatAndParseFile(filename string) (any, error)
- func DisplayDocs(componentDocs string, usePager bool) error
- func EnsureDir(fileName string) error
- func EnvironToMap() map[string]string
- func EvaluateYqExpression(atmosConfig *schema.AtmosConfiguration, data any, yq string) (any, error)
- func ExtractAtmosConfig(data any) schema.AtmosConfiguration
- func FileExists(filename string) bool
- func FileOrDirExists(filename string) bool
- func GetAllFilesInDir(dir string) ([]string, error)
- func GetAllYamlFilesInDir(dir string) ([]string, error)
- func GetFileNameFromURL(rawURL string) (string, error)
- func GetGlobMatches(pattern string) ([]string, error)
- func GetHighlightSettings(config schema.AtmosConfiguration) *schema.SyntaxHighlighting
- func GetLatestGitHubRepoRelease(owner string, repo string) (string, error)
- func GetLineEnding() string
- func HighlightCode(code string, lexerName string, theme string) (string, error)
- func HighlightCodeWithConfig(code string, config schema.AtmosConfiguration, format ...string) (string, error)
- func InitializeMarkdown(atmosConfig schema.AtmosConfiguration)
- func IsDirectory(path string) (bool, error)
- func IsHCL(data string) bool
- func IsJSON(data string) bool
- func IsPathAbsolute(path string) bool
- func IsSocket(path string) (bool, error)
- func IsURL(s string) bool
- func IsYAML(data string) bool
- func IsYaml(file string) bool
- func JSONToMapOfInterfaces(input string) (schema.AtmosSectionMapType, error)
- func JoinAbsolutePathWithPath(basePath string, providedPath string) (string, error)
- func JoinAbsolutePathWithPaths(basePath string, paths []string) ([]string, error)
- func LogDebug(message string)deprecated
- func LogError(err error)deprecated
- func LogErrorAndExit(err error)deprecated
- func LogInfo(message string)deprecated
- func LogTrace(message string)deprecated
- func LogWarning(message string)deprecated
- func MapKeyExists(m map[string]any, key string) bool
- func MapOfInterfaceKeysToMapOfStringKeys(input map[any]any) map[string]any
- func MapOfInterfacesToMapOfStrings(input map[string]any) map[string]string
- func PathMatch(pattern, name string) (bool, error)
- func PrintAsHcl(data any) error
- func PrintAsJSON(data any) error
- func PrintAsJSONToFileDescriptor(atmosConfig schema.AtmosConfiguration, data any) error
- func PrintAsYAML(data any) error
- func PrintAsYAMLToFileDescriptor(atmosConfig schema.AtmosConfiguration, data any) error
- func PrintErrorInColor(message string)deprecated
- func PrintErrorMarkdown(title string, err error, suggestion string)
- func PrintErrorMarkdownAndExit(title string, err error, suggestion string)
- func PrintInvalidUsageErrorAndExit(err error, suggestion string)
- func PrintMessage(message string)
- func PrintMessageInColor(message string, messageColor *color.Color)
- func PrintMessageToUpgradeToAtmosLatestRelease(latestVersion string)
- func PrintfErrorMarkdown(format string, a ...interface{})
- func PrintfMarkdown(format string, a ...interface{})
- func ResolveRelativePath(path string, basePath string) string
- func SearchConfigFile(path string) (string, bool)
- func SliceContainsInt(s []int, i int) bool
- func SliceContainsString(s []string, str string) bool
- func SliceContainsStringHasPrefix(s []string, prefix string) bool
- func SliceContainsStringStartsWith(s []string, str string) bool
- func SliceOfInterfacesToSliceOdStrings(input []any) []string
- func SliceOfInterfacesToSliceOfStrings(input []any) ([]string, error)
- func SliceOfPathsContainsPath(paths []string, checkPath string) bool
- func SliceOfStringsToSpaceSeparatedString(s []string) string
- func SortMapByKeysAndValuesUniq(m map[string][]string) map[string][]string
- func SplitStringAtFirstOccurrence(s string, sep string) [2]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 WriteTerraformBackendConfigToFileAsHcl(atmosConfig schema.AtmosConfiguration, filePath string, backendType string, ...) error
- func WriteToFileAsHcl(atmosConfig schema.AtmosConfiguration, filePath string, data any, ...) error
- func WriteToFileAsJSON(filePath string, data any, fileMode os.FileMode) error
- func WriteToFileAsYAML(filePath string, data any, fileMode os.FileMode) error
- type HighlightWriter
Constants ¶
const ( DefaultStackConfigFileExtension = ".yaml" YamlFileExtension = ".yaml" YmlFileExtension = ".yml" YamlTemplateExtension = ".yaml.tmpl" YmlTemplateExtension = ".yml.tmpl" TemplateExtension = ".tmpl" )
const ( LogLevelTrace = "Trace" LogLevelDebug = "Debug" LogLevelInfo = "Info" LogLevelWarning = "Warning" )
const ( // Atmos YAML functions AtmosYamlFuncExec = "!exec" AtmosYamlFuncStore = "!store" AtmosYamlFuncTemplate = "!template" AtmosYamlFuncTerraformOutput = "!terraform.output" AtmosYamlFuncEnv = "!env" AtmosYamlFuncInclude = "!include" // For internal use by Atmos when processing the `!include` function AtmosYamlFuncIncludeLocalFile = "!include-local-file" AtmosYamlFuncIncludeGoGetter = "!include-go-getter" )
Variables ¶
var AtmosYamlTags = []string{ AtmosYamlFuncExec, AtmosYamlFuncStore, AtmosYamlFuncTemplate, AtmosYamlFuncTerraformOutput, AtmosYamlFuncEnv, AtmosYamlFuncInclude, }
Functions ¶
func Coalesce ¶ added in v1.31.0
func Coalesce[T comparable](v ...T) (result T)
Coalesce returns the first non-empty argument. Arguments must be comparable
func ConvertEnvVars ¶ added in v1.4.22
ConvertEnvVars converts ENV vars from a map to a list of strings in the format ["key1=val1", "key2=val2", "key3=val3" ...]
func ConvertFromJSON ¶ added in v1.9.0
ConvertFromJSON converts the provided JSON-encoded string to Go data types
func ConvertPathsToAbsolutePaths ¶
ConvertPathsToAbsolutePaths converts a slice of paths to a slice of absolute paths
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
ConvertToYAML converts the provided data to a YAML string
func DefaultHighlightSettings ¶ added in v1.148.0
func DefaultHighlightSettings() *schema.SyntaxHighlighting
DefaultHighlightSettings returns the default syntax highlighting settings
func DetectFormatAndParseFile ¶ added in v1.153.0
DetectFormatAndParseFile detects the format of the file (JSON, YAML, HCL) and parses the file into a Go type For all other formats, it just reads the file and returns the content as a string
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 EnvironToMap ¶ added in v1.160.4
EnvironToMap converts all the environment variables in the environment into a map of strings
func EvaluateYqExpression ¶ added in v1.140.0
func ExtractAtmosConfig ¶ added in v1.148.0
func ExtractAtmosConfig(data any) schema.AtmosConfiguration
ExtractAtmosConfig extracts the Atmos configuration from any data type. It handles both direct AtmosConfiguration instances and pointers to AtmosConfiguration. If the data is neither, it returns an empty configuration.
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 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 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
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 GetLatestGitHubRepoRelease ¶ added in v1.60.0
GetLatestGitHubRepoRelease returns the latest release tag for a GitHub repository
func GetLineEnding ¶ added in v1.155.0
func GetLineEnding() string
GetLineEnding returns the appropriate line ending for the current platform
func HighlightCode ¶ added in v1.148.0
HighlightCode highlights the given code using chroma with the specified lexer and theme
func HighlightCodeWithConfig ¶ added in v1.148.0
func HighlightCodeWithConfig(code string, config schema.AtmosConfiguration, 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)
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 IsYaml ¶
IsYaml checks if the file has YAML extension (does not check file schema, nor validates the file)
func JSONToMapOfInterfaces ¶ added in v1.88.0
func JSONToMapOfInterfaces(input string) (schema.AtmosSectionMapType, error)
JSONToMapOfInterfaces takes a JSON string as input and returns a map[string]any
func JoinAbsolutePathWithPath ¶ added in v1.4.27
JoinAbsolutePathWithPath checks if the provided path is absolute. If the provided path is relative, it joins the base path with the path and returns the absolute path
func JoinAbsolutePathWithPaths ¶
JoinAbsolutePathWithPaths joins a base path with each item in the path slice and returns a slice of absolute paths
func LogErrorAndExit
deprecated
added in
v1.33.0
func LogErrorAndExit(err error)
Deprecated: Use `log.Fatal` instead. This function will be removed in a future release. LogErrorAndExit logs errors to std.Error and exits with an error code
func LogWarning
deprecated
added in
v1.33.0
func LogWarning(message string)
Deprecated: Use `log.Warn` instead. This function will be removed in a future release. LogWarning logs the provided warning message
func MapKeyExists ¶ added in v1.4.1
MapKeyExists checks if a key already defined in a map
func MapOfInterfaceKeysToMapOfStringKeys ¶ added in v1.160.3
MapOfInterfaceKeysToMapOfStringKeys converts map[any]any to map[string]any
func MapOfInterfacesToMapOfStrings ¶ added in v1.111.0
MapOfInterfacesToMapOfStrings converts map[string]any to map[string]string
func PathMatch ¶ added in v1.4.21
PathMatch returns true if `name` matches the file name `pattern`. PathMatch will automatically use your system's path separator to split `name` and `pattern`. On systems where the path separator is `'\'`, escaping will be disabled.
Note: this is meant as a drop-in replacement for filepath.Match(). It assumes that both `pattern` and `name` are using the system's path separator. If you can't be sure of that, use filepath.ToSlash() on both `pattern` and `name`, and then use the Match() function instead.
func PrintAsHcl ¶ added in v1.6.0
PrintAsHcl prints the provided value as HCL (HashiCorp Language) document to the console
func PrintAsJSON ¶
PrintAsJSON prints the provided value as JSON document to the console
func PrintAsJSONToFileDescriptor ¶ added in v1.74.0
func PrintAsJSONToFileDescriptor(atmosConfig schema.AtmosConfiguration, data any) error
PrintAsJSONToFileDescriptor prints the provided value as JSON document to a file descriptor
func PrintAsYAML ¶
PrintAsYAML prints the provided value as YAML document to the console
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 PrintErrorInColor
deprecated
added in
v1.152.0
func PrintErrorInColor(message string)
Deprecated: Use `log.Error` instead. This function will be removed in a future release.
func PrintErrorMarkdown ¶ added in v1.162.0
func PrintErrorMarkdownAndExit ¶ added in v1.162.0
func PrintInvalidUsageErrorAndExit ¶ added in v1.162.0
func PrintMessage ¶ added in v1.5.0
func PrintMessage(message string)
PrintMessage prints the message to the console
func PrintMessageInColor ¶ added in v1.54.0
PrintMessageInColor prints the message to the console using the provided color
func PrintMessageToUpgradeToAtmosLatestRelease ¶ added in v1.119.0
func PrintMessageToUpgradeToAtmosLatestRelease(latestVersion string)
PrintMessageToUpgradeToAtmosLatestRelease prints info on how to upgrade Atmos to the latest version
func PrintfErrorMarkdown ¶ added in v1.162.0
func PrintfErrorMarkdown(format string, a ...interface{})
PrintfErrorMarkdown prints a formatted error message in markdown format
func PrintfMarkdown ¶ added in v1.162.0
func PrintfMarkdown(format string, a ...interface{})
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 SliceContainsInt ¶
SliceContainsInt checks if an int is present in a slice
func SliceContainsString ¶
SliceContainsString checks if a string is present in a slice
func SliceContainsStringHasPrefix ¶ added in v1.23.0
SliceContainsStringHasPrefix checks if a slice contains a string that begins with the given prefix
func SliceContainsStringStartsWith ¶
SliceContainsStringStartsWith checks if a slice contains a string that the given string begins with
func SliceOfInterfacesToSliceOdStrings ¶ added in v1.9.0
SliceOfInterfacesToSliceOdStrings converts a slice of any to a slice os strings
func SliceOfInterfacesToSliceOfStrings ¶ added in v1.88.0
SliceOfInterfacesToSliceOfStrings takes a slice of interfaces and converts it to a slice of strings
func SliceOfPathsContainsPath ¶ added in v1.17.0
SliceOfPathsContainsPath checks if a slice of file paths contains a path
func SliceOfStringsToSpaceSeparatedString ¶
SliceOfStringsToSpaceSeparatedString checks if an int is present in a slice
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 SplitStringAtFirstOccurrence ¶ added in v1.160.4
SplitStringAtFirstOccurrence splits a string into two parts at the first occurrence of the separator
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 WriteTerraformBackendConfigToFileAsHcl ¶ added in v1.7.0
func WriteTerraformBackendConfigToFileAsHcl( atmosConfig schema.AtmosConfiguration, 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
func WriteToFileAsHcl( atmosConfig schema.AtmosConfiguration, filePath string, data any, fileMode os.FileMode, ) error
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
Types ¶
type HighlightWriter ¶ added in v1.148.0
type HighlightWriter struct {
// contains filtered or unexported fields
}
HighlightWriter returns an io.Writer that highlights code written to it
func NewHighlightWriter ¶ added in v1.148.0
func NewHighlightWriter(w io.Writer, config schema.AtmosConfiguration, format ...string) *HighlightWriter
NewHighlightWriter creates a new HighlightWriter
func (*HighlightWriter) Write ¶ added in v1.148.0
func (h *HighlightWriter) Write(p []byte) (n int, err error)
Write implements io.Writer The returned byte count n is the length of p regardless of whether the highlighting process changes the actual number of bytes written to the underlying writer. This maintains compatibility with the io.Writer interface contract while still providing syntax highlighting functionality.