app

package
v0.0.0-...-f5bcdd4 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WordSepNormalizeFunc

func WordSepNormalizeFunc(_ *pflag.FlagSet, name string) pflag.NormalizedName

WordSepNormalizeFunc changes all flags that contain "_" separators.

Types

type App

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

App is the main structure of a cli application.

func NewApp

func NewApp(name, basename string, opts ...Option) *App

NewApp creates a new application instance based on the given application name, binary name, and other options.

func (*App) AddCommand

func (app *App) AddCommand(cmd *Command)

AddCommand adds sub command to the application.

func (*App) AddCommands

func (app *App) AddCommands(cmds ...*Command)

AddCommands adds multiple sub commands to the application.

func (*App) Command

func (app *App) Command() *cobra.Command

Command returns cobra command instance inside the application.

func (*App) Run

func (app *App) Run()

Run is used to launch the application.

type CliOptions

type CliOptions interface {
	Flags() (fss NamedFlagSets)
	Validate() []error
}

type Command

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

Command is a sub command structure of a cli application.

func NewCommand

func NewCommand(usage string, desc string, opts ...CommandOption) *Command

NewCommand creates a new sub command instance based on the given command name and other options.

func (*Command) AddCommand

func (cmd *Command) AddCommand(c *Command)

AddCommand adds sub command to the current command.

func (*Command) AddCommands

func (cmd *Command) AddCommands(cmds ...*Command)

AddCommands adds multiple sub commands to the current command.

type CommandOption

type CommandOption func(*Command)

CommandOption defines optional parameters for initializing the command structure.

func WithCommandOptions

func WithCommandOptions(opt CliOptions) CommandOption

WithCommandOptions to open the application's function to read from the command line.

func WithCommandRunFunc

func WithCommandRunFunc(run RunCommandFunc) CommandOption

WithCommandRunFunc is used to set the application's command startup callback function option.

type CompletableOptions

type CompletableOptions interface {
	Complete() error
}

CompletableOptions abstracts options which can be completed.

type NamedFlagSets

type NamedFlagSets struct {
	Order    []string
	FlagSets map[string]*pflag.FlagSet
}

NamedFlagSets stores named flag sets in the order of calling FlagSet.

func (*NamedFlagSets) FlagSet

func (nfs *NamedFlagSets) FlagSet(name string) *pflag.FlagSet

FlagSet returns the flag set with the given name and adds it to the ordered name list if it is not in there yet.

type Option

type Option func(app *App)

Option defines optional parameters for initializing the application structure.

func WithDefaultValidArgs

func WithDefaultValidArgs() Option

WithDefaultValidArgs set default validation function to valid non-flag arguments.

func WithDescription

func WithDescription(desc string) Option

WithDescription is used to set the description of the application.

func WithNoConfig

func WithNoConfig() Option

WithNoConfig set the application does not provide configs flag.

func WithNoVersion

func WithNoVersion() Option

WithNoVersion set the application does not provide version flag.

func WithOptions

func WithOptions(opt CliOptions) Option

WithOptions to open the application's function to read from the command line or read parameters from the configuration file.

func WithRunFunc

func WithRunFunc(run RunFunc) Option

WithRunFunc is used to set the application startup callback function option.

func WithSilence

func WithSilence() Option

WithSilence sets the application to silent mode, in which the program startup information, configuration information, and version information are not printed in the console.

func WithValidArgs

func WithValidArgs(args cobra.PositionalArgs) Option

WithValidArgs set the validation function to valid non-flag arguments.

type PrintableOptions

type PrintableOptions interface {
	String() string
}

PrintableOptions abstracts options which can be printed.

type RunCommandFunc

type RunCommandFunc func(args []string) error

RunCommandFunc defines the application's command startup callback function.

type RunFunc

type RunFunc func(basename string) error

RunFunc defines the application's startup callback function.

Jump to

Keyboard shortcuts

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