Documentation
¶
Index ¶
- Variables
- func CopyFile(src string, dst string) (int64, error)
- func FileExists(filePath string) (bool, error)
- func MapSortedByKey[Map ~map[K]V, K cmp.Ordered, V any](m Map) iter.Seq2[K, V]
- func RunInDirectory(path string, f func() error) (err error)
- func RunInDirectory1P[P1 any](path string, f func() (P1, error)) (P1, error)
- func RunInDirectory2P[P1 any, P2 any](path string, f func() (P1, P2, error)) (P1, P2, error)
- func RunInDirectory3P[P1 any, P2 any, P3 any](path string, f func() (P1, P2, P3, error)) (P1, P2, P3, error)
- func RunWithEnvs(envVariables map[string]string, f func() error) error
- func RunWithEnvs1P[P1 any](envVariables map[string]string, f func() (P1, error)) (P1, error)
- func RunWithEnvs2P[P1 any, P2 any](envVariables map[string]string, f func() (P1, P2, error)) (P1, P2, error)
- func RunWithEnvs3P[P1 any, P2 any, P3 any](envVariables map[string]string, f func() (P1, P2, P3, error)) (P1, P2, P3, error)
- func RunWithOptions(f func() error, options ...RunOption) (err error)
- func RunWithOptions1P[P1 any](f func() (P1, error), options ...RunOption) (P1, error)
- func RunWithOptions2P[P1 any, P2 any](f func() (P1, P2, error), options ...RunOption) (P1, P2, error)
- func RunWithOptions3P[P1 any, P2 any, P3 any](f func() (P1, P2, P3, error), options ...RunOption) (P1, P2, P3, error)
- func SliceAppendIf[T any](slice []T, cond bool, values ...T) []T
- func SliceAppendIfFunc[T any](slice []T, cond bool, f func() []T) []T
- func SliceAppendIfMissing[T comparable](slice []T, values ...T) []T
- func SliceAppendIfMissingFunc[T comparable](slice []T, f func() []T) []T
- func SlicePrepend[T any](slice []T, elems ...T) []T
- func SlicePrependIf[T any](slice []T, cond bool, values ...T) []T
- func SlicePrependIfFunc[T any](slice []T, cond bool, f func() []T) []T
- func StringContainsAny(s string, substrings ...string) bool
- func StringSplitByNewLine(value string) []string
- func StringTrimAllPrefix(s, prefix string) string
- func StringTrimAllSuffix(s, suffix string) string
- func StringTrimNewlineSuffix(v string) string
- func Ternary[T any](cond bool, vtrue, vfalse T) T
- func TernaryFunc[T any](cond bool, vtrue, vfalse func() T) T
- func TernaryFuncErr[T any](cond bool, vtrue, vfalse func() (T, error)) (T, error)
- func WriteJsonToFile(object any, outputFilePath string, indented bool) error
- type CmdRunner
- func (r *CmdRunner) Clone() *CmdRunner
- func (r *CmdRunner) Run(executable string, arguments ...string) error
- func (r *CmdRunner) RunGetCombinedOutput(executable string, arguments ...string) (string, error)
- func (r *CmdRunner) RunGetOutput(executable string, arguments ...string) (string, string, error)
- func (r *CmdRunner) WithConsoleOutput() *CmdRunner
- func (r *CmdRunner) WithEnv(key, value string) *CmdRunner
- func (r *CmdRunner) WithSkipPostProcessOutput() *CmdRunner
- func (r *CmdRunner) WithWorkingDirectory(workingDirectory string) *CmdRunner
- type RunOption
- type TablePrinter
- type TablePrinterAlignment
- type TablePrinterColumn
- type TablePrinterOptions
- type TablePrinterRow
- type TablePrinterStyle
Constants ¶
This section is empty.
Variables ¶
var Cmd cmdNamespace = 0
Contains methods regarding commands.
var CmdRunners cmdRunners = cmdRunners{ Default: NewCmdRunner(), Console: NewCmdRunner().WithConsoleOutput(), }
Contains a few pre-configured CmdRunners for easy access.
var Env envNamespace = 0
Contains methods regarding environment variables.
var TablePrinterStyleAscii = &TablePrinterStyle{
TopLeft: "+",
TopRight: "+",
TopIntersection: "+",
TopSpacer: "-",
MiddleLeft: "|",
MiddleRight: "|",
MiddleIntersection: "|",
SeparatorLeft: "+",
SeparatorRight: "+",
SeparatorIntersection: "+",
SeparatorSpacer: "-",
BottomLeft: "+",
BottomRight: "+╯",
BottomIntersection: "+",
BottomSpacer: "-",
}
var TablePrinterStyleDefault = &TablePrinterStyle{
TopLeft: "┌",
TopRight: "┐",
TopIntersection: "┬",
TopSpacer: "─",
MiddleLeft: "│",
MiddleRight: "│",
MiddleIntersection: "│",
SeparatorLeft: "├",
SeparatorRight: "┤",
SeparatorIntersection: "┼",
SeparatorSpacer: "─",
BottomLeft: "└",
BottomRight: "┘",
BottomIntersection: "┴",
BottomSpacer: "─",
}
var TablePrinterStyleRounded = &TablePrinterStyle{
TopLeft: "╭",
TopRight: "╮",
TopIntersection: "┬",
TopSpacer: "─",
MiddleLeft: "│",
MiddleRight: "│",
MiddleIntersection: "│",
SeparatorLeft: "├",
SeparatorRight: "┤",
SeparatorIntersection: "┼",
SeparatorSpacer: "─",
BottomLeft: "╰",
BottomRight: "╯",
BottomIntersection: "┴",
BottomSpacer: "─",
}
Functions ¶
func FileExists ¶ added in v0.6.0
Checks if a file exists (and it is not a directory).
func MapSortedByKey ¶
Returns an iterator for the given map that yields the key-value pairs in sorted order.
func RunInDirectory ¶ added in v0.4.0
func RunInDirectory1P ¶ added in v0.4.0
func RunInDirectory2P ¶ added in v0.4.0
func RunInDirectory3P ¶ added in v0.4.0
func RunWithEnvs ¶ added in v0.4.0
func RunWithEnvs1P ¶ added in v0.4.0
func RunWithEnvs2P ¶ added in v0.4.0
func RunWithEnvs3P ¶ added in v0.4.0
func RunWithOptions ¶ added in v0.4.0
Runs a given method with additional options.
func RunWithOptions1P ¶ added in v0.4.0
Runs a given method with returns one parameter with additional options.
func RunWithOptions2P ¶ added in v0.4.0
func RunWithOptions2P[P1 any, P2 any](f func() (P1, P2, error), options ...RunOption) (P1, P2, error)
Runs a given method with returns two parameters with additional options.
func RunWithOptions3P ¶ added in v0.4.0
func RunWithOptions3P[P1 any, P2 any, P3 any](f func() (P1, P2, P3, error), options ...RunOption) (P1, P2, P3, error)
Runs a given method with returns three parameters with additional options.
func SliceAppendIf ¶
Appends the given values to a slice if the condition is fulfilled.
func SliceAppendIfFunc ¶
Appends the given value if the condition is fulfilled. The value is lazily evaluated.
func SliceAppendIfMissing ¶ added in v0.8.0
func SliceAppendIfMissing[T comparable](slice []T, values ...T) []T
Appends the given elements if it is missing in the slice.
func SliceAppendIfMissingFunc ¶ added in v0.8.0
func SliceAppendIfMissingFunc[T comparable](slice []T, f func() []T) []T
Appends the given elements if it is missing in the slice. The value is lazily evaluated.
func SlicePrepend ¶
func SlicePrepend[T any](slice []T, elems ...T) []T
Prepends the given elements to the given array.
func SlicePrependIf ¶
Prepends the given values to a slice if the condition is fulfilled.
func SlicePrependIfFunc ¶
Prepends the given value if the condition is fulfilled. The value is lazily evaluated.
func StringContainsAny ¶
Checks if the string contains at least one of the substrings.
func StringSplitByNewLine ¶ added in v0.2.0
Splits the string by new line characters, supporting both "\n" and "\r\n".
func StringTrimAllPrefix ¶ added in v0.2.0
Trims all occurrences of the given prefix from the start of the string.
func StringTrimAllSuffix ¶ added in v0.2.0
Trims all occurrences of the given suffix from the end of the string.
func StringTrimNewlineSuffix ¶ added in v0.2.0
Trims all occurrences of newline characters from the end of the string.
func Ternary ¶
A simple ternary function that returns one of two values based on a boolean condition.
func TernaryFunc ¶
Like Ternary but uses functions to lazily evaluate the values.
func TernaryFuncErr ¶
Like TernaryFunc but returns an error as well.
Types ¶
type CmdRunner ¶ added in v0.3.0
type CmdRunner struct {
WorkingDirectory string
OutputToConsole bool
SkipPostProcessOutput bool
AdditionalEnv map[string]string
}
The CmdRunner struct that holds the configuration for running commands.
func NewCmdRunner ¶ added in v0.3.0
func NewCmdRunner() *CmdRunner
Creates a new CmdRunner with the given options.
func (*CmdRunner) RunGetCombinedOutput ¶ added in v0.3.0
Runs the command and returns the output from stdout and stderr combined.
func (*CmdRunner) RunGetOutput ¶ added in v0.3.0
Runs the command and returns the separate output from stdout and stderr.
func (*CmdRunner) WithConsoleOutput ¶ added in v0.3.0
Sets to output to console.
func (*CmdRunner) WithSkipPostProcessOutput ¶ added in v0.3.0
Sets to skip post-processing of output (trimming newlines).
func (*CmdRunner) WithWorkingDirectory ¶ added in v0.3.0
Sets the working directory for the command.
type RunOption ¶ added in v0.4.0
type RunOption interface {
// contains filtered or unexported methods
}
An option that can be used to run which is applied before the run and reverted after.
func RunOptionInDirectory ¶ added in v0.4.0
Option that allows changing the working directory during a run.
func RunOptionWithEnvs ¶ added in v0.4.0
Option that allows setting/overriding environment variables during a run.
type TablePrinter ¶
type TablePrinter struct {
Options *TablePrinterOptions
Columns []*TablePrinterColumn
Rows []*TablePrinterRow
}
func NewTablePrinter ¶
func NewTablePrinter(options *TablePrinterOptions) *TablePrinter
Create a new TablePrinter with the given options or default options.
func (*TablePrinter) AddRows ¶
func (tp *TablePrinter) AddRows(valueRows ...[]any)
Add rows to the TablePrinter with the given values.
func (*TablePrinter) Print ¶
func (tp *TablePrinter) Print(writer io.Writer)
Print the table to the given writer.
func (*TablePrinter) PrintToFile ¶
func (tp *TablePrinter) PrintToFile(filePath string) error
Print the table to a file.
func (*TablePrinter) SetHeaders ¶
func (tp *TablePrinter) SetHeaders(headers ...string)
Set the headers for the TablePrinter.
type TablePrinterAlignment ¶
type TablePrinterAlignment int
const ( TABLE_PRINTER_ALIGNMENT_LEFT TablePrinterAlignment = iota TABLE_PRINTER_ALIGNMENT_RIGHT )
type TablePrinterColumn ¶
type TablePrinterColumn struct {
Header string
HeaderAlignment TablePrinterAlignment
ValueAlignment TablePrinterAlignment
Hide bool
// contains filtered or unexported fields
}
type TablePrinterOptions ¶
type TablePrinterOptions struct {
Padding int
Style *TablePrinterStyle
}
type TablePrinterRow ¶
type TablePrinterRow struct {
Values []string
}
type TablePrinterStyle ¶
type TablePrinterStyle struct {
TopLeft string
TopRight string
TopIntersection string
TopSpacer string
MiddleLeft string
MiddleRight string
MiddleIntersection string
SeparatorLeft string
SeparatorRight string
SeparatorIntersection string
SeparatorSpacer string
BottomLeft string
BottomRight string
BottomIntersection string
BottomSpacer string
}