cling

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 11 Imported by: 0

README

cling

A Simple and Clear CLI library.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hydrate

func Hydrate[T any](ctx context.Context, argArguments []string, destination *T) error

func WithCommand added in v0.2.0

func WithCommand(ctx context.Context, command *Command) context.Context

Types

type CLI

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

func NewCLI

func NewCLI(name string, version string) *CLI

func (*CLI) AddCommand

func (cli *CLI) AddCommand(command *Command) *CLI

Assuming AddCommand is a method of a CLI struct, make it a generic method

func (*CLI) Run

func (c *CLI) Run(ctx context.Context, args []string) error

func (*CLI) WithDescription

func (cli *CLI) WithDescription(description string) *CLI

func (*CLI) WithLongDescription

func (cli *CLI) WithLongDescription(longDescription string) *CLI

type ClingContextKey added in v0.2.0

type ClingContextKey string
const (
	ContextKeyCommand ClingContextKey = "command"
)

type CmdArg added in v0.2.0

type CmdArg interface {
	CmdInput
	WithLongDescription(string) CmdArg
	LongDescription() string
}

type CmdFlag added in v0.2.0

type CmdFlag interface {
	CmdInput
}

type CmdInput added in v0.2.0

type CmdInput interface {
	Name() string
	Description() string
	Required() CmdInput
	AsFlag() CmdFlag
	AsArgument() CmdArg
	// contains filtered or unexported methods
}

type CmdInputWithDefaultAndValidator added in v0.2.0

type CmdInputWithDefaultAndValidator[S any] interface {
	CmdInput
	WithDefault(value S) CmdInputWithDefaultAndValidator[S]
	WithValidators(validators ...Validator[S]) CmdInputWithDefaultAndValidator[S]
}

func NewIntCmdInput added in v0.2.0

func NewIntCmdInput(name string) CmdInputWithDefaultAndValidator[int]

func NewStringCmdInput added in v0.2.0

func NewStringCmdInput(name string) CmdInputWithDefaultAndValidator[string]

type Command

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

func CommandFromContext added in v0.2.0

func CommandFromContext(ctx context.Context) (*Command, bool)

func NewCommand

func NewCommand(name string, action CommandHandler) *Command

func (*Command) WithArgument added in v0.2.0

func (command *Command) WithArgument(arg CmdArg) *Command

func (*Command) WithChildCommand added in v0.2.0

func (command *Command) WithChildCommand(cmd *Command) *Command

func (*Command) WithCommandShortcut

func (command *Command) WithCommandShortcut(shortcut string) *Command

func (*Command) WithDescription

func (c *Command) WithDescription(description string) *Command

func (*Command) WithFlag added in v0.2.0

func (command *Command) WithFlag(flag CmdFlag) *Command

func (*Command) WithLongDescription

func (c *Command) WithLongDescription(longDescription string) *Command

type CommandHandler

type CommandHandler func(ctx context.Context, args []string) error

type ConfigTargets added in v0.2.0

type ConfigTargets map[string]configTarget

type EnumValidator added in v0.2.0

type EnumValidator[T comparable] struct {
	// contains filtered or unexported fields
}

func NewEnumValidator added in v0.2.0

func NewEnumValidator[T comparable](allowedValues ...T) *EnumValidator[T]

func (*EnumValidator[T]) Validate added in v0.2.0

func (v *EnumValidator[T]) Validate(value T) error

type IntCmdInput added in v0.2.0

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

func (*IntCmdInput) AsArgument added in v0.2.0

func (f *IntCmdInput) AsArgument() CmdArg

func (*IntCmdInput) AsFlag added in v0.2.0

func (f *IntCmdInput) AsFlag() CmdFlag

func (*IntCmdInput) Description added in v0.2.0

func (f *IntCmdInput) Description() string

func (*IntCmdInput) LongDescription added in v0.2.0

func (f *IntCmdInput) LongDescription() string

func (*IntCmdInput) Name added in v0.2.0

func (f *IntCmdInput) Name() string

func (*IntCmdInput) Required added in v0.2.0

func (f *IntCmdInput) Required() CmdInput

func (*IntCmdInput) WithDefault added in v0.2.0

func (f *IntCmdInput) WithDefault(value int) CmdInputWithDefaultAndValidator[int]

func (*IntCmdInput) WithDescription added in v0.2.0

func (f *IntCmdInput) WithDescription(value string) CmdInput

func (*IntCmdInput) WithLongDescription added in v0.2.0

func (f *IntCmdInput) WithLongDescription(value string) CmdArg

func (*IntCmdInput) WithValidators added in v0.2.0

func (f *IntCmdInput) WithValidators(validators ...Validator[int]) CmdInputWithDefaultAndValidator[int]

type IntRangeValidator added in v0.2.0

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

func NewIntRangeValidator added in v0.2.0

func NewIntRangeValidator(min, max int) *IntRangeValidator

func (*IntRangeValidator) Validate added in v0.2.0

func (v *IntRangeValidator) Validate(value int) error

type RuntimeArg added in v0.2.0

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

type RuntimeFlag added in v0.2.0

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

type StringCmdInput added in v0.2.0

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

func (*StringCmdInput) AsArgument added in v0.2.0

func (f *StringCmdInput) AsArgument() CmdArg

func (*StringCmdInput) AsFlag added in v0.2.0

func (f *StringCmdInput) AsFlag() CmdFlag

func (*StringCmdInput) Description added in v0.2.0

func (f *StringCmdInput) Description() string

func (*StringCmdInput) LongDescription added in v0.2.0

func (f *StringCmdInput) LongDescription() string

func (*StringCmdInput) Name added in v0.2.0

func (f *StringCmdInput) Name() string

func (*StringCmdInput) Required added in v0.2.0

func (f *StringCmdInput) Required() CmdInput

func (*StringCmdInput) WithDefault added in v0.2.0

func (*StringCmdInput) WithDescription added in v0.2.0

func (f *StringCmdInput) WithDescription(value string) CmdInput

func (*StringCmdInput) WithLongDescription added in v0.2.0

func (f *StringCmdInput) WithLongDescription(longDescription string) CmdArg

func (*StringCmdInput) WithValidators added in v0.2.0

func (f *StringCmdInput) WithValidators(validators ...Validator[string]) CmdInputWithDefaultAndValidator[string]

type StringLengthValidator added in v0.2.0

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

func NewStringLengthValidator added in v0.2.0

func NewStringLengthValidator(min, max int) *StringLengthValidator

func (*StringLengthValidator) Validate added in v0.2.0

func (v *StringLengthValidator) Validate(value string) error

type Validator added in v0.2.0

type Validator[T any] interface {
	Validate(value T) error
}

Jump to

Keyboard shortcuts

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