cli

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2020 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultEnvSeparator defines how to join env var names.
	DefaultEnvSeparator = "_"
	// DefaultCommandDelimiters defines which delimiters should be replaced.
	DefaultCommandDelimiters = []string{" ", "-"}
)

Functions

func PrettyJSON

func PrettyJSON(data interface{}) (string, error)

PrettyJSON returns a 4-space indented JSON text. Can be useful for printing out structs.

Types

type App

type App struct {
	*kingpin.Application
	// contains filtered or unexported fields
}

App represents a command-line application that wraps the kingpin library and adds additional functionality.

func NewApp

func NewApp(name, help string) *App

NewApp defines a new command-line application.

func (*App) CheckStrictEnv added in v0.34.0

func (a *App) CheckStrictEnv() error

CheckStrictEnv checks that every environment variable that starts with the app name is recognized by the application.

func (*App) Command

func (a *App) Command(name, help string) *CommandClause

Command defines a new top-level command with the given name and help text.

func (*App) ExtraEnvVarFunc added in v0.24.0

func (a *App) ExtraEnvVarFunc(f func(key string) bool) *App

ExtraEnvVarFunc takes a function that determines additional environment variables recognized by the application.

func (*App) Flag

func (a *App) Flag(name, help string) *Flag

Flag defines a new flag with the given long name and help text, adding an environment variable default configurable by APP_FLAG_NAME.

func (*App) PrintEnv

func (a *App) PrintEnv(w io.Writer, verbose bool, osEnv func() []string) error

PrintEnv reads all environment variables starting with the app name and writes a table with the keys and their status: set, empty, unrecognized. The value of environment variables are not printed out for security reasons. The list is limited to variables that are actually set in the environment. Setting verbose to true will also include all known variables that are not set.

func (*App) Version

func (a *App) Version(version string) *App

Version adds a flag for displaying the application version number.

type CommandClause

type CommandClause struct {
	*kingpin.CmdClause
	// contains filtered or unexported fields
}

CommandClause represents a command clause in a command0-line application.

func (*CommandClause) Command

func (cmd *CommandClause) Command(name, help string) *CommandClause

Command adds a new subcommand to this command.

func (*CommandClause) Flag

func (cmd *CommandClause) Flag(name, help string) *Flag

Flag defines a new flag with the given long name and help text, adding an environment variable default configurable by APP_COMMAND_FLAG_NAME. The help text is suffixed with a description of secrthe environment variable default.

func (*CommandClause) Hidden

func (cmd *CommandClause) Hidden() *CommandClause

Hidden hides the command in help texts.

type Flag

type Flag struct {
	*kingpin.FlagClause
	// contains filtered or unexported fields
}

Flag represents a command-line flag.

func (*Flag) Envar

func (f *Flag) Envar(name string) *Flag

Envar overrides the environment variable name that configures the default value for a flag.

func (*Flag) Hidden

func (f *Flag) Hidden() *Flag

Hidden hides the flag in help texts.

func (*Flag) NoEnvar

func (f *Flag) NoEnvar() *Flag

NoEnvar forces environment variable defaults to be disabled for this flag.

type Logger

type Logger interface {
	// Debugf logs a message when debug mode is enabled.
	Debugf(format string, args ...interface{})
	// Warningf logs a message when debug mode is enabled.
	Warningf(format string, args ...interface{})
	// EnableDebug turns printing debug messages on.
	EnableDebug()
}

Logger can be used to log debug and warning messages.

func NewLogger

func NewLogger() Logger

NewLogger returns a logger with the given format, module and loglevel.

Directories

Path Synopsis
Package clip provides functionality to read from and write to the clipboard.
Package clip provides functionality to read from and write to the clipboard.
fakeclip
Package fakeclip provides fake implementations of the clip.Clipper interface to be used for testing.
Package fakeclip provides fake implementations of the clip.Clipper interface to be used for testing.
Package cloneproc provides functionality to spawn a detached clone of the current process.
Package cloneproc provides functionality to spawn a detached clone of the current process.
Package filemode provides a wrapper around os.FileMode so that it can be parsed from a CLI flag.
Package filemode provides a wrapper around os.FileMode so that it can be parsed from a CLI flag.
Package mlock allows for locking memory, providing implementations for different operating systems.
Package mlock allows for locking memory, providing implementations for different operating systems.
Package progress provides a printer that writes dots at a configured interval.
Package progress provides a printer that writes dots at a configured interval.
fakeprogress
Package fakeprogress provides an implementation of the progress.Printer interface to be used in tests.
Package fakeprogress provides an implementation of the progress.Printer interface to be used in tests.
ui
Package ui provides a simple way to interact with the user through the terminal, i.e.
Package ui provides a simple way to interact with the user through the terminal, i.e.

Jump to

Keyboard shortcuts

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