utils

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DiagInvalid hcl.DiagnosticSeverity = iota
	DiagError
	DiagWarning
	DiagInfo
	DiagDebug
)

Variables

View Source
var (
	Fs afero.Fs       = afero.NewOsFs()
	Io AbstractIoUtil = &IoUtil{}
	Wd string         = ""
)
View Source
var ErrSilent = errors.New("ErrSilent")

Functions

func Abs added in v0.1.3

func Abs(rel string) string

func All

func All[T any](s []T, test func(T) bool) bool

func Any

func Any[T any](s []T, test func(T) bool) bool

func Contains

func Contains(s []string, v string) bool

func Filter

func Filter[T any](s []T, test func(T) bool) []T

func FormatMap

func FormatMap(m map[string]string, separator string, alignRight bool) string

func GetCaptures

func GetCaptures(re *regexp.Regexp, findAll bool, capture string, s string) ([]string, error)

"findAll" gives back multiple matches. if set to false, only the first match is captured capture is either the group index as a string or the group name

func GetURLsFromArgs

func GetURLsFromArgs(args []string) ([]string, hcl.Diagnostics)

func Getwd added in v0.1.3

func Getwd() error

sets the working directory globally

func HasNamedCaptures

func HasNamedCaptures(re *regexp.Regexp) (bool, []string)

func IsValidURL added in v0.1.3

func IsValidURL(str string) (*url.URL, bool)

func ParseURLList

func ParseURLList(contents, filename string) ([]string, hcl.Diagnostics)

func Plural

func Plural(count int, singular string, plural string) string

func PrintDiag

func PrintDiag(w io.Writer, diag *hcl.Diagnostic)

func Unique

func Unique(s []string) []string

func ZipMap

func ZipMap(keys []string, values []string) map[string]string

Types

type AbstractIoUtil added in v0.1.6

type AbstractIoUtil interface {
	WriteFile(fs afero.Fs, filename string, data []byte, perm os.FileMode) error
	ReadFile(fs afero.Fs, filename string) ([]byte, error)
	Exists(fs afero.Fs, path string) (bool, error)
}

type IoUtil added in v0.1.6

type IoUtil struct{}

func (*IoUtil) Exists added in v0.1.6

func (i *IoUtil) Exists(fs afero.Fs, path string) (bool, error)

func (*IoUtil) ReadFile added in v0.1.6

func (i *IoUtil) ReadFile(fs afero.Fs, filename string) ([]byte, error)

func (*IoUtil) WriteFile added in v0.1.6

func (i *IoUtil) WriteFile(fs afero.Fs, filename string, data []byte, perm os.FileMode) error

Jump to

Keyboard shortcuts

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