tool

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteFile

func DeleteFile(dst string) (err error)

DeleteFile deletes a file if exists

func FileExists

func FileExists(filepath string) bool

FileExists returns the existence of an directory or file

func LaunchEditor

func LaunchEditor(editor string, fnamegetter func() string) (content []byte, err error)

LaunchEditor launches the specified editor

func LaunchEditorWith

func LaunchEditorWith(editor, filename string) (content []byte, err error)

LaunchEditorWith launches the specified editor with a filename

func Must

func N

func N[T constraints.Float | constraints.Integer](s string) (ret T, err error)

func ParseT

func ParseT[T Parseable](str string) (T, error)

ParseT do short converting on numeric types.

func ReadFile

func ReadFile(filename string) ([]byte, error)

ReadFile reads the file named by filename and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.

As of Go 1.16, this function simply calls os.ReadFile.

func SplitCommandString

func SplitCommandString(s string, quoteChars ...rune) []string

SplitCommandString allows split command-line by quote characters (default is double-quote).

In: `bash -c 'echo hello world!'` Out: []string{ "bash", "-c", "echo hello world!"}

func StringToBool

func StringToBool(val string, defaultVal ...bool) (ret bool)

func StripQuotes

func StripQuotes(s string) string

StripQuotes strips first and last quote char (double quote or single quote).

func ToBool

func ToBool(val any, defaultVal ...bool) (ret bool)

ToBool translate a value (int, bool, string) to boolean

func TrimQuotes

func TrimQuotes(s string) string

TrimQuotes strips first and last quote char (double quote or single quote).

Types

type Parseable

type Parseable interface {
	// NOTE: I didn't check that fmt.Sscanf can accept all these,
	// but it seems like it probably should...
	string | bool | int | int8 | int16 | int32 | int64 |
		uint | uint8 | uint16 | uint32 | uint64 | uintptr |
		float32 | float64 | complex64 | complex128
}

Jump to

Keyboard shortcuts

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