cli

package
v0.5.27 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: MIT Imports: 21 Imported by: 46

Documentation

Index

Constants

View Source
const GlazedCommandSlug = "glazed-command"

Variables

This section is empty.

Functions

func AddCommandsToRootCommand added in v0.2.10

func AddCommandsToRootCommand(
	rootCmd *cobra.Command,
	commands []cmds.Command,
	aliases []*alias.CommandAlias,
	options ...CobraParserOption,
) 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 to their CLI flags.

func BuildCobraCommandAlias added in v0.2.10

func BuildCobraCommandAlias(
	alias *alias.CommandAlias,
	options ...CobraParserOption,
) (*cobra.Command, error)

func BuildCobraCommandFromBareCommand added in v0.2.69

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

func BuildCobraCommandFromCommand added in v0.2.47

func BuildCobraCommandFromCommand(
	command cmds.Command,
	options ...CobraParserOption,
) (*cobra.Command, error)

func BuildCobraCommandFromCommandAndFunc added in v0.4.3

func BuildCobraCommandFromCommandAndFunc(
	s cmds.Command,
	run CobraRunFunc,
	options ...CobraParserOption,
) (*cobra.Command, error)

func BuildCobraCommandFromGlazeCommand added in v0.2.46

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

func BuildCobraCommandFromWriterCommand added in v0.2.47

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

func CobraCommandDefaultMiddlewares added in v0.4.36

func CobraCommandDefaultMiddlewares(
	commandSettings *GlazedCommandSettings,
	cmd *cobra.Command,
	args []string,
) ([]cmd_middlewares.Middleware, error)

CobraCommandDefaultMiddlewares is the default implementation for creating the middlewares used in a Cobra command. It handles parsing parameters from Cobra flags, command line arguments, environment variables, and default values. The middlewares gather all these parameters into a ParsedParameters object.

If the commandSettings specify parameters to be loaded from a file, this gets added as a middleware.

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 GetVerbsFromCobraCommand added in v0.2.55

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

func NewCobraCommandFromCommandDescription added in v0.5.3

func NewCobraCommandFromCommandDescription(
	description *cmds.CommandDescription,
) *cobra.Command

func NewGlazedCommandLayer added in v0.4.36

func NewGlazedCommandLayer() (layers.ParameterLayer, error)

Types

type CobraMiddlewaresFunc added in v0.4.36

type CobraMiddlewaresFunc func(
	commandSettings *GlazedCommandSettings,
	cmd *cobra.Command,
	args []string,
) ([]cmd_middlewares.Middleware, error)

CobraMiddlewaresFunc is a function that returns a list of middlewares for a cobra command. It can be used to overload the default middlewares for cobra commands. It is mostly used to add a "load from json" layer set in the GlazedCommandSettings.

type CobraParser added in v0.2.46

type CobraParser struct {
	Layers *layers.ParameterLayers
	// 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 ParsedLayer 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 NewCobraParserFromLayers added in v0.5.3

func NewCobraParserFromLayers(
	layers *layers.ParameterLayers,
	options ...CobraParserOption,
) (*CobraParser, error)

NewCobraParserFromLayers creates a new CobraParser instance from a CommandDescription, initializes the underlying cobra.Command, and adds all the parameters specified in the Layers CommandDescription to the cobra command.

func (*CobraParser) AddToCobraCommand added in v0.5.3

func (c *CobraParser) AddToCobraCommand(cmd *cobra.Command) error

func (*CobraParser) Parse added in v0.2.46

func (c *CobraParser) Parse(
	cmd *cobra.Command,
	args []string,
) (*layers.ParsedLayers, error)

type CobraParserOption added in v0.4.36

type CobraParserOption func(*CobraParser) error

func WithCobraMiddlewaresFunc added in v0.4.36

func WithCobraMiddlewaresFunc(middlewaresFunc CobraMiddlewaresFunc) CobraParserOption

func WithCobraShortHelpLayers added in v0.5.6

func WithCobraShortHelpLayers(layers ...string) CobraParserOption

func WithSkipGlazedCommandLayer added in v0.5.27

func WithSkipGlazedCommandLayer() CobraParserOption

type CobraRunFunc added in v0.2.47

type CobraRunFunc func(ctx context.Context, parsedLayers *layers.ParsedLayers) error

type GlazedCommandSettings added in v0.4.36

type GlazedCommandSettings struct {
	CreateCommand          string `glazed.parameter:"create-command"`
	CreateAlias            string `glazed.parameter:"create-alias"`
	CreateCliopatra        string `glazed.parameter:"create-cliopatra"`
	PrintYAML              bool   `glazed.parameter:"print-yaml"`
	PrintParsedParameters  bool   `glazed.parameter:"print-parsed-parameters"`
	LoadParametersFromFile string `glazed.parameter:"load-parameters-from-file"`
	Profile                string `glazed.parameter:"profile"`
	ProfileFile            string `glazed.parameter:"profile-file"`
}

func ParseGlazedCommandLayer added in v0.5.17

func ParseGlazedCommandLayer(cmd *cobra.Command) (*GlazedCommandSettings, error)

ParseGlazedCommandLayer parses the global glazed settings from the given cobra.Command, if not nil, and from the configured viper config file.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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