cli

package
v1.4.10 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NilAction = func(v Value) error {
		return nil
	}
	HelpAction = func(v Value) error {
		args := v.Args()
		if args.Present() {
			return cli.ShowCommandHelp(v.Kernel(), args.First())
		}
		_ = cli.ShowAppHelp(v.Kernel())
		return nil
	}
)

Functions

func WithFlagBool

func WithFlagBool(name string, value bool, usage string)

func WithFlagDuration

func WithFlagDuration(name string, value time.Duration, usage string)

func WithFlagFloat64

func WithFlagFloat64(name string, value float64, usage string)

func WithFlagInt

func WithFlagInt(name string, value int, usage string)

func WithFlagInt64

func WithFlagInt64(name string, value int64, usage string)

func WithFlagIntSlice

func WithFlagIntSlice(name string, value []int, usage string)

func WithFlagString

func WithFlagString(name string, value string, usage string)

func WithFlagStringSlice

func WithFlagStringSlice(name string, value []string, usage string)

WithFlagStringSlice example: main.ext -names Bob -names Tom -names Lisa

func WithFlagUint

func WithFlagUint(name string, value uint, usage string)

func WithFlagUint64

func WithFlagUint64(name string, value uint64, usage string)

Types

type Action

type Action func(v Value) error

type App

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

func NewApp

func NewApp(options ...Option) *App

func NewAppWithConfig

func NewAppWithConfig(config Config) *App

func (*App) Action

func (app *App) Action() Action

func (*App) AddCommand

func (app *App) AddCommand(command *command.Command) *App

func (*App) Commands

func (app *App) Commands() []*command.Command

func (*App) Flags

func (app *App) Flags() []cli.Flag

func (*App) Kernel

func (app *App) Kernel() *cli.App

func (*App) OnAfterAction

func (app *App) OnAfterAction(action Action) *App

func (*App) OnBeforeAction

func (app *App) OnBeforeAction(action Action) *App

func (*App) Run

func (app *App) Run() error

func (*App) WithAction

func (app *App) WithAction(action Action) *App

func (*App) WithCommandNotFoundHandler

func (app *App) WithCommandNotFoundHandler(handler CommandNotFoundHandler) *App

WithCommandNotFoundHandler Execute this function if the proper command cannot be found

func (*App) WithExitErrHandler

func (app *App) WithExitErrHandler(handler ExitErrHandlerFunc) *App

WithExitErrHandler Execute this function to handle ExitErrors.

func (*App) WithFlagBool

func (app *App) WithFlagBool(name string, value bool, usage string, required bool, hidden ...bool) *App

func (*App) WithFlagDuration

func (app *App) WithFlagDuration(name string, value time.Duration, usage string, required bool, hidden ...bool) *App

func (*App) WithFlagFloat64

func (app *App) WithFlagFloat64(name string, value float64, usage string, required bool, hidden ...bool) *App

func (*App) WithFlagInt

func (app *App) WithFlagInt(name string, value int, usage string, required bool, hidden ...bool) *App

func (*App) WithFlagInt64

func (app *App) WithFlagInt64(name string, value int64, usage string, required bool, hidden ...bool) *App

func (*App) WithFlagIntSlice

func (app *App) WithFlagIntSlice(name string, value []int, usage string, required bool, hidden ...bool) *App

WithFlagIntSlice example: main.ext -names Bob -names Tom -names Lisa

func (*App) WithFlagString

func (app *App) WithFlagString(name string, value string, usage string, required bool, hidden ...bool) *App

func (*App) WithFlagStringSlice

func (app *App) WithFlagStringSlice(name string, value []string, usage string, required bool, hidden ...bool) *App

func (*App) WithFlagUint

func (app *App) WithFlagUint(name string, value uint, usage string, required bool, hidden ...bool) *App

func (*App) WithFlagUint64

func (app *App) WithFlagUint64(name string, value uint64, usage string, required bool, hidden ...bool) *App

func (*App) WithUsageErrorHandler

func (app *App) WithUsageErrorHandler(handler UsageErrorHandler) *App

WithUsageErrorHandler Execute this function if a usage error occurs

type Author

type Author struct {
	Name  string // The Author name
	Email string // The Author email
}

type CommandNotFoundHandler

type CommandNotFoundHandler = func(v Value, s string)

type Config

type Config struct {
	// The name of the program. Defaults to path.Base(os.Args[0])
	Name string
	// Full name of command for help, defaults to Name
	HelpName string
	// Description of the program.
	Usage string
	// Text to override the USAGE section of help
	UsageText string
	// Description of the program argument format.
	ArgsUsage string
	// Version of the program
	Version string
	// Description of the program
	Description string
	// Boolean to enable bash completion commands
	EnableBashCompletion bool
	// Boolean to hide built-in help command
	HideHelp bool
	// Boolean to hide built-in version flag and the VERSION section of help
	HideVersion bool
	// Compilation date
	Compiled time.Time
	// List of all authors who contributed
	Authors []Author
	// Copyright of the binary if any
	Copyright string
	// Name of Author (Note: Use App.Authors, this is deprecated)
	Author string
	// Email of Author (Note: Use App.Authors, this is deprecated)
	Email string
	// Writer writer to write output to
	Writer io.Writer
	// ErrWriter writes error output
	ErrWriter io.Writer
	// CustomAppHelpTemplate the text template for app help topic.
	// cli.go uses text/template to render templates. You can
	// render custom help text by setting this variable.
	CustomAppHelpTemplate string
	// Boolean to enable short-option handling so user can combine several
	// single-character bool arguements into one
	// i.e. foobar -o -v -> foobar -ov
	UseShortOptionHandling bool
}

type ExitErrHandlerFunc

type ExitErrHandlerFunc = func(v Value, err error)

type Option

type Option func(config *Config)

func WithArgsUsage

func WithArgsUsage(argsUsage string) Option

func WithAuthor

func WithAuthor(author string) Option

func WithAuthors

func WithAuthors(authors []Author) Option

func WithCompiled

func WithCompiled(compiled time.Time) Option

func WithCopyright

func WithCopyright(copyright string) Option

func WithCustomAppHelpTemplate

func WithCustomAppHelpTemplate(customAppHelpTemplate string) Option

func WithDescription

func WithDescription(description string) Option

func WithEmail

func WithEmail(email string) Option

func WithEnableBashCompletion

func WithEnableBashCompletion(enableBashCompletion bool) Option

func WithErrWriter

func WithErrWriter(errWriter io.Writer) Option

func WithHelpName

func WithHelpName(helpName string) Option

func WithHideHelp

func WithHideHelp(hideHelp bool) Option

func WithHideVersion

func WithHideVersion(hideVersion bool) Option

func WithName

func WithName(name string) Option

func WithUsage

func WithUsage(usage string) Option

func WithUsageText

func WithUsageText(usageText string) Option

func WithUseShortOptionHandling

func WithUseShortOptionHandling(useShortOptionHandling bool) Option

func WithVersion

func WithVersion(version string) Option

func WithWriter

func WithWriter(writer io.Writer) Option

type UsageErrorHandler

type UsageErrorHandler = func(v Value, err error, isSubcommand bool) error

type Value

type Value = flag.Value

func Run

func Run() (value Value, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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