command

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 15 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Annotation added in v0.3.0

func Annotation(key, value string) opt.Option[Command]

Annotation sets a key-value pair in the Annotations map of a Command.

func Annotations added in v0.3.0

func Annotations(annotations map[string]string) opt.Option[Command]

Annotations sets additional metadata for the command via the provided annotations map.

func BoolFlag added in v0.4.8

func BoolFlag(flag Flag, ptr *bool) opt.Option[Command]

BoolFlag creates an option for a boolean flag within a Cobra command and links it to a specified bool pointer.

func Commands added in v0.5.0

func Commands(commandProviders ...any) opt.Option[app.Module]

func Deprecated added in v0.3.0

func Deprecated(reason ...string) opt.Option[Command]

Deprecated marks a Command as deprecated optionally specifying a reason.

func Do added in v0.5.0

func Do(impl func(ctx context.Context) error) opt.Option[Command]

Do is where your actual command code should go.

func Example added in v0.3.0

func Example(example string) opt.Option[Command]

Example sets the example string for a Command instance.

func IntFlag added in v0.4.8

func IntFlag(flag Flag, ptr *int) opt.Option[Command]

IntFlag registers an integer flag with the given flag specifications and stores the value in the specified pointer.

func Module

func Module() app.Module

func Runner added in v0.3.0

func Runner(impl func(cmd *cobra.Command, args []string) error) opt.Option[Command]

Runner is where your actual command code should go. Deprecated: use command.Do instead

func StringFlag added in v0.3.0

func StringFlag(flag Flag, ptr *string) opt.Option[Command]

StringFlag configures a string flag for a command using the provided Flag configuration and a pointer to store the flag's value.

func StringsFlag added in v0.5.0

func StringsFlag(flag Flag, ptr *[]string) opt.Option[Command]

StringsFlag registers a string slice command-line flag for the given Command.

func SuggestFor added in v0.3.0

func SuggestFor(alternatives ...string) opt.Option[Command]

SuggestFor returns an Option that sets the SuggestFor field of a Command to the provided alternatives.

Types

type Command

type Command struct {
	Name                   string
	Short                  string
	Long                   string
	Run                    func(cmd *cobra.Command, args []string) error
	Example                string
	Annotations            map[string]string
	Deprecated             string
	SuggestFor             []string
	MutuallyExclusiveFlags []string
	RequiredOneFlags       []string
	RequiredFlags          []string
	FlagHandlers           map[string]func(cmd *cobra.Command) error
	ChildOf                []string
}

func New

func New(name string, short string, long string, opts ...opt.Option[Command]) *Command

New creates a new Command instance with the specified name, short description, long description, and optional configurations.

type Flag added in v0.3.0

type Flag struct {
	// Name is the identifier for the command-line option.
	Name string
	// Shorthand is a single-character alias for the flag that allows for quicker command-line access.
	Shorthand string
	// Usage describes the purpose or functionality of the command-line flag.
	Usage string
	// OneRequired indicates that at least one of the flags marked with this field must be specified.
	OneRequired bool
	// Required indicates whether this flag is mandatory for the command-line tool to execute successfully.
	Required bool
	// Exclusive indicates whether the flag is mutually exclusive with other flags in the command-line tool.
	Exclusive bool
}

Flag represents a command-line option for a CLI application.

type Root

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

func NewRoot

func NewRoot(params RootParams) (*Root, error)

func (*Root) OnStart

func (r *Root) OnStart(ctx context.Context) error

func (*Root) OnStop

func (r *Root) OnStop(context.Context) error

type RootParams

type RootParams struct {
	fx.In
	Manifest *manifest.Manifest
	Shutdown fx.Shutdowner
	Commands []*Command `group:"command"`
}

Jump to

Keyboard shortcuts

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