commandline

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: Apache-2.0 Imports: 5 Imported by: 16

README

commandline - cobra integration package

Types to allow to write CLI tools using cobra in easy way.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRootCommand = errors.New("no root command provided")

ErrNoRootCommand is returned when no root command is provided.

Functions

This section is empty.

Types

type App

type App struct {
	CobraProvider
	ErrorHandler
	Exit func(code int)
	// contains filtered or unexported fields
}

App represents a command line application.

func New

func New(cp CobraProvider) *App

New creates a new App from CobraProvider.

func (*App) Execute

func (a *App) Execute(options ...Option) error

Execute will execute the application with the provided options and return error if any.

func (*App) ExecuteOrDie

func (a *App) ExecuteOrDie(options ...Option)

ExecuteOrDie will execute the application or perform os.Exit in case of error.

type CobraProvider

type CobraProvider interface {
	Command() *cobra.Command
}

CobraProvider is used to provide a Cobra command.

type ErrorHandler added in v1.2.0

type ErrorHandler func(err error, cmd *cobra.Command) bool

ErrorHandler is a function that will be used to handle the errors. If true is returned, the default error handling will not be used. The Cobra's command passed to the error handler is the command that thrown the error.

type Option

type Option func(*App)

Option is used to configure an App.

func WithArgs

func WithArgs(args ...string) Option

WithArgs creates an option which sets args. Deprecated: use WithCommand instead.

func WithCommand added in v1.1.0

func WithCommand(fn func(cmd *cobra.Command)) Option

WithCommand will allow one to change the cobra.Command.

func WithErrorHandler added in v1.2.0

func WithErrorHandler(fn ErrorHandler) Option

WithErrorHandler will allow changing the default error handler.

func WithExit

func WithExit(fn func(code int)) Option

WithExit creates an option which sets the exit function.

func WithInput

func WithInput(in io.Reader) Option

WithInput creates an option witch sets os.Stdin. Deprecated: use WithCommand instead.

func WithOutput

func WithOutput(out io.Writer) Option

WithOutput creates an option witch sets os.Stdout and os.Stderr. Deprecated: use WithCommand instead.

Directories

Path Synopsis
test
cmd

Jump to

Keyboard shortcuts

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