util

package
v0.0.2-rc1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Utility functions for directories and files

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateClusterIncludesExcludes

func CalculateClusterIncludesExcludes(input map[string]string, filters PathFilterOptions) []string

Using the allClusterParams variable and command flags to create a list of clusters to generate. Clusters can be filtered with "=" for equality or "~" for regex match.

func CheckObjectMatch

func CheckObjectMatch(input gjson.Result, filterString string) bool

Checks if a input object matches a filter string. The filter string can be an equality match or a regex match.

func Colorize

func Colorize(input interface{}, colorNum int, disabled bool) string

Colorize function from zerolog console.go file to replicate their coloring functionality. Source: https://github.com/rs/zerolog/blob/a21d6107dcda23e36bc5cfd00ce8fdbe8f3ddc23/console.go#L389

func FatalErrorCheck

func FatalErrorCheck(message string, err error)

Logs an error and exits the program if the error is not nil. Saves 3 lines per use and centralizes fatal errors for rewriting.

func FetchRepoUrl

func FetchRepoUrl(url string, destination string, performFetch bool) error

Fetch a git repo from a url and clone it to a destination directory. If the performFetch flag is false, it will log the command that would be run and return without doing anything.

func Filter

func Filter(vs []string, f func(string) bool) []string

Filter returns a new slice containing only the elements that satisfy the predicate function. From https://gobyexample.com/collection-functions

func FilterItems

func FilterItems(input map[string]string, pfilter PathFilterOptions) []string

Given a map of string, filter them based on the provided options. The map value is parsed as a gjson result and then checked against the provided options.

func FormatJsonnetString

func FormatJsonnetString(input string) (string, error)

Formats a jsonnet string using the default options.

func FormatJsonnetStringCustom

func FormatJsonnetStringCustom(input string, opts formatter.Options) (string, error)

Formats a jsonnet string using custom options.

func GetClusterFilenames

func GetClusterFilenames(searchDir string) ([]types.Kr8Cluster, error)

Get a list of cluster from within a directory. Walks the directory tree, creating a types.Kr8Cluster for each cluster.jsonnet file found.

func GetClusterParamsFilenames

func GetClusterParamsFilenames(basePath string, targetPath string) []string

Get all cluster parameters within a directory. Walks through the directory hierarchy and returns all paths to `params.jsonnet` files.

func GetClusterPaths

func GetClusterPaths(searchDir string, clusterName string) string

Get a specific cluster within a directory by name. Returns the path to the cluster.

func GetDefaultFormatOptions

func GetDefaultFormatOptions() formatter.Options

Configures the default options for the jsonnet formatter.

func JsonnetPrint

func JsonnetPrint(output string, format string, color bool)

Print the jsonnet output in the specified format. Acceptable formats are: yaml, stream, json.

func Pretty

func Pretty(input string, colorOutput bool) string

Pretty formats the input jsonnet string with indentation and optional color output.

func WriteObjToJsonFile

func WriteObjToJsonFile(filename string, path string, objStruct interface{}) (string, error)

Write out a struct to a specified path and file. If successful, returns what was written. If not successful, returns an error.

Types

type PathFilterOptions

type PathFilterOptions struct {
	// Comma-separated list of include filters
	// Filters can include:
	//
	// regex filters using the "~" operator. For example, "name~^myregex$"
	// equality matches using the "=" operator. For example, "name=myvalue"
	// substring matches using the "=" operator. For example, "name=myvalue"
	//
	// If no operator is provided, it is treated as a substring match against the "name" field.
	Includes string
	// Comma-separated list of exclude filters.
	// Filters can include:
	//
	// regex filters using the "~" operator. For example, "name~^myregex$"
	// equality matches using the "=" operator. For example, "name=myvalue"
	// substring matches using the "=" operator. For example, "name=myvalue"
	//
	// If no operator is provided, it is treated as a substring match against the "name" field.
	Excludes string
	// Comma separated cluster names.
	// Filters keys on exact match.
	Clusters string
	// Comma separated component names.
	Components string
}

Fill with string to include and exclude, using kr8's special parsing.

Jump to

Keyboard shortcuts

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