snake

package module
v0.12.13 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: Apache-2.0 Imports: 12 Imported by: 23

README

snake

Documentation

Index

Constants

View Source
const RootCommandName = "______root_____________"

Variables

View Source
var (
	ErrMissingBinding   = errors.New("snake.ErrMissingBinding")
	ErrMissingRun       = errors.New("snake.ErrMissingRun")
	ErrInvalidRun       = errors.New("snake.ErrInvalidRun")
	ErrInvalidArguments = errors.New("snake.ErrInvalidArguments")
	ErrInvalidResolver  = errors.New("snake.ErrInvalidResolver")
)
View Source
var Defaults = []string{"context.Context", "*cobra.Command"}
View Source
var (
	ErrInvalidMethodSignature = errors.New("invalid method signatured")
)
View Source
var (
	ErrMissingResolver = errors.New("missing resolver")
)

Functions

func Apply added in v0.12.0

func Apply(ctx context.Context, r *cobra.Command) error

func ApplyCtx added in v0.12.3

func ApplyCtx(ctx context.Context, me *Ctx, root *cobra.Command) error

func Assemble added in v0.10.4

func Assemble(ctx context.Context) *cobra.Command

func Bind

func Bind(ctx context.Context, key any, value any) context.Context

func BindG added in v0.11.3

func BindG[T any](ctx context.Context, value T) context.Context

func Build added in v0.12.0

func Build(ctx context.Context) (*cobra.Command, error)

func BuildCtx added in v0.12.3

func BuildCtx(ctx context.Context, me *Ctx) (*cobra.Command, error)

func ClearActiveCommand added in v0.10.1

func ClearActiveCommand(ctx context.Context) context.Context

func DecorateTemplate added in v0.10.4

func DecorateTemplate(ctx context.Context, root *cobra.Command, cfg *DecorateOptions) (string, error)

Init patches Cobra's usage template with configuration provided.

func FormatCaller added in v0.8.0

func FormatCaller(path string, number int) string

func FormatError added in v0.8.0

func FormatError(cmd *cobra.Command, err error) string

func GetActiveCommand added in v0.10.1

func GetActiveCommand(ctx context.Context) string

func GetAllNamedCommands added in v0.10.4

func GetAllNamedCommands(ctx context.Context) namedCommandMap

func GetAlreadyBound added in v0.11.3

func GetAlreadyBound[I any](ctx context.Context) (I, bool)

func HandleErrorByPrintingToConsole added in v0.8.1

func HandleErrorByPrintingToConsole(cmd *cobra.Command, err error) error

func IsHandledByPrintingToConsole added in v0.8.1

func IsHandledByPrintingToConsole(err error) bool

func MustNewCommand

func MustNewCommand(ctx context.Context, name string, snk Snakeable) context.Context

func NewArgument added in v0.12.0

func NewArgument[I any](method Flagged)

func NewCmd added in v0.12.0

func NewCmd[I Cobrad](cmd I)

func NewCommand

func NewCommand(ctx context.Context, name string, snk Snakeable) (context.Context, error)

func NewRootCommand

func NewRootCommand(ctx context.Context, snk Snakeable) (context.Context, error)

func NewWrappedEnum added in v0.12.0

func NewWrappedEnum[I ~string](values ...I) *wrappedEnum[I]

func RegisterBindingResolver added in v0.9.1

func RegisterBindingResolver[I any](ctx context.Context, res typedResolver[I], f ...flagbinding) context.Context

func ResolveBindingsFromProvider added in v0.9.0

func ResolveBindingsFromProvider(ctx context.Context, rf reflect.Value) (context.Context, error)

func SetActiveCommand added in v0.10.1

func SetActiveCommand(ctx context.Context, str string) context.Context

func SetNamedCommand added in v0.10.1

func SetNamedCommand(ctx context.Context, name string, cmd *NamedCommand) context.Context

func SetRootCommand added in v0.10.0

func SetRootCommand(ctx context.Context, cmd *NamedCommand) context.Context

func WithActiveCommand added in v0.10.1

func WithActiveCommand(ctx context.Context, x func(*cobra.Command) error) error

func WithNamedCommand added in v0.10.1

func WithNamedCommand(ctx context.Context, name string, x func(*cobra.Command) error) error

func WithRootCommand added in v0.10.1

func WithRootCommand(ctx context.Context, x func(*cobra.Command) error) error

Types

type Cobrad added in v0.12.1

type Cobrad interface {
	Cobra() *cobra.Command
}

type Ctx added in v0.12.0

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

func NewCtx added in v0.12.5

func NewCtx() *Ctx

func (*Ctx) FlagsFor added in v0.12.0

func (me *Ctx) FlagsFor(str Method) (*pflag.FlagSet, error)

func (*Ctx) FlagsForString added in v0.12.0

func (me *Ctx) FlagsForString(str string) (*pflag.FlagSet, error)

func (*Ctx) Run added in v0.12.0

func (me *Ctx) Run(str Method) error

func (*Ctx) RunString added in v0.12.0

func (me *Ctx) RunString(str string) error

type DecorateOptions added in v0.4.0

type DecorateOptions struct {
	Headings        *color.Color
	Commands        *color.Color
	CmdShortDescr   *color.Color
	ExecName        *color.Color
	Flags           *color.Color
	FlagsDataType   *color.Color
	FlagsDescr      *color.Color
	Aliases         *color.Color
	Example         *color.Color
	NoExtraNewlines bool
	NoBottomNewline bool
}

type ErrHandledByPrintingToConsole added in v0.8.1

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

func (*ErrHandledByPrintingToConsole) Error added in v0.8.1

func (*ErrHandledByPrintingToConsole) Unwrap added in v0.8.1

type FMap added in v0.12.0

type FMap[G any] func(string) G

type Flagged added in v0.12.0

type Flagged interface {
	Flags(*pflag.FlagSet)
}

func NewArgInlineFunc added in v0.12.3

func NewArgInlineFunc[I any](flagFunc func(*pflag.FlagSet), runFunc func() (I, error)) Flagged

type HasRunArgs added in v0.12.0

type HasRunArgs interface{ RunArgs() []reflect.Type }

type IsRunnable added in v0.12.0

type IsRunnable interface {
	HasRunArgs
	Run() reflect.Value
	HandleResponse([]reflect.Value) (*reflect.Value, error)
}

type Method added in v0.12.0

type Method interface {
	Flags(*pflag.FlagSet)
	Run() reflect.Value
	RunArgs() []reflect.Type
	ValidateResponse() error
	HandleResponse([]reflect.Value) (*reflect.Value, error)
	Name() string
	Command() Cobrad
}

func NewArgContext added in v0.12.0

func NewArgContext[I any](con *Ctx, m Flagged) Method

func NewCmdContext added in v0.12.0

func NewCmdContext[I Cobrad](con *Ctx, cbra I) Method

type NamedCommand added in v0.11.0

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

func GetActiveNamedCommand added in v0.10.1

func GetActiveNamedCommand(ctx context.Context) *NamedCommand

func GetNamedCommand added in v0.10.1

func GetNamedCommand(ctx context.Context, name string) *NamedCommand

func GetRootCommand added in v0.10.0

func GetRootCommand(ctx context.Context) *NamedCommand

type Snakeable

type Snakeable interface {
	PreRun(ctx context.Context, args []string) (context.Context, error)
	Register(context.Context) (*cobra.Command, error) // need a way for us to be able to have the full command like we do when the kubectl command is importable
}

Directories

Path Synopsis
example
wails module

Jump to

Keyboard shortcuts

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