appcmd

package
v0.1.30 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NoArgs matches cobra.NoArgs.
	NoArgs = newPositionalArgs(cobra.NoArgs)
	// OnlyValidArgs matches cobra.OnlyValidArgs.
	OnlyValidArgs = newPositionalArgs(cobra.OnlyValidArgs)
	// ArbitraryArgs matches cobra.ArbitraryArgs.
	ArbitraryArgs = newPositionalArgs(cobra.ArbitraryArgs)
)
View Source
var (
	ShellCompDirectiveError         = newShellCompDirective(cobra.ShellCompDirectiveError)
	ShellCompDirectiveNoSpace       = newShellCompDirective(cobra.ShellCompDirectiveNoSpace)
	ShellCompDirectiveNoFileComp    = newShellCompDirective(cobra.ShellCompDirectiveNoFileComp)
	ShellCompDirectiveFilterFileExt = newShellCompDirective(cobra.ShellCompDirectiveFilterFileExt)
	ShellCompDirectiveFilterDirs    = newShellCompDirective(cobra.ShellCompDirectiveFilterDirs)
	ShellCompDirectiveKeepOrder     = newShellCompDirective(cobra.ShellCompDirectiveKeepOrder)
)

Functions

func BindMultiple

func BindMultiple(bindFuncs ...func(*pflag.FlagSet)) func(*pflag.FlagSet)

BindMultiple is a convenience function for binding multiple flag functions.

func Main

func Main(ctx context.Context, command *Command)

Main runs the application using the OS container and calling os.Exit on the return value of Run.

func MarkFlagRequired

func MarkFlagRequired(flagSet *pflag.FlagSet, flagName string) error

MarkFlagRequired matches cobra.MarkFlagRequired so that importers of appcmd do not need to reference cobra (and shouldn't).

func NewInvalidArgumentError

func NewInvalidArgumentError(message string) error

NewInvalidArgumentError creates a new invalidArgumentError, indicating that the error was caused by argument validation. This causes us to print the usage help text for the command that it is returned from.

func NewInvalidArgumentErrorf

func NewInvalidArgumentErrorf(format string, args ...any) error

NewInvalidArgumentErrorf creates a new InvalidArgumentError, indicating that the error was caused by argument validation. This causes us to print the usage help text for the command that it is returned from.

func Run

func Run(ctx context.Context, container app.Container, command *Command) error

Run runs the application using the container.

Types

type Command

type Command struct {
	// Use is the one-line usage message.
	// Required.
	Use string
	// Aliases are aliases that can be used instead of the first word in Use.
	Aliases []string
	// Short is the short message shown in the 'help' output.
	// Required if Long is set.
	Short string
	// Long is the long message shown in the 'help <this-command>' output.
	// The Short field will be prepended to the Long field with two newlines.
	// Must be unset if short is unset.
	Long string

	// Example is examples of how to use the command.
	Example string

	// Args are the expected arguments.
	Args PositionalArgs

	// ValidArgs is list of all valid non-flag arguments that are accepted in shell completions
	ValidArgs []string
	// ValidArgsFunction is an optional function that provides valid non-flag arguments for shell completion.
	// It is a dynamic version of using ValidArgs.
	// Only one of ValidArgs and ValidArgsFunction can be used for a command.
	ValidArgsFunction func(args []string, toComplete string) ([]string, ShellCompDirective)

	// Deprecated says to print this deprecation string.
	Deprecated string
	// Hidden says to hide this command.
	Hidden bool
	// BindFlags allows binding of flags on build.
	BindFlags func(*pflag.FlagSet)
	// BindPersistentFlags allows binding of flags on build.
	BindPersistentFlags func(*pflag.FlagSet)
	// NormalizeFlag allows for normalization of flag names.
	NormalizeFlag func(*pflag.FlagSet, string) string
	// NormalizePersistentFlag allows for normalization of flag names.
	NormalizePersistentFlag func(*pflag.FlagSet, string) string
	// Run is the command to run.
	// Required if there are no sub-commands.
	// Must be unset if there are sub-commands.
	Run func(context.Context, app.Container) error
	// SubCommands are the sub-commands. Optional.
	// Must be unset if there is a run function.
	SubCommands []*Command
	// Version the version of the command.
	//
	// If this is specified, a flag --version will be added to the command
	// that precedes all other functionality, and which prints the version
	// to stdout.
	Version string
}

Command is a command.

type PositionalArgs

type PositionalArgs interface {
	// contains filtered or unexported methods
}

PositionalArgs matches cobra.PositionalArgs so that importers of appcmd do not need to reference cobra (and shouldn't).

func ExactArgs

func ExactArgs(n int) PositionalArgs

ExactArgs matches cobra.ExactArgs.

func MatchAll added in v0.1.27

func MatchAll(args ...PositionalArgs) PositionalArgs

MatchAll matches cobra.MatchAll.

func MaximumNArgs

func MaximumNArgs(n int) PositionalArgs

MaximumNArgs matches cobra.MaximumNArgs.

func MinimumNArgs

func MinimumNArgs(n int) PositionalArgs

MinimumNArgs matches cobra.MinimumNArgs.

func RangeArgs

func RangeArgs(min int, max int) PositionalArgs

RangeArgs matches cobra.RangeArgs.

type ShellCompDirective added in v0.1.27

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

Jump to

Keyboard shortcuts

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