cmdutil

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCancel = errors.New("CancelError")

ErrCancel signals user-initiated cancellation.

View Source
var ErrSilent = errors.New("SilentError")

ErrSilent is an error that triggers exit code 1 without any error messaging.

View Source
var IsTerminal = func(f *os.File) bool {
	return isatty.IsTerminal(f.Fd()) || IsCygwinTerminal(f)
}

IsTerminal returns true if the given file descriptor is a terminal.

View Source
var TerminalSize = func(w interface{}) (int, int, error) {
	if f, isFile := w.(*os.File); isFile {
		return term.GetSize(int(f.Fd()))
	}

	return 0, 0, fmt.Errorf("%v is not a file", w)
}

TerminalSize returns the height and width in characters of the given terminal.

Functions

func AddJSONFlags

func AddJSONFlags(cmd *cobra.Command, exportTarget *Exporter, fields []string)

AddJSONFlags adds JSON output flags to a command.

func CheckAuth

func CheckAuth(cfg config.Config) bool

CheckAuth checks if the user is authenticated.

func DisableAuthCheck

func DisableAuthCheck(cmd *cobra.Command)

DisableAuthCheck disables the auth check for the given command.

func FlagErrorWrap

func FlagErrorWrap(err error) error

FlagErrorWrap returns a new FlagError that wraps the specified error.

func FlagErrorf

func FlagErrorf(format string, args ...interface{}) error

FlagErrorf returns a new FlagError that wraps an error produced by fmt.Errorf(format, args...).

func HostnameValidator

func HostnameValidator(v interface{}) error

HostnameValidator is a function that validates a hostname.

func IsAuthCheckEnabled

func IsAuthCheckEnabled(cmd *cobra.Command) bool

IsAuthCheckEnabled checks if the auth check is enabled for the given command.

func IsCygwinTerminal

func IsCygwinTerminal(f *os.File) bool

IsCygwinTerminal returns true if the given file descriptor is a Cygwin terminal.

func IsUserCancellation

func IsUserCancellation(err error) bool

IsUserCancellation returns true if the user cancelled the operation.

func MutuallyExclusive

func MutuallyExclusive(message string, conditions ...bool) error

MutuallyExclusive sets of flags that are mutually exclusive.

func ReadFile

func ReadFile(filename string, stdin io.ReadCloser) ([]byte, error)

ReadFile reads the file at the given path and returns the contents. If "-" is given, it reads from stdin.

Types

type Exporter

type Exporter interface {
	Fields() []string
	Write(io *iostreams.IOStreams, data interface{}) error
}

Exporter is a function that can be used to export data to a writer.

type FlagError

type FlagError struct {
	// contains filtered or unexported fields
}

FlagError indicates an error processing command-line flags or other arguments. Such errors cause the application to display the usage message.

func (*FlagError) Error

func (fe *FlagError) Error() string

Error implements the error interface.

func (*FlagError) Unwrap

func (fe *FlagError) Unwrap() error

Unwrap returns the underlying error.

type JSONFlagError

type JSONFlagError struct {
	// contains filtered or unexported fields
}

JSONFlagError is returned by AddJSONFlags when the user specifies an invalid JSON field.

type TablePrinter

type TablePrinter interface {
	IsTTY() bool
	AddField(string, func(int, string) string, func(string) string)
	EndRow()
	Render() error
}

TablePrinter is an interface for printing tabular data.

func NewTablePrinter

func NewTablePrinter(io *iostreams.IOStreams) TablePrinter

NewTablePrinter returns a TablePrinter that prints to the given io.Writer.

func NewTablePrinterWithOptions

func NewTablePrinterWithOptions(io *iostreams.IOStreams, opts TablePrinterOptions) TablePrinter

NewTablePrinterWithOptions returns a TablePrinter that prints to the given io.Writer.

type TablePrinterOptions

type TablePrinterOptions struct {
	IsTTY bool
}

TablePrinterOptions are options for configuring a TablePrinter.

Jump to

Keyboard shortcuts

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