cmdutil

package module
v0.0.0-...-e2c53ed Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 8 Imported by: 7

README

Package cloudeng.io/cmdutil

import cloudeng.io/cmdutil

Package cmdutil provides support for implementing command line utilities.

Functions

Func CopyAll
func CopyAll(fromDir, toDir string, ovewrite bool) error

CopyAll will create an exact copy, including permissions, of a local filesystem hierarchy. The arguments must both refer to directories. A trailing slash (/) for the fromDir copies the contents of fromDir rather than fromDir itself. Thus:

CopyAll("a/b", "c") is the same as CopyAll("a/b/", "c/b")
and both create an exact copy of the tree a/b rooted at c/b.

If overwrite is set any existing files will be overwritten. Existing directories will always have their contents updated. It is suitable for very large directory trees since it uses filepath.Walk.

Func CopyFile
func CopyFile(from, to string, perms os.FileMode, overwrite bool) (returnErr error)

CopyFile will copy a local file with the option to overwrite an existing file and to set the permissions on the new file. It uses chmod to explicitly set permissions. It is not suitable for very large fles.

Func Exit
func Exit(format string, args ...interface{})

Exit formats and prints the supplied parameters to os.Stderr and then calls os.Exit(1).

Func HandleSignals
func HandleSignals(fn func(), signals ...os.Signal)

HandleSignals will asynchronously invoke the supplied function when the specified signals are received.

Func IsDir
func IsDir(path string) bool

IsDir returns true iff path exists and is a directory.

Func ListDir
func ListDir(dir string) ([]string, error)

ListDir returns the lexicographically ordered directories that lie beneath dir.

Func ListRegular
func ListRegular(dir string) ([]string, error)

ListRegular returns the lexicographically ordered regular files that lie beneath dir.

Func ParseYAMLConfig
func ParseYAMLConfig(spec []byte, cfg interface{}) error

ParseYAMLConfig will parse the yaml config in spec into the requested type. It provides improved error reporting via YAMLErrorWithSource.

Func ParseYAMLConfigFile
func ParseYAMLConfigFile(ctx context.Context, filename string, cfg interface{}) error

ParseYAMLConfigFile reads a yaml config file as per ParseYAMLConfig using file.FSReadFile to read the file. The use of FSReadFile allows for the configuration file to be read from storage system, including from embed.FS, instead of the local filesystem if an instance of fs.ReadFileFS is stored in the context.

Func ParseYAMLConfigString
func ParseYAMLConfigString(spec string, cfg interface{}) error

ParseYAMLConfigString is like ParseYAMLConfig but for a string.

Func VCSInfo
func VCSInfo() (revision string, lastCommit time.Time, dirty, ok bool)
Func YAMLErrorWithSource
func YAMLErrorWithSource(spec []byte, err error) error

YAMLErrorWithSource returns an error that includes the yaml source code that was the cause of the error to help with debugging YAML errors. Note that the errors reported for the yaml parser may be inaccurate in terms of the lines the error is reported on. This seems to be particularly true for lists where errors with use of tabs to indent are often reported against the previous line rather than the offending one.

Documentation

Overview

Package cmdutil provides support for implementing command line utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyAll

func CopyAll(fromDir, toDir string, ovewrite bool) error

CopyAll will create an exact copy, including permissions, of a local filesystem hierarchy. The arguments must both refer to directories. A trailing slash (/) for the fromDir copies the contents of fromDir rather than fromDir itself. Thus:

CopyAll("a/b", "c") is the same as CopyAll("a/b/", "c/b")
and both create an exact copy of the tree a/b rooted at c/b.

If overwrite is set any existing files will be overwritten. Existing directories will always have their contents updated. It is suitable for very large directory trees since it uses filepath.Walk.

func CopyFile

func CopyFile(from, to string, perms os.FileMode, overwrite bool) (returnErr error)

CopyFile will copy a local file with the option to overwrite an existing file and to set the permissions on the new file. It uses chmod to explicitly set permissions. It is not suitable for very large fles.

func Exit

func Exit(format string, args ...interface{})

Exit formats and prints the supplied parameters to os.Stderr and then calls os.Exit(1).

func HandleSignals

func HandleSignals(fn func(), signals ...os.Signal)

HandleSignals will asynchronously invoke the supplied function when the specified signals are received.

func IsDir

func IsDir(path string) bool

IsDir returns true iff path exists and is a directory.

func ListDir

func ListDir(dir string) ([]string, error)

ListDir returns the lexicographically ordered directories that lie beneath dir.

func ListRegular

func ListRegular(dir string) ([]string, error)

ListRegular returns the lexicographically ordered regular files that lie beneath dir.

func VCSInfo

func VCSInfo() (revision string, lastCommit time.Time, dirty, ok bool)

Types

This section is empty.

Directories

Path Synopsis
Package boolexpr provides a boolean expression evaluator and parser.
Package boolexpr provides a boolean expression evaluator and parser.
Package cmdexec provides a means of executing multiple subcommands with the ability to expand the command line arguments using Go's text/template package and environment variables.
Package cmdexec provides a means of executing multiple subcommands with the ability to expand the command line arguments using Go's text/template package and environment variables.
Package expect provides support for making expectations on the contents of input streams.
Package expect provides support for making expectations on the contents of input streams.
Package flags provides support for working with flag variables, and for managing flag variables by embedding them in structs.
Package flags provides support for working with flag variables, and for managing flag variables by embedding them in structs.
Package profiling provides support for enabling profiling of command line tools via flags.
Package profiling provides support for enabling profiling of command line tools via flags.
Package signals provides support for working with operating system signals and contexts.
Package signals provides support for working with operating system signals and contexts.
Package structdoc provides a means of exposing struct tags for use when generating documentation for those structs.
Package structdoc provides a means of exposing struct tags for use when generating documentation for those structs.
Package subcmd provides a multi-level command facility of the following form:
Package subcmd provides a multi-level command facility of the following form:

Jump to

Keyboard shortcuts

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