Documentation ¶
Index ¶
- func AllowStdIn(do *delayOpenFile)
- func AllowStdout(dow *delayOpenFile)
- func CombineCmdArgsFuncs(funcs ...func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error
- func DeferClose(c func() error, e *error)
- func DeferWrap(e *error, format string, args ...interface{})
- func DelayOpenRead(path string, options ...DelayOpenReadOption) io.ReadCloser
- func DelayOpenWrite(path string, sensitive bool, options ...DelayOpenWriteOption) io.WriteCloser
- func InitFile(path string, mode os.FileMode, creator func(w io.Writer) error) (created bool, err error)
- func ParseFields(text, separator string, minFields int, fields ...interface{}) (fieldsParsed int, err error)
- func ReadAll(path string, options ...DelayOpenReadOption) (data []byte, err error)
- func RemoveFileIfEmpty(path string, retErr *error)
- func StdInOnce(cmd *cobra.Command, args []string) error
- func WriteAll(path string, data []byte, sensitive bool, options ...DelayOpenWriteOption) (err error)
- type DelayOpenReadOption
- type DelayOpenWriteOption
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 DeferClose ¶
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 ParseFields ¶
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 ¶
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)