utils

package
v1.123.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultStackConfigFileExtension       = ".yaml"
	DefaultVendoringManifestFileExtension = ".yaml"
	YamlFileExtension                     = ".yaml"
	YmlFileExtension                      = ".yml"
	YamlTemplateExtension                 = ".yaml.tmpl"
	YmlTemplateExtension                  = ".yml.tmpl"
	TemplateExtension                     = ".tmpl"
)
View Source
const (
	LogLevelTrace   = "Trace"
	LogLevelDebug   = "Debug"
	LogLevelInfo    = "Info"
	LogLevelWarning = "Warning"
)

Variables

View Source
var (
	AtmosYamlTags = []string{
		"!terraform.output",
		"!exec",
		"!template",
	}
)

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

func ConvertEnvVars(envVarsMap map[string]any) []string

ConvertEnvVars convert 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

func ConvertFromJSON(jsonString string) (any, error)

ConvertFromJSON converts the provided JSON-encoded string to Go data types

func ConvertPathsToAbsolutePaths

func ConvertPathsToAbsolutePaths(paths []string) ([]string, error)

ConvertPathsToAbsolutePaths converts a slice of paths to a slice of absolute paths

func ConvertToHclAst added in v1.6.0

func ConvertToHclAst(data any) (ast.Node, error)

ConvertToHclAst converts the provided value to an HCL abstract syntax tree

func ConvertToJSON added in v1.6.0

func ConvertToJSON(data any) (string, error)

ConvertToJSON converts the provided value to a JSON-encoded string

func ConvertToJSONFast added in v1.6.0

func ConvertToJSONFast(data any) (string, error)

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) (string, error)

ConvertToYAML converts the provided data to a YAML string

func EnsureDir added in v1.5.0

func EnsureDir(fileName string) error

EnsureDir accepts a file path and creates all the intermediate subdirectories

func FileExists

func FileExists(filename string) bool

FileExists checks if the file exists and is not a directory

func FileOrDirExists added in v1.11.3

func FileOrDirExists(filename string) bool

FileOrDirExists checks if the file or directory exists

func GetAllFilesInDir added in v1.55.0

func GetAllFilesInDir(dir string) ([]string, error)

GetAllFilesInDir returns all files in the provided directory and all subdirectories

func GetAllYamlFilesInDir added in v1.55.0

func GetAllYamlFilesInDir(dir string) ([]string, error)

GetAllYamlFilesInDir returns all YAML files in the provided directory and all subdirectories

func GetFileNameFromURL added in v1.97.0

func GetFileNameFromURL(rawURL string) (string, error)

GetFileNameFromURL extracts the file name from a URL

func GetGlobMatches added in v1.4.21

func GetGlobMatches(pattern string) ([]string, error)

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 GetLatestGitHubRepoRelease added in v1.60.0

func GetLatestGitHubRepoRelease(owner string, repo string) (string, error)

GetLatestGitHubRepoRelease returns the latest release tag for a GitHub repository

func IsDirectory

func IsDirectory(path string) (bool, error)

IsDirectory checks if the path is a directory

func IsPathAbsolute added in v1.4.0

func IsPathAbsolute(path string) bool

IsPathAbsolute checks if the provided file path is absolute

func IsSocket added in v1.83.1

func IsSocket(path string) (bool, error)

IsSocket checks if a file is a socket

func IsURL added in v1.97.0

func IsURL(s string) bool

IsURL checks if a string is a URL

func IsYaml

func IsYaml(file string) bool

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

func JoinAbsolutePathWithPath(basePath string, providedPath string) (string, error)

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

func JoinAbsolutePathWithPaths(basePath string, paths []string) ([]string, error)

JoinAbsolutePathWithPaths joins a base path with each item in the path slice and returns a slice of absolute paths

func LogDebug added in v1.33.0

func LogDebug(cliConfig schema.CliConfiguration, message string)

LogDebug logs the provided debug message

func LogError added in v1.33.0

func LogError(cliConfig schema.CliConfiguration, err error)

LogError logs errors to std.Error

func LogErrorAndExit added in v1.33.0

func LogErrorAndExit(cliConfig schema.CliConfiguration, err error)

LogErrorAndExit logs errors to std.Error and exits with an error code

func LogInfo added in v1.33.0

func LogInfo(cliConfig schema.CliConfiguration, message string)

LogInfo logs the provided info message

func LogTrace added in v1.33.0

func LogTrace(cliConfig schema.CliConfiguration, message string)

LogTrace logs the provided trace message

func LogWarning added in v1.33.0

func LogWarning(cliConfig schema.CliConfiguration, message string)

LogWarning logs the provided warning message

func MapKeyExists added in v1.4.1

func MapKeyExists(m map[string]any, key string) bool

MapKeyExists checks if a key already defined in a map

func MapOfInterfacesToMapOfStrings added in v1.111.0

func MapOfInterfacesToMapOfStrings(input map[any]any) map[string]any

func PathMatch added in v1.4.21

func PathMatch(pattern, name string) (bool, error)

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

func PrintAsHcl(data any) error

PrintAsHcl prints the provided value as HCL (HashiCorp Language) document to the console

func PrintAsJSON

func PrintAsJSON(data any) error

PrintAsJSON prints the provided value as JSON document to the console

func PrintAsJSONToFileDescriptor added in v1.74.0

func PrintAsJSONToFileDescriptor(cliConfig schema.CliConfiguration, data any) error

PrintAsJSONToFileDescriptor prints the provided value as JSON document to a file descriptor

func PrintAsYAML

func PrintAsYAML(data any) error

PrintAsYAML prints the provided value as YAML document to the console

func PrintAsYAMLToFileDescriptor added in v1.74.0

func PrintAsYAMLToFileDescriptor(cliConfig schema.CliConfiguration, 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

func PrintMessageInColor added in v1.54.0

func PrintMessageInColor(message string, messageColor *color.Color)

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 SearchConfigFile added in v1.94.0

func SearchConfigFile(path string) (string, bool)

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

func SliceContainsInt(s []int, i int) bool

SliceContainsInt checks if an int is present in a slice

func SliceContainsString

func SliceContainsString(s []string, str string) bool

SliceContainsString checks if a string is present in a slice

func SliceContainsStringHasPrefix added in v1.23.0

func SliceContainsStringHasPrefix(s []string, prefix string) bool

SliceContainsStringHasPrefix checks if a slice contains a string that begins with the given prefix

func SliceContainsStringStartsWith

func SliceContainsStringStartsWith(s []string, str string) bool

SliceContainsStringStartsWith checks if a slice contains a string that the given string begins with

func SliceOfInterfacesToSliceOdStrings added in v1.9.0

func SliceOfInterfacesToSliceOdStrings(input []any) []string

SliceOfInterfacesToSliceOdStrings converts a slice of any to a slice os strings

func SliceOfInterfacesToSliceOfStrings added in v1.88.0

func SliceOfInterfacesToSliceOfStrings(input []any) ([]string, error)

SliceOfInterfacesToSliceOfStrings takes a slice of interfaces and converts it to a slice of strings

func SliceOfPathsContainsPath added in v1.17.0

func SliceOfPathsContainsPath(paths []string, checkPath string) bool

SliceOfPathsContainsPath checks if a slice of file paths contains a path

func SliceOfStringsToSpaceSeparatedString

func SliceOfStringsToSpaceSeparatedString(s []string) string

SliceOfStringsToSpaceSeparatedString checks if an int is present in a slice

func SortMapByKeysAndValuesUniq added in v1.54.0

func SortMapByKeysAndValuesUniq(m map[string][]string) map[string][]string

SortMapByKeysAndValuesUniq sorts the provided map by the keys, sorts the map values (lists of strings), and makes the values unique

func StringKeysFromMap

func StringKeysFromMap(m map[string]any) []string

StringKeysFromMap returns a slice of sorted string keys from the provided map

func TrimBasePathFromPath

func TrimBasePathFromPath(basePath string, path string) string

TrimBasePathFromPath trims the base path prefix from the path

func UniqueStrings

func UniqueStrings(input []string) []string

UniqueStrings returns a unique subset of the string slice provided

func UnmarshalYAML added in v1.88.0

func UnmarshalYAML[T any](input string) (T, error)

func WriteTerraformBackendConfigToFileAsHcl added in v1.7.0

func WriteTerraformBackendConfigToFileAsHcl(
	cliConfig schema.CliConfiguration,
	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(
	cliConfig schema.CliConfiguration,
	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

func WriteToFileAsJSON(filePath string, data any, fileMode os.FileMode) error

WriteToFileAsJSON converts the provided value to JSON and writes it to the specified file

func WriteToFileAsYAML

func WriteToFileAsYAML(filePath string, data any, fileMode os.FileMode) error

WriteToFileAsYAML converts the provided value to YAML and writes it to the specified file

Types

This section is empty.

Jump to

Keyboard shortcuts

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