cmd

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCLIApp

func NewCLIApp(options ...CLIAppOption) *cli.App

func NewCommand

func NewCommand(command *cli.Command, options ...CommandOption) *cli.Command

Types

type AfterHandler

type AfterHandler[P any] interface {
	After(ctx *HandlerContext[P], params *P, w io.Writer) error
}

type Application

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

func NewApplication

func NewApplication(env *Environment, cli *cli.App) *Application

func (*Application) Run

func (app *Application) Run(ctx context.Context)

type BeforeHandler

type BeforeHandler[P any] interface {
	Before(ctx *HandlerContext[P], params *P, w io.Writer) error
}

type CLIAppOption

type CLIAppOption func(*cli.App)

func UseCommands

func UseCommands(commands ...*cli.Command) CLIAppOption

func UseDefaultCommand

func UseDefaultCommand(command string) CLIAppOption

func UseEnvironment

func UseEnvironment(env *Environment) CLIAppOption

type Clock

type Clock interface {
	Now() time.Time
}

type CommandHandler

type CommandHandler[P any] interface {
	Action(ctx *HandlerContext[P], params *P, w io.Writer) error
}

type CommandOption

type CommandOption func(*cli.Command)

func UseHandler

func UseHandler[P any](handler CommandHandler[P], opts ...HandlerOption[P]) CommandOption

type Environment

type Environment struct {
	Reader     io.Reader
	Writer     io.Writer
	ErrWriter  io.Writer
	FileSystem afero.Fs
	Args       []string
	Exit       func(error)
	Clock      Clock
}

type FakeClock

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

func (*FakeClock) Now

func (st *FakeClock) Now() time.Time

type Handler

type Handler[P any] struct {
	CommandHandler[P]
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler[P any](commandHandler CommandHandler[P], opts ...HandlerOption[P]) *Handler[P]

func (*Handler[P]) Action

func (h *Handler[P]) Action(cCtx *cli.Context) error

func (*Handler[P]) After

func (h *Handler[P]) After(cCtx *cli.Context) error

func (*Handler[P]) Before

func (h *Handler[P]) Before(cCtx *cli.Context) error

func (*Handler[P]) OnUsageError

func (h *Handler[P]) OnUsageError(cCtx *cli.Context, err error, isSubcommand bool) error

type HandlerContext

type HandlerContext[P any] struct {
	Reader io.Reader
	Log    *zerolog.Logger
	// contains filtered or unexported fields
}

func (*HandlerContext[P]) Deadline

func (ctx *HandlerContext[P]) Deadline() (deadline time.Time, ok bool)

func (*HandlerContext[P]) Done

func (ctx *HandlerContext[P]) Done() <-chan struct{}

func (*HandlerContext[P]) Err

func (ctx *HandlerContext[P]) Err() error

func (*HandlerContext[P]) Value

func (ctx *HandlerContext[P]) Value(key any) any

type HandlerOption

type HandlerOption[P any] func(*Handler[P]) CommandOption

func UseArguments

func UseArguments[P any](mapping func(*P, []string)) HandlerOption[P]

func UseBoolFlag

func UseBoolFlag[P any](flag *cli.BoolFlag, mapping func(*P, bool)) HandlerOption[P]

func UseStringFlag

func UseStringFlag[P any](flag *cli.StringFlag, mapping func(*P, string)) HandlerOption[P]

func UseStringSliceFlag

func UseStringSliceFlag[P any](flag *cli.StringSliceFlag, mapping func(*P, []string)) HandlerOption[P]

type OnUsageErrorHandler

type OnUsageErrorHandler[P any] interface {
	OnUsageError(ctx *HandlerContext[P], err error, isSubcommand bool, params *P, w io.Writer) error
}

type SystemClock

type SystemClock struct{}

func (*SystemClock) Now

func (st *SystemClock) Now() time.Time

Jump to

Keyboard shortcuts

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