cli

package
v0.2.63 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 35 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.GlazeCommand, aliases []*cmds.CommandAlias) error

func AddGlazedProcessorFlagsToCobraCommand added in v0.2.10

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

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

func BuildCobraCommandAlias added in v0.2.10

func BuildCobraCommandAlias(alias *cmds.CommandAlias) (*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(s cmds.GlazeCommand) (*cobra.Command, error)

func BuildCobraCommandFromWriterCommand added in v0.2.47

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

func CreateGlazedProcessorFromCobra added in v0.2.10

func CreateGlazedProcessorFromCobra(cmd *cobra.Command) (
	*cmds.GlazeProcessor,
	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 SetupProcessor 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

func NewJqMiddlewaresFromSettings added in v0.2.33

func NewJqMiddlewaresFromSettings(settings *JqSettings) (*middlewares.JqObjectMiddleware, *middlewares.JqTableMiddleware, error)

func SetupProcessor

func SetupProcessor(ps map[string]interface{}) (
	*cmds.GlazeProcessor,
	formatters.OutputFormatter,
	error,
)

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

type FieldsFilterFlagsDefaults

type FieldsFilterFlagsDefaults struct {
	Fields           []string `glazed.parameter:"fields"`
	Filter           []string `glazed.parameter:"filter"`
	SortColumns      bool     `glazed.parameter:"sort-columns"`
	RemoveNulls      bool     `glazed.parameter:"remove-nulls"`
	RemoveDuplicates []string `glazed.parameter:"remove-duplicates"`
}

type FieldsFilterSettings

type FieldsFilterSettings struct {
	Filters          []string `glazed.parameter:"filter"`
	Fields           []string `glazed.parameter:"fields"`
	SortColumns      bool     `glazed.parameter:"sort-columns"`
	RemoveNulls      bool     `glazed.parameter:"remove-nulls"`
	RemoveDuplicates []string `glazed.parameter:"remove-duplicates"`
	ReorderColumns   []string
}

func NewFieldsFilterSettings added in v0.2.6

func NewFieldsFilterSettings(ps map[string]interface{}) (*FieldsFilterSettings, error)

func (*FieldsFilterSettings) AddMiddlewares

func (ffs *FieldsFilterSettings) AddMiddlewares(of formatters.OutputFormatter)

type FieldsFiltersParameterLayer added in v0.2.10

type FieldsFiltersParameterLayer struct {
	*layers.ParameterLayerImpl
}

func NewFieldsFiltersParameterLayer added in v0.2.10

func NewFieldsFiltersParameterLayer(options ...layers.ParameterLayerOptions) (*FieldsFiltersParameterLayer, error)

func (*FieldsFiltersParameterLayer) AddFlagsToCobraCommand added in v0.2.10

func (f *FieldsFiltersParameterLayer) AddFlagsToCobraCommand(cmd *cobra.Command) error

func (*FieldsFiltersParameterLayer) ParseFlagsFromCobraCommand added in v0.2.10

func (f *FieldsFiltersParameterLayer) ParseFlagsFromCobraCommand(cmd *cobra.Command) (map[string]interface{}, error)

type GlazeParameterLayerOption added in v0.2.19

type GlazeParameterLayerOption func(*GlazedParameterLayers) error

func WithFieldsFiltersParameterLayerOptions added in v0.2.19

func WithFieldsFiltersParameterLayerOptions(options ...layers.ParameterLayerOptions) GlazeParameterLayerOption

func WithJqParameterLayerOptions added in v0.2.33

func WithJqParameterLayerOptions(options ...layers.ParameterLayerOptions) GlazeParameterLayerOption

func WithOutputParameterLayerOptions added in v0.2.19

func WithOutputParameterLayerOptions(options ...layers.ParameterLayerOptions) GlazeParameterLayerOption

func WithRenameParameterLayerOptions added in v0.2.19

func WithRenameParameterLayerOptions(options ...layers.ParameterLayerOptions) GlazeParameterLayerOption

func WithReplaceParameterLayerOptions added in v0.2.19

func WithReplaceParameterLayerOptions(options ...layers.ParameterLayerOptions) GlazeParameterLayerOption

func WithSelectParameterLayerOptions added in v0.2.19

func WithSelectParameterLayerOptions(options ...layers.ParameterLayerOptions) GlazeParameterLayerOption

func WithSortParameterLayerOptions added in v0.2.50

func WithSortParameterLayerOptions(options ...layers.ParameterLayerOptions) GlazeParameterLayerOption

func WithTemplateParameterLayerOptions added in v0.2.19

func WithTemplateParameterLayerOptions(options ...layers.ParameterLayerOptions) GlazeParameterLayerOption

type GlazedParameterLayers added in v0.2.10

type GlazedParameterLayers struct {
	FieldsFiltersParameterLayer *FieldsFiltersParameterLayer
	OutputParameterLayer        *OutputParameterLayer
	RenameParameterLayer        *RenameParameterLayer
	ReplaceParameterLayer       *ReplaceParameterLayer
	SelectParameterLayer        *SelectParameterLayer
	TemplateParameterLayer      *TemplateParameterLayer
	JqParameterLayer            *JqParameterLayer
	SortParameterLayer          *SortParameterLayer
}

func NewGlazedParameterLayers added in v0.2.10

func NewGlazedParameterLayers(options ...GlazeParameterLayerOption) (*GlazedParameterLayers, error)

func (*GlazedParameterLayers) AddFlag added in v0.2.10

func (*GlazedParameterLayers) AddFlagsToCobraCommand added in v0.2.10

func (g *GlazedParameterLayers) AddFlagsToCobraCommand(cmd *cobra.Command) error

func (*GlazedParameterLayers) GetDescription added in v0.2.13

func (g *GlazedParameterLayers) GetDescription() string

func (*GlazedParameterLayers) GetName added in v0.2.13

func (g *GlazedParameterLayers) GetName() string

func (*GlazedParameterLayers) GetParameterDefinitions added in v0.2.10

func (g *GlazedParameterLayers) GetParameterDefinitions() map[string]*parameters.ParameterDefinition

func (*GlazedParameterLayers) GetPrefix added in v0.2.18

func (g *GlazedParameterLayers) GetPrefix() string

func (*GlazedParameterLayers) GetSlug added in v0.2.13

func (g *GlazedParameterLayers) GetSlug() string

func (*GlazedParameterLayers) InitializeParameterDefaultsFromStruct added in v0.2.13

func (g *GlazedParameterLayers) InitializeParameterDefaultsFromStruct(s interface{}) error

func (*GlazedParameterLayers) ParseFlagsFromCobraCommand added in v0.2.10

func (g *GlazedParameterLayers) ParseFlagsFromCobraCommand(cmd *cobra.Command) (map[string]interface{}, error)

type JqParameterLayer added in v0.2.33

type JqParameterLayer struct {
	*layers.ParameterLayerImpl
}

func NewJqParameterLayer added in v0.2.33

func NewJqParameterLayer(options ...layers.ParameterLayerOptions) (*JqParameterLayer, error)

type JqSettings added in v0.2.33

type JqSettings struct {
	JqExpression       string            `glazed.parameter:"jq"`
	JqFile             string            `glazed.parameter:"jq-file"`
	JqFieldExpressions map[string]string `glazed.parameter:"field-jq"`
}

func NewJqSettingsFromParameters added in v0.2.33

func NewJqSettingsFromParameters(ps map[string]interface{}) (*JqSettings, error)

type OutputFormatterSettings

type OutputFormatterSettings struct {
	Output                    string                 `glazed.parameter:"output"`
	OutputFile                string                 `glazed.parameter:"output-file"`
	OutputFileTemplate        string                 `glazed.parameter:"output-file-template"`
	OutputMultipleFiles       bool                   `glazed.parameter:"output-multiple-files"`
	SheetName                 string                 `glazed.parameter:"sheet-name"`
	TableFormat               string                 `glazed.parameter:"table-format"`
	OutputAsObjects           bool                   `glazed.parameter:"output-as-objects"`
	FlattenObjects            bool                   `glazed.parameter:"flatten"`
	WithHeaders               bool                   `glazed.parameter:"with-headers"`
	CsvSeparator              string                 `glazed.parameter:"csv-separator"`
	Template                  string                 `glazed.parameter:"template-file"`
	TemplateData              map[string]interface{} `glazed.parameter:"template-data"`
	TemplateFormatterSettings *TemplateFormatterSettings
}

func NewOutputFormatterSettings added in v0.2.6

func NewOutputFormatterSettings(ps map[string]interface{}) (*OutputFormatterSettings, error)

func (*OutputFormatterSettings) CreateOutputFormatter

func (ofs *OutputFormatterSettings) CreateOutputFormatter() (formatters.OutputFormatter, error)

type OutputParameterLayer added in v0.2.10

type OutputParameterLayer struct {
	*layers.ParameterLayerImpl
}

func NewOutputParameterLayer added in v0.2.10

func NewOutputParameterLayer(options ...layers.ParameterLayerOptions) (*OutputParameterLayer, error)

type RenameFlagsDefaults

type RenameFlagsDefaults struct {
	Rename       []string          `glazed.parameter:"rename"`
	RenameRegexp map[string]string `glazed.parameter:"rename-regexp"`
	RenameYaml   string            `glazed.parameter:"rename-yaml"`
}

type RenameParameterLayer added in v0.2.10

type RenameParameterLayer struct {
	*layers.ParameterLayerImpl
}

func NewRenameParameterLayer added in v0.2.10

func NewRenameParameterLayer(options ...layers.ParameterLayerOptions) (*RenameParameterLayer, error)

type RenameSettings

type RenameSettings struct {
	RenameFields  map[types.FieldName]string
	RenameRegexps table.RegexpReplacements
	YamlFile      string
}

func NewRenameSettingsFromParameters added in v0.2.10

func NewRenameSettingsFromParameters(ps map[string]interface{}) (*RenameSettings, error)

func (*RenameSettings) AddMiddlewares

func (rs *RenameSettings) AddMiddlewares(of formatters.OutputFormatter) error

type ReplaceParameterLayer added in v0.2.10

type ReplaceParameterLayer struct {
	*layers.ParameterLayerImpl
}

func NewReplaceParameterLayer added in v0.2.10

func NewReplaceParameterLayer(options ...layers.ParameterLayerOptions) (*ReplaceParameterLayer, error)

type ReplaceSettings

type ReplaceSettings struct {
	ReplaceFile string            `glazed.parameter:"replace-file"`
	AddFields   map[string]string `glazed.parameter:"add-fields"`
}

func NewReplaceSettingsFromParameters added in v0.2.9

func NewReplaceSettingsFromParameters(ps map[string]interface{}) (*ReplaceSettings, error)

func (*ReplaceSettings) AddMiddlewares

func (rs *ReplaceSettings) AddMiddlewares(of formatters.OutputFormatter) error

type SelectParameterLayer added in v0.2.10

type SelectParameterLayer struct {
	*layers.ParameterLayerImpl
}

func NewSelectParameterLayer added in v0.2.10

func NewSelectParameterLayer(options ...layers.ParameterLayerOptions) (*SelectParameterLayer, error)

type SelectSettings

type SelectSettings struct {
	SelectField     string `glazed.parameter:"select"`
	SelectSeparator string `glazed.parameter:"select-separator"`
	SelectTemplate  string `glazed.parameter:"select-template"`
}

func NewSelectSettingsFromParameters added in v0.2.9

func NewSelectSettingsFromParameters(ps map[string]interface{}) (*SelectSettings, error)

type SortFlagsSettings added in v0.2.50

type SortFlagsSettings struct {
	SortBy []string `glazed.parameter:"sort-by"`
}

func NewSortSettingsFromParameters added in v0.2.50

func NewSortSettingsFromParameters(ps map[string]interface{}) (*SortFlagsSettings, error)

func (*SortFlagsSettings) AddMiddlewares added in v0.2.50

func (s *SortFlagsSettings) AddMiddlewares(of formatters.OutputFormatter)

type SortParameterLayer added in v0.2.50

type SortParameterLayer struct {
	*layers.ParameterLayerImpl
}

func NewSortParameterLayer added in v0.2.50

func NewSortParameterLayer(options ...layers.ParameterLayerOptions) (*SortParameterLayer, error)

type TemplateFlagsDefaults

type TemplateFlagsDefaults struct {
	Template        string            `glazed.parameter:"template"`
	TemplateField   map[string]string `glazed.parameter:"template-field"`
	UseRowTemplates bool              `glazed.parameter:"use-row-templates"`
}

func NewTemplateFlagsDefaults

func NewTemplateFlagsDefaults() *TemplateFlagsDefaults

type TemplateFormatterSettings

type TemplateFormatterSettings struct {
	TemplateFuncMaps []template.FuncMap
}

TemplateFormatterSettings is probably obsolete...

type TemplateParameterLayer added in v0.2.10

type TemplateParameterLayer struct {
	*layers.ParameterLayerImpl
}

func NewTemplateParameterLayer added in v0.2.10

func NewTemplateParameterLayer(options ...layers.ParameterLayerOptions) (*TemplateParameterLayer, error)

type TemplateSettings

type TemplateSettings struct {
	RenameSeparator string
	UseRowTemplates bool `glazed.parameter:"use-row-templates"`
	Templates       map[types.FieldName]string
}

func NewTemplateSettings added in v0.2.6

func NewTemplateSettings(parameters map[string]interface{}) (*TemplateSettings, error)

func (*TemplateSettings) AddMiddlewares

func (tf *TemplateSettings) AddMiddlewares(of formatters.OutputFormatter) error

func (*TemplateSettings) UpdateWithSelectSettings

func (tf *TemplateSettings) UpdateWithSelectSettings(ss *SelectSettings)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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