command

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvCLINoColor is an env var that toggles colored UI output.
	EnvCLINoColor = `NO_COLOR`
)

Variables

This section is empty.

Functions

func ArgumentAsString

func ArgumentAsString(arguments []Argument) string

func ArgumentsString added in v0.3.0

func ArgumentsString(arguments []Argument) string

func CommandErrorText

func CommandErrorText(cmd NamedCommand) string

CommandErrorText is used to easily render the same messaging across commads when an error is printed.

func CommandHelp

func CommandHelp(c Command) string

func Commands

func Commands(ctx context.Context, metaPtr *Meta, commandsFunc CommandFunc) map[string]cli.CommandFactory

Commands returns the mapping of CLI commands. The meta parameter lets you set meta options for all commands.

func ExampleString

func ExampleString(examples map[string]string) string

func FlagString

func FlagString(flags *flag.FlagSet) string

func MergeAutocompleteFlags

func MergeAutocompleteFlags(flags ...complete.Flags) complete.Flags

MergeAutocompleteFlags is used to join multiple flag completion sets.

func ParseArguments

func ParseArguments(args []string, arguments []Argument) (map[string]Argument, error)

func SetupEnv

func SetupEnv(args []string)

setupEnv parses args and may replace them and sets some env vars to known values based on format options

Types

type Argument

type Argument struct {
	Name        string
	Description string
	Optional    bool
	Type        ArgumentType
	Value       interface{}
	HasValue    bool
}

func (Argument) BoolValue

func (a Argument) BoolValue() bool

func (Argument) IntValue

func (a Argument) IntValue() int

func (Argument) ListValue

func (a Argument) ListValue() []string

func (Argument) StringValue

func (a Argument) StringValue() string

type ArgumentType

type ArgumentType uint

ArgumentType is an enum to define what arguments are present

const (
	ArgumentString ArgumentType = 0
	ArgumentInt    ArgumentType = 1 << iota
	ArgumentBool   ArgumentType = 2 << iota
	ArgumentList   ArgumentType = 3 << iota
)

type Command

type Command interface {
	Name() string
	FlagSet() *flag.FlagSet
	Arguments() []Argument
	Synopsis() string
	Examples() map[string]string
}

type CommandFunc

type CommandFunc func(ctx context.Context, meta Meta) map[string]cli.CommandFactory

type FlagSetFlags

type FlagSetFlags uint

FlagSetFlags is an enum to define what flags are present in the default FlagSet returned by Meta.FlagSet.

const (
	FlagSetNone    FlagSetFlags = 0
	FlagSetClient  FlagSetFlags = 1 << iota
	FlagSetDefault              = FlagSetClient
)

type GlobalFlagCommand added in v0.2.0

type GlobalFlagCommand interface {
	GlobalFlags(*flag.FlagSet)
}

type HumanWriter added in v0.6.0

type HumanWriter struct {
	// Out is the output destination.
	Out io.Writer

	// NoColor disables the colorized output.
	NoColor bool

	// TimeFormat specifies the format for timestamp in output.
	TimeFormat string

	// PartsOrder defines the order of parts in output.
	PartsOrder []string

	// PartsExclude defines parts to not display in output.
	PartsExclude []string

	FormatTimestamp     zerolog.Formatter
	FormatLevel         zerolog.Formatter
	FormatCaller        zerolog.Formatter
	FormatMessage       zerolog.Formatter
	FormatFieldName     zerolog.Formatter
	FormatFieldValue    zerolog.Formatter
	FormatErrFieldName  zerolog.Formatter
	FormatErrFieldValue zerolog.Formatter
}

HumanWriter parses the JSON input and writes it in an (optionally) colorized, human-friendly format to Out.

func NewHumanWriter added in v0.6.0

func NewHumanWriter(options ...func(w *HumanWriter)) HumanWriter

NewHumanWriter creates and initializes a new HumanWriter.

func (HumanWriter) Write added in v0.6.0

func (w HumanWriter) Write(p []byte) (n int, err error)

Write transforms the JSON input with formatters and appends to w.Out.

type Meta

type Meta struct {
	Ui cli.Ui

	Context context.Context
	// contains filtered or unexported fields
}

Meta contains the meta-options and functionality that nearly every command inherits.

func SetupRun

func SetupRun(ctx context.Context, appName string, version string, args []string) *Meta

func (*Meta) AutocompleteFlags

func (m *Meta) AutocompleteFlags(fs FlagSetFlags) complete.Flags

AutocompleteFlags returns a set of flag completions for the given flag set.

func (*Meta) Colorize

func (m *Meta) Colorize() *colorstring.Colorize

func (*Meta) FlagSet

func (m *Meta) FlagSet(n string, fs FlagSetFlags) *flag.FlagSet

FlagSet returns a FlagSet with the common flags that every command implements. The exact behavior of FlagSet can be configured using the flags as the second parameter, for example to disable server settings on the commands that don't talk to a server.

type NamedCommand

type NamedCommand interface {
	Name() string
}

NamedCommand is a interface to denote a commmand's name.

type VersionCommand

type VersionCommand struct {
	Meta
}

func (*VersionCommand) Arguments

func (c *VersionCommand) Arguments() []Argument

func (*VersionCommand) AutocompleteArgs

func (c *VersionCommand) AutocompleteArgs() complete.Predictor

func (*VersionCommand) AutocompleteFlags

func (c *VersionCommand) AutocompleteFlags() complete.Flags

func (*VersionCommand) Examples

func (c *VersionCommand) Examples() map[string]string

func (*VersionCommand) FlagSet

func (c *VersionCommand) FlagSet() *flag.FlagSet

func (*VersionCommand) Help

func (c *VersionCommand) Help() string

func (*VersionCommand) Name

func (c *VersionCommand) Name() string

func (*VersionCommand) ParsedArguments

func (c *VersionCommand) ParsedArguments(args []string) (map[string]Argument, error)

func (*VersionCommand) Run

func (c *VersionCommand) Run(args []string) int

func (*VersionCommand) Synopsis

func (c *VersionCommand) Synopsis() string

type ZerologUi added in v0.6.0

type ZerologUi struct {
	StderrLogger      zerolog.Logger
	StdoutLogger      zerolog.Logger
	OriginalFields    map[string]interface{}
	Ui                cli.Ui
	OutputIndentField bool
}

func HumanZerologUiWithFields added in v0.6.0

func HumanZerologUiWithFields(ui cli.Ui, fields map[string]interface{}) *ZerologUi

func ZerologUiWithFields added in v0.6.0

func ZerologUiWithFields(ui cli.Ui, fields map[string]interface{}) *ZerologUi

func (*ZerologUi) Ask added in v0.6.0

func (u *ZerologUi) Ask(query string) (string, error)

func (*ZerologUi) AskSecret added in v0.6.0

func (u *ZerologUi) AskSecret(query string) (string, error)

func (*ZerologUi) Error added in v0.6.0

func (u *ZerologUi) Error(message string)

func (*ZerologUi) Field added in v0.6.0

func (u *ZerologUi) Field(field string, value interface{}) *ZerologUi

func (*ZerologUi) Fields added in v0.6.0

func (u *ZerologUi) Fields(newFields map[string]interface{}) *ZerologUi

func (*ZerologUi) Info added in v0.6.0

func (u *ZerologUi) Info(message string)

func (*ZerologUi) LogHeader1 added in v0.6.0

func (u *ZerologUi) LogHeader1(message string)

func (*ZerologUi) LogHeader2 added in v0.6.0

func (u *ZerologUi) LogHeader2(message string)

func (*ZerologUi) Output added in v0.6.0

func (u *ZerologUi) Output(message string)

func (*ZerologUi) Warn added in v0.6.0

func (u *ZerologUi) Warn(message string)

Jump to

Keyboard shortcuts

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