cli

package
v0.2.14 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 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 []*cmds.CommandAlias) error

func AddGlazedProcessorFlagsToCobraCommand added in v0.2.10

func AddGlazedProcessorFlagsToCobraCommand(cmd *cobra.Command, defaults interface{}) error

func BuildCobraCommand added in v0.2.10

func BuildCobraCommand(s cmds.Command) (*cobra.Command, error)

func BuildCobraCommandAlias added in v0.2.10

func BuildCobraCommandAlias(alias *cmds.CommandAlias) (*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.Command` 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.Command 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.

func SetupProcessor

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

Types

type FieldsFilterFlagsDefaults

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

type FieldsFilterSettings

type FieldsFilterSettings struct {
	Filters        []string `glazed.parameter:"filter"`
	Fields         []string `glazed.parameter:"fields"`
	SortColumns    bool     `glazed.parameter:"sort-columns"`
	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)

func (*FieldsFilterSettings) UpdateWithSelectSettings

func (ffs *FieldsFilterSettings) UpdateWithSelectSettings(ss *SelectSettings)

type FieldsFiltersParameterLayer added in v0.2.10

type FieldsFiltersParameterLayer struct {
	layers.ParameterLayerImpl
	Defaults *FieldsFilterFlagsDefaults
}

func NewFieldsFiltersParameterLayer added in v0.2.10

func NewFieldsFiltersParameterLayer() (*FieldsFiltersParameterLayer, error)

func (*FieldsFiltersParameterLayer) AddFlagsToCobraCommand added in v0.2.10

func (f *FieldsFiltersParameterLayer) AddFlagsToCobraCommand(cmd *cobra.Command, defaults interface{}) error

func (*FieldsFiltersParameterLayer) ParseFlagsFromCobraCommand added in v0.2.10

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

type GlazedParameterLayers added in v0.2.10

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

func NewGlazedParameterLayers added in v0.2.10

func NewGlazedParameterLayers() (*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, defaults interface{}) 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) 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) InitializeStructFromParameterDefaults added in v0.2.13

func (g *GlazedParameterLayers) InitializeStructFromParameterDefaults(interface{}) error

func (*GlazedParameterLayers) ParseFlagsFromCobraCommand added in v0.2.10

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

type OutputFlagsDefaults

type OutputFlagsDefaults struct {
	Output          string `glazed.parameter:"output"`
	OutputFile      string `glazed.parameter:"output-file"`
	TableFormat     string `glazed.parameter:"table-format"`
	WithHeaders     bool   `glazed.parameter:"with-headers"`
	CsvSeparator    string `glazed.parameter:"csv-separator"`
	OutputAsObjects bool   `glazed.parameter:"output-as-objects"`
	Flatten         bool   `glazed.parameter:"flatten"`
	TemplateFile    string `glazed.parameter:"template-file"`
}

type OutputFormatterSettings

type OutputFormatterSettings struct {
	Output                    string `glazed.parameter:"output"`
	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
	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)

func (*OutputFormatterSettings) UpdateWithSelectSettings

func (ofs *OutputFormatterSettings) UpdateWithSelectSettings(ss *SelectSettings)

type OutputParameterLayer added in v0.2.10

type OutputParameterLayer struct {
	layers.ParameterLayerImpl
	Defaults *OutputFlagsDefaults
}

func NewOutputParameterLayer added in v0.2.10

func NewOutputParameterLayer() (*OutputParameterLayer, error)

func (*OutputParameterLayer) AddFlagsToCobraCommand added in v0.2.10

func (opl *OutputParameterLayer) AddFlagsToCobraCommand(cmd *cobra.Command, s interface{}) 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
	Defaults *RenameFlagsDefaults
}

func NewRenameParameterLayer added in v0.2.10

func NewRenameParameterLayer() (*RenameParameterLayer, error)

func (*RenameParameterLayer) AddFlagsToCobraCommand added in v0.2.10

func (r *RenameParameterLayer) AddFlagsToCobraCommand(cmd *cobra.Command, s interface{}) error

type RenameSettings

type RenameSettings struct {
	RenameFields  map[types.FieldName]string
	RenameRegexps middlewares.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 ReplaceFlagsDefaults

type ReplaceFlagsDefaults struct {
	// currently, only support loading replacements from a file
	ReplaceFile string `glazed.parameter:"replace-file"`
}

type ReplaceParameterLayer added in v0.2.10

type ReplaceParameterLayer struct {
	layers.ParameterLayerImpl
	Defaults *ReplaceFlagsDefaults
}

func NewReplaceParameterLayer added in v0.2.10

func NewReplaceParameterLayer() (*ReplaceParameterLayer, error)

type ReplaceSettings

type ReplaceSettings struct {
	ReplaceFile string `glazed.parameter:"replace-file"`
}

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 SelectFlagsDefaults

type SelectFlagsDefaults struct {
	Select         string `glazed.parameter:"select"`
	SelectTemplate string `glazed.parameter:"select-template"`
}

type SelectParameterLayer added in v0.2.10

type SelectParameterLayer struct {
	layers.ParameterLayerImpl
	Defaults *SelectFlagsDefaults
}

func NewSelectParameterLayer added in v0.2.10

func NewSelectParameterLayer() (*SelectParameterLayer, error)

func (*SelectParameterLayer) AddFlagsToCobraCommand added in v0.2.10

func (s *SelectParameterLayer) AddFlagsToCobraCommand(cmd *cobra.Command, defaults interface{}) error

type SelectSettings

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

func NewSelectSettingsFromParameters added in v0.2.9

func NewSelectSettingsFromParameters(ps map[string]interface{}) (*SelectSettings, 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
	AdditionalData   map[string]interface{} `glazed.parameter:"template-data"`
}

type TemplateParameterLayer added in v0.2.10

type TemplateParameterLayer struct {
	layers.ParameterLayerImpl
	Defaults *TemplateFlagsDefaults
}

func NewTemplateParameterLayer added in v0.2.10

func NewTemplateParameterLayer() (*TemplateParameterLayer, error)

func (*TemplateParameterLayer) AddFlagsToCobraCommand added in v0.2.10

func (t *TemplateParameterLayer) AddFlagsToCobraCommand(cmd *cobra.Command, defaults interface{}) 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)

Jump to

Keyboard shortcuts

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