cli

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: MIT Imports: 20 Imported by: 40

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCommandsToRootCommand added in v0.2.10

func AddCommandsToRootCommand(rootCmd *cobra.Command, commands []cmds.Command, aliases []*alias.CommandAlias) error

func AddGlazedProcessorFlagsToCobraCommand added in v0.2.10

func AddGlazedProcessorFlagsToCobraCommand(cmd *cobra.Command, options ...settings.GlazeParameterLayerOption) error

AddGlazedProcessorFlagsToCobraCommand is a helper for cobra centric apps that quickly want to add the glazed processing layer.

func BuildCobraCommandFromBareCommand added in v0.2.69

func BuildCobraCommandFromBareCommand(c cmds.BareCommand) (*cobra.Command, error)

func BuildCobraCommandFromCommand added in v0.2.47

func BuildCobraCommandFromCommand(s cmds.Command, run CobraRunFunc) (*cobra.Command, error)

func BuildCobraCommandFromGlazeCommand added in v0.2.46

func BuildCobraCommandFromGlazeCommand(cmd_ cmds.GlazeCommand) (*cobra.Command, error)

func BuildCobraCommandFromWriterCommand added in v0.2.47

func BuildCobraCommandFromWriterCommand(s cmds.WriterCommand) (*cobra.Command, error)

func BuildCobraGlazeCommandAlias added in v0.2.81

func BuildCobraGlazeCommandAlias(alias *alias.CommandAlias) (*cobra.Command, error)

func CreateGlazedProcessorFromCobra added in v0.2.10

func CreateGlazedProcessorFromCobra(cmd *cobra.Command) (*middlewares.TableProcessor, formatters.OutputFormatter, error)

CreateGlazedProcessorFromCobra is a helper for cobra centric apps that quickly want to add the glazed processing layer.

If you are more serious about using glazed, consider using the `cmds.GlazeCommand` and `parameters.ParameterDefinition` abstraction to define your CLI applications, which allows you to use layers and other nice features of the glazed ecosystem.

If so, use SetupTableProcessor instead, and create a proper glazed.GlazeCommand for your command.

func GatherParametersFromCobraCommand added in v0.2.10

func GatherParametersFromCobraCommand(
	cmd *cobra.Command,
	description *cmds.CommandDescription,
	args []string,
) (map[string]interface{}, error)

GatherParametersFromCobraCommand takes a cobra command, an argument list as well as a description of the command, and returns a list of parsed parameters as a hashmap. It does so by parsing both the flags and the positional arguments.

TODO(manuel, 2021-02-04) This function should return how a parameter was set This would match warg's behaviour. It would also make it possible for us to record if it was set from ENV, from the query, from default, frmo which config file, etc...

See https://github.com/go-go-golems/glazed/issues/172

func GetVerbsFromCobraCommand added in v0.2.55

func GetVerbsFromCobraCommand(cmd *cobra.Command) []string

Types

type CobraParameterLayer added in v0.2.46

type CobraParameterLayer interface {
	// AddFlagsToCobraCommand adds all the flags defined in this layer to the given cobra command.
	//
	// NOTE(manuel, 2023-02-27) This can be moved to use that ParameterLayerParser API
	// As I'm working out what it means to parse layers and use it to fill structs,
	// and how defaults should be registered, it makes sense to move this out.
	// Further more, defaults should probably be managed in the layer entirely, and
	// thus not be shown in the interface here.
	//
	// Do we want to keep the parsers in the layer itself, so that when a command is registered,
	// it gets registered here? Or should the parsers and registerers be outside,
	// and generic enough to be able to process all the layers of a command without
	// the command framework knowing about it. This seems to make more sense.
	AddFlagsToCobraCommand(cmd *cobra.Command) error
	ParseFlagsFromCobraCommand(cmd *cobra.Command) (map[string]interface{}, error)
}

type CobraParser added in v0.2.46

type CobraParser struct {
	Cmd *cobra.Command
	// contains filtered or unexported fields
}

CobraParser takes a CommandDescription, and hooks it up to a cobra command. It can then be used to parse the cobra flags and arguments back into a set of ParsedParameterLayer and a map[string]interface{} for the lose stuff.

That command however doesn't have a Run method, which is left to the caller to implement.

This returns a CobraParser that can be used to parse the registered layers from the description.

func NewCobraParserFromCommandDescription added in v0.2.46

func NewCobraParserFromCommandDescription(description *cmds.CommandDescription) (*CobraParser, error)

func (*CobraParser) Parse added in v0.2.46

func (c *CobraParser) Parse(args []string) (map[string]*layers.ParsedParameterLayer, map[string]interface{}, error)

type CobraRunFunc added in v0.2.47

type CobraRunFunc func(ctx context.Context, parsedLayers map[string]*layers.ParsedParameterLayer, ps map[string]interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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