cli

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 25 Imported by: 71

Documentation

Index

Constants

View Source
const CommandSettingsSlug = "command-settings"
View Source
const CreateCommandSettingsSlug = "create-command-settings"
View Source
const ProfileSettingsSlug = "profile-settings"

Variables

This section is empty.

Functions

func AddCommandsToRootCommand added in v0.2.10

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

func AddGlazedProcessorFlagsToCobraCommand added in v0.2.10

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

AddGlazedProcessorFlagsToCobraCommand is a helper for cobra centric apps that quickly want to add the glazed processing section to their CLI flags.

func BuildCobraCommand added in v0.2.10

func BuildCobraCommand(
	command cmds.Command,
	opts ...CobraOption,
) (*cobra.Command, error)

BuildCobraCommand is an alias to help with LLM hallucinations

func BuildCobraCommandAlias added in v0.2.10

func BuildCobraCommandAlias(
	alias *alias.CommandAlias,
	opts ...CobraOption,
) (*cobra.Command, error)

func BuildCobraCommandFromCommand added in v0.2.47

func BuildCobraCommandFromCommand(
	s cmds.Command,
	opts ...CobraOption,
) (*cobra.Command, error)

Unified builder: determines runFunc based on implemented interfaces and delegates to BuildCobraCommandFromCommandAndFunc

func BuildCobraCommandFromCommandAndFunc added in v0.4.3

func BuildCobraCommandFromCommandAndFunc(
	s cmds.Command,
	run CobraRunFunc,
	opts ...CobraOption,
) (*cobra.Command, error)

func CobraCommandDefaultMiddlewares added in v0.4.36

func CobraCommandDefaultMiddlewares(
	parsedCommandSections *values.Values,
	cmd *cobra.Command,
	args []string,
) ([]cmd_sources.Middleware, error)

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

If the commandSettings specify fields 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 section.

If you are more serious about using glazed, consider using the `cmds.GlazeCommand` and `fields.Definition` abstraction to define your CLI applications, which allows you to use sections 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 NewCommandSettingsSection added in v1.0.0

func NewCommandSettingsSection() (schema.Section, error)

func NewCreateCommandSettingsSection added in v1.0.0

func NewCreateCommandSettingsSection() (schema.Section, error)

func NewProfileSettingsSection added in v1.0.0

func NewProfileSettingsSection() (schema.Section, error)

func ParseCommandSettingsSection added in v1.0.0

func ParseCommandSettingsSection(cmd *cobra.Command) (*values.Values, error)

ParseGlazedCommandSection parses the global glazed settings from the given cobra.Command, if not nil, and from the command itself if present.

Types

type CobraMiddlewaresFunc added in v0.4.36

type CobraMiddlewaresFunc func(
	parsedCommandSections *values.Values,
	cmd *cobra.Command,
	args []string,
) ([]cmd_sources.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" section set in the GlazedCommandSettings.

type CobraOption added in v0.6.7

type CobraOption func(cfg *commandBuildConfig)

Insert foundation types for unified builder options CobraOption configures command and parser builder settings

func WithCobraMiddlewaresFunc added in v0.4.36

func WithCobraMiddlewaresFunc(fn CobraMiddlewaresFunc) CobraOption

WithCobraMiddlewaresFunc sets a custom middleware function for parsing (deprecated)

func WithCobraShortHelpSections added in v1.0.0

func WithCobraShortHelpSections(sections ...string) CobraOption

WithCobraShortHelpSections sets the sections shown in short help.

func WithCreateCommandSettingsSection added in v1.0.0

func WithCreateCommandSettingsSection() CobraOption

WithCreateCommandSettingsSection enables the create-command settings section.

func WithDefaultToGlaze added in v0.6.2

func WithDefaultToGlaze() CobraOption

WithDefaultToGlaze makes glaze mode the default unless negated

func WithDualMode added in v0.6.7

func WithDualMode(enabled bool) CobraOption

WithDualMode enables or disables dual-mode behavior

func WithGlazeToggleFlag added in v0.6.2

func WithGlazeToggleFlag(name string) CobraOption

WithGlazeToggleFlag customizes the glaze toggle flag name

func WithHiddenGlazeFlags added in v0.6.2

func WithHiddenGlazeFlags(names ...string) CobraOption

WithHiddenGlazeFlags marks glaze flags to remain hidden

func WithParserConfig added in v0.6.7

func WithParserConfig(cfg CobraParserConfig) CobraOption

WithParserConfig sets parser customization on the builder

func WithProfileSettingsSection added in v1.0.0

func WithProfileSettingsSection() CobraOption

WithProfileSettingsSection enables the profile settings section.

func WithSkipCommandSettingsSection added in v1.0.0

func WithSkipCommandSettingsSection() CobraOption

WithSkipCommandSettingsSection hides the command settings section flags.

type CobraParser added in v0.2.46

type CobraParser struct {
	Sections *schema.Schema
	// 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 SectionValues 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 Sections from the description.

func NewCobraParserFromSections added in v1.0.0

func NewCobraParserFromSections(
	sections *schema.Schema,
	cfg *CobraParserConfig,
) (*CobraParser, error)

NewCobraParserFromSections creates a new CobraParser instance from a CommandDescription, initializes the underlying cobra.Command, and adds all the fields specified in the Sections 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,
) (*values.Values, error)

type CobraParserConfig added in v0.6.7

type CobraParserConfig struct {
	MiddlewaresFunc                    CobraMiddlewaresFunc
	ShortHelpSections                  []string
	SkipCommandSettingsSection         bool
	EnableProfileSettingsSection       bool
	EnableCreateCommandSettingsSection bool
	// New: application name and optional explicit config path
	AppName    string
	ConfigPath string
	// New: optional callback returning an ordered list of config files (low -> high precedence)
	ConfigFilesFunc func(parsedCommandSections *values.Values, cmd *cobra.Command, args []string) ([]string, error)
}

Inserted: new config struct for parser customization

type CobraRunFunc added in v0.2.47

type CobraRunFunc func(ctx context.Context, parsedValues *values.Values) error

type CommandSettings added in v0.5.29

type CommandSettings struct {
	PrintYAML         bool   `glazed:"print-yaml"`
	PrintParsedFields bool   `glazed:"print-parsed-fields"`
	PrintSchema       bool   `glazed:"print-schema"`
	ConfigFile        string `glazed:"config-file"`
}

GlazedMinimalCommandSettings contains a subset of the most commonly used settings

type CreateCommandSettings added in v0.5.29

type CreateCommandSettings struct {
	CreateCommand   string `glazed:"create-command"`
	CreateAlias     string `glazed:"create-alias"`
	CreateCliopatra string `glazed:"create-cliopatra"`
}

type ProfileSettings added in v0.5.29

type ProfileSettings struct {
	Profile     string `glazed:"profile"`
	ProfileFile string `glazed:"profile-file"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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