commandline

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 5 Imported by: 17

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
	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 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 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 command

Jump to

Keyboard shortcuts

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