kcobra

package
v0.0.0-...-66343a0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: BSD-3-Clause, BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CobraPopulator

func CobraPopulator(root *cobra.Command, args []string) kflags.Populator

CobraPopulator returns a kflags.Populator capable of filling in the defaults for flags defined through cobra and the pflags library.

func LogFlags

func LogFlags(command *cobra.Command, log logger.Printer)

func PopulateCommands

func PopulateCommands(root *cobra.Command, args []string, resolvers ...kflags.Augmenter) error

func PopulateDefaults

func PopulateDefaults(root *cobra.Command, args []string, resolvers ...kflags.Augmenter) error

func PopulateFlagDefaults

func PopulateFlagDefaults(root *cobra.Command, args []string, resolvers ...kflags.Augmenter) error

PopulateFlagDefaults is a function that walks all the flags of the specified root command and all its sub commands, the argv provided as args, and tries to provide defaults using the spcified resolvers.

root is the cobra.Command of which to walk the flags to fill in the defaults.

args is the list of command line parameters passed to the command, argv. This is generally os.Args. It is expected to include argv[0], the path of the command, as first argument.

resolvers is the list of resolvers to use to assign the defaults.

WARNING: PopulateFlagDefaults does not call Done() supplied list of resolvers. It is the responsibility of the caller to do so.

func Run

func Run(root *cobra.Command, mods ...Modifier)

Types

type Command

type Command interface {
	Execute() error
	UsageString() string

	Println(...interface{})
	Printf(string, ...interface{})
}

type FlagSet

type FlagSet struct {
	*pflag.FlagSet
}

func Runner

func Runner(root *cobra.Command, argv []string, eh ...kflags.ErrorHandler) (*FlagSet, kflags.Populator, kflags.Runner)

func (*FlagSet) ByteFileVar

func (fs *FlagSet) ByteFileVar(p *[]byte, name string, defaultFile string, usage string, mods ...kflags.ByteFileModifier)

type Helper

type Helper interface {
	Help(cmd *cobra.Command, args []string) bool
}

type HiddenFlagSet

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

func HideFlags

func HideFlags(fs *FlagSet) *HiddenFlagSet

func (*HiddenFlagSet) BoolVar

func (hfs *HiddenFlagSet) BoolVar(p *bool, name string, value bool, usage string)

func (*HiddenFlagSet) ByteFileVar

func (hfs *HiddenFlagSet) ByteFileVar(p *[]byte, name string, defaultFile string, usage string, mods ...kflags.ByteFileModifier)

func (*HiddenFlagSet) DurationVar

func (hfs *HiddenFlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string)

func (*HiddenFlagSet) Help

func (hfs *HiddenFlagSet) Help(cmd *cobra.Command, args []string) bool

func (*HiddenFlagSet) Hide

func (hfs *HiddenFlagSet) Hide(name string)

func (*HiddenFlagSet) IntVar

func (hfs *HiddenFlagSet) IntVar(p *int, name string, value int, usage string)

func (*HiddenFlagSet) StringArrayVar

func (hfs *HiddenFlagSet) StringArrayVar(p *[]string, name string, value []string, usage string)

func (*HiddenFlagSet) StringVar

func (hfs *HiddenFlagSet) StringVar(p *string, name string, value string, usage string)

type KCommand

type KCommand struct {
	*cobra.Command
}

func (*KCommand) AddCommand

func (kc *KCommand) AddCommand(def kflags.CommandDefinition, flags []kflags.FlagDefinition, action kflags.CommandAction) error

func (*KCommand) Hide

func (kc *KCommand) Hide(hidden bool)

type Modifier

type Modifier func(*cobra.Command, *options) error

func WithArgs

func WithArgs(argv []string) Modifier

WithArgs sets the argv used by the parser. If not set, defaults to os.Args.

func WithErrorHandler

func WithErrorHandler(eh ...kflags.ErrorHandler) Modifier

WithErrorHandler sets a function that will be invoked for each error returned by the program. This is useful to allow to implement logic to handle specific errors in specific ways, or to augment the error message with more details.

func WithHelper

func WithHelper(helper func(c *cobra.Command, args []string) bool) Modifier

func WithPrinter

func WithPrinter(log kflags.Printer) Modifier

WithPrinter sets a function to use for logging.

func WithRunner

func WithRunner(runner func() error) Modifier

Adds a function to run before the actual program. This is useful to perform - for example - additional initialization.

type Modifiers

type Modifiers []Modifier

func (Modifiers) Apply

func (mods Modifiers) Apply(c *cobra.Command, o *options) error

type PFlag

type PFlag struct {
	*pflag.Flag
}

func (*PFlag) Name

func (pf *PFlag) Name() string

func (*PFlag) Set

func (pf *PFlag) Set(value string) error

func (*PFlag) SetContent

func (pf *PFlag) SetContent(origin string, data []byte) error

type Runnable

type Runnable interface {
	Run() error
}

Jump to

Keyboard shortcuts

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