util

package
v0.0.0-...-3746c95 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowStdIn

func AllowStdIn(do *delayOpenFile)

AllowStdIn will cause the returned ReaderCloser to read from os.StdIn if the file name was "-". os.StdIn will not be closed when the ReadCloser is Close()d

func AllowStdout

func AllowStdout(dow *delayOpenFile)

AllowStdout will cause the returned WriteCloser to write to os.StdOut if the file name was "-". os.StdOut will not be closed when the WriteCloser is Close()d

func CombineCmdArgsFuncs

func CombineCmdArgsFuncs(funcs ...func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error

func DeferClose

func DeferClose(c func() error, e *error)

func DeferWrap

func DeferWrap(e *error, format string, args ...interface{})

func DelayOpenRead

func DelayOpenRead(path string, options ...DelayOpenReadOption) io.ReadCloser

DelayOpenRead returns an io.ReadCloser which will open the given file for reading upon the first call to Read().

func DelayOpenWrite

func DelayOpenWrite(path string, sensitive bool, options ...DelayOpenWriteOption) io.WriteCloser

DelayOpenWrite returns an io.WriteCloser that will open the given file for writing upon the first call to Write(). The file will be created (or truncated if it already exists) and the mode will be 0666 or 0600 depending on whether sensitive is true. The process umask will likely convert that to something stricter.

func InitFile

func InitFile(path string, mode os.FileMode, creator func(w io.Writer) error) (created bool, err error)

func ParseFields

func ParseFields(text, separator string, minFields int, fields ...interface{}) (fieldsParsed int, err error)

func ReadAll

func ReadAll(path string, options ...DelayOpenReadOption) (data []byte, err error)

ReadAll opens a file, reads all the contents, closes the file, and then returns the contents. This allows the use of DelayOpenReadOption(s) with io.ReadAll()

func RemoveFileIfEmpty

func RemoveFileIfEmpty(path string, retErr *error)

func StdInOnce

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

func WriteAll

func WriteAll(path string, data []byte, sensitive bool, options ...DelayOpenWriteOption) (err error)

Types

type DelayOpenReadOption

type DelayOpenReadOption func(dor *delayOpenFile)

func AllowStdInPrompt

func AllowStdInPrompt(prompt string) DelayOpenReadOption

AllowStdInPrompt behaves like AllowStdIn with addition that if and only if os.Stdin is a terminal then the prompt is written to os.StdErr upon the first call to Read(). The prompt has the suffix instructing the user to finish with Ctrl-D

type DelayOpenWriteOption

type DelayOpenWriteOption func(dow *delayOpenFile)

Jump to

Keyboard shortcuts

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