utils

package
v0.0.0-...-5a15cda Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoBellStdout = &noBellStdout{}

NoBellStdout returns a stdout wrapper that doesn't ring the terminal bell https://github.com/manifoldco/promptui/issues/49 & https://github.com/manifoldco/promptui/issues/49#issuecomment-1012640880

Functions

func ExecuteCommand

func ExecuteCommand(name string, args ...string) (string, error)

ExecuteCommand executes a command and returns the output

func ExecuteCommandBare

func ExecuteCommandBare(name string, stdOut, stdErr io.Writer, args ...string) error

ExecuteCommandBare executes a command and writes the output to the given writers

func FileExists

func FileExists(path string) bool

FileExists checks if a file exists

func IsCommandInstalled

func IsCommandInstalled(name string) bool

IsCommandAvailable checks if a command is available

func Max

func Max[T constraints.Ordered](x, y T) T

Max returns the larger of x or y.

func Min

func Min[T constraints.Ordered](x, y T) T

Min returns the smaller of x or y.

func ReadJson

func ReadJson(file afero.File, v any) error

ReadJson reads a json file, removes utf-8 BOM and unmarshals it

func RemoveUTF8BOM

func RemoveUTF8BOM(data []byte) []byte

RemoveUTF8BOM removes the UTF8 BOM from the given byte array if present

func WrapCobraCommandHandler

func WrapCobraCommandHandler(fun func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string)

WrapCobraCommand wraps a cobra command with a function that may return error and logs the error

func WriteJson

func WriteJson(file afero.File, v any) error

WriteJson writes a json file

Types

type Comparable

type Comparable interface {
	Compare(Comparable) int
}

Comparable is an interface that can be used to compare two objects

type ComparableNamed

type ComparableNamed interface {
	Comparable
	Named
}

ComparableNamed is an interface that can be used to sort a slice of named objects

type ComparableNamedSlice

type ComparableNamedSlice[T ComparableNamed] []T

NamedSortableSlice is an interface that can be used to sort a slice of named objects

func (ComparableNamedSlice[T]) Filter

func (slice ComparableNamedSlice[T]) Filter(test func(T) bool) (ret ComparableNamedSlice[T])

Filter filters a slice of any type using a test function

func (ComparableNamedSlice[T]) Len

func (slice ComparableNamedSlice[T]) Len() int

Implement the sort.Interface interface

func (ComparableNamedSlice[T]) Less

func (slice ComparableNamedSlice[T]) Less(i, j int) bool

func (ComparableNamedSlice[T]) Names

func (slice ComparableNamedSlice[T]) Names() (ret []string)

Names returns the names of the give slice of named objects

func (ComparableNamedSlice[T]) Swap

func (slice ComparableNamedSlice[T]) Swap(i, j int)

type Named

type Named interface {
	Named() string
}

Named is an interface that can be used to get the name of an object

type StringSlice

type StringSlice []string

StringSlice is a slice of strings, helper type used for extension methods

func (StringSlice) LongestLength

func (slice StringSlice) LongestLength() int

LongestLength returns the length of the longest string in the given slice

func (StringSlice) ToLower

func (slice StringSlice) ToLower() StringSlice

ToLower returns a copy of the given slice of strings with all strings lowercased

Jump to

Keyboard shortcuts

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