Documentation
¶
Index ¶
- type BareCommand
- type Command
- type CommandDescription
- func (cd *CommandDescription) Clone(cloneSchema bool, options ...CommandDescriptionOption) *CommandDescription
- func (cd *CommandDescription) Description() *CommandDescription
- func (cd *CommandDescription) FullPath() string
- func (cd *CommandDescription) GetDefaultArguments() *fields.Definitions
- func (cd *CommandDescription) GetDefaultFlags() *fields.Definitions
- func (cd *CommandDescription) GetDefaultSection() (schema.Section, bool)
- func (cd *CommandDescription) GetDefaultsMap() (map[string]interface{}, error)
- func (cd *CommandDescription) GetSection(name string) (schema.Section, bool)
- func (cd *CommandDescription) SetSections(sections ...schema.Section)
- func (c *CommandDescription) ToJsonSchema() (*CommandJsonSchema, error)
- func (cd *CommandDescription) ToYAML(w io.Writer) error
- type CommandDescriptionOption
- func WithArguments(arguments ...*fields.Definition) CommandDescriptionOption
- func WithFlags(flags ...*fields.Definition) CommandDescriptionOption
- func WithLayout(l *layout.Layout) CommandDescriptionOption
- func WithLong(s string) CommandDescriptionOption
- func WithMetadata(metadata map[string]interface{}) CommandDescriptionOption
- func WithName(s string) CommandDescriptionOption
- func WithParents(p ...string) CommandDescriptionOption
- func WithPrependSource(s string) CommandDescriptionOption
- func WithReplaceSections(sections ...schema.Section) CommandDescriptionOption
- func WithSchema(schema_ *schema.Schema) CommandDescriptionOption
- func WithSections(sections ...schema.Section) CommandDescriptionOption
- func WithSectionsMap(m map[string]schema.Section) CommandDescriptionOption
- func WithShort(s string) CommandDescriptionOption
- func WithSource(s string) CommandDescriptionOption
- func WithStripParentsPrefix(prefixes []string) CommandDescriptionOption
- func WithTags(tags ...string) CommandDescriptionOption
- func WithType(t string) CommandDescriptionOption
- type CommandJsonSchema
- type CommandWithMetadata
- type ExitWithoutGlazeError
- type GlazeCommand
- type JsonSchemaProperty
- type TemplateCommand
- type TemplateCommandDescription
- type TemplateCommandLoader
- type WriterCommand
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BareCommand ¶ added in v0.2.46
type Command ¶
type Command interface {
Description() *CommandDescription
ToYAML(w io.Writer) error
}
type CommandDescription ¶
type CommandDescription struct {
Name string `yaml:"name"`
Short string `yaml:"short"`
Long string `yaml:"long,omitempty"`
// TODO(manuel, 2023-12-21) Does this need to be a list of pointers? Could it just be a list of struct?
Layout []*layout.Section `yaml:"layout,omitempty"`
Schema *schema.Schema `yaml:"schema,omitempty"`
AdditionalData map[string]interface{} `yaml:"additionalData,omitempty"`
Type string `yaml:"type,omitempty"`
Tags []string `yaml:"tags,omitempty"`
Metadata map[string]interface{} `yaml:"metadata,omitempty"`
Parents []string `yaml:",omitempty"`
// Source indicates where the command was loaded from, to make debugging easier.
Source string `yaml:",omitempty"`
}
CommandDescription contains the necessary information for registering a command with cobra. Because a command gets registered in a verb tree, a full list of Parents all the way to the root needs to be provided.
func NewCommandDescription ¶ added in v0.2.10
func NewCommandDescription(name string, options ...CommandDescriptionOption) *CommandDescription
func (*CommandDescription) Clone ¶ added in v0.2.25
func (cd *CommandDescription) Clone(cloneSchema bool, options ...CommandDescriptionOption) *CommandDescription
func (*CommandDescription) Description ¶ added in v0.4.0
func (cd *CommandDescription) Description() *CommandDescription
func (*CommandDescription) FullPath ¶ added in v0.5.14
func (cd *CommandDescription) FullPath() string
func (*CommandDescription) GetDefaultArguments ¶ added in v0.4.36
func (cd *CommandDescription) GetDefaultArguments() *fields.Definitions
func (*CommandDescription) GetDefaultFlags ¶ added in v0.4.36
func (cd *CommandDescription) GetDefaultFlags() *fields.Definitions
func (*CommandDescription) GetDefaultSection ¶ added in v1.0.0
func (cd *CommandDescription) GetDefaultSection() (schema.Section, bool)
func (*CommandDescription) GetDefaultsMap ¶ added in v0.5.37
func (cd *CommandDescription) GetDefaultsMap() (map[string]interface{}, error)
GetDefaultsMap returns a map of field names to their default values by combining the default flags and arguments.
func (*CommandDescription) GetSection ¶ added in v1.0.0
func (cd *CommandDescription) GetSection(name string) (schema.Section, bool)
func (*CommandDescription) SetSections ¶ added in v1.0.0
func (cd *CommandDescription) SetSections(sections ...schema.Section)
func (*CommandDescription) ToJsonSchema ¶ added in v0.5.29
func (c *CommandDescription) ToJsonSchema() (*CommandJsonSchema, error)
ToJsonSchema converts a ShellCommand to a JSON Schema representation
type CommandDescriptionOption ¶ added in v0.2.10
type CommandDescriptionOption func(*CommandDescription)
func WithArguments ¶ added in v0.2.10
func WithArguments( arguments ...*fields.Definition, ) CommandDescriptionOption
WithArguments is a convenience function to add arguments to the default section, useful to make the transition from explicit flags and arguments to a default section a bit easier.
func WithFlags ¶ added in v0.2.10
func WithFlags( flags ...*fields.Definition, ) CommandDescriptionOption
WithFlags is a convenience function to add arguments to the default section, useful to make the transition from explicit flags and arguments to a default section a bit easier.
func WithLayout ¶ added in v0.2.70
func WithLayout(l *layout.Layout) CommandDescriptionOption
func WithLong ¶ added in v0.2.10
func WithLong(s string) CommandDescriptionOption
func WithMetadata ¶ added in v0.5.31
func WithMetadata(metadata map[string]interface{}) CommandDescriptionOption
func WithName ¶ added in v0.2.25
func WithName(s string) CommandDescriptionOption
func WithParents ¶ added in v0.2.10
func WithParents(p ...string) CommandDescriptionOption
func WithPrependSource ¶ added in v0.2.27
func WithPrependSource(s string) CommandDescriptionOption
func WithReplaceSections ¶ added in v1.0.0
func WithReplaceSections(sections ...schema.Section) CommandDescriptionOption
func WithSchema ¶ added in v0.7.4
func WithSchema(schema_ *schema.Schema) CommandDescriptionOption
func WithSections ¶ added in v1.0.0
func WithSections(sections ...schema.Section) CommandDescriptionOption
func WithSectionsMap ¶ added in v1.0.0
func WithSectionsMap(m map[string]schema.Section) CommandDescriptionOption
WithSectionsMap registers sections using explicit slugs from the provided map. The map key is used as the registration slug. If a section's internal slug (returned by section.GetSlug()) differs from the map key, this function will try to align them when possible so that runtime parsing and lookups are consistent:
- Prefer cloning the section and overriding the slug on the clone when the clone is a *schema.SectionImpl (common for wrapper types that embed SectionImpl and whose Clone returns a SectionImpl).
- Otherwise, the section is registered under the provided key as-is.
Note: If a non-SectionImpl is registered under a key that differs from its internal slug, middlewares that derive resolved section slugs from the section's GetSlug() may use the internal slug instead of the registration key. Prefer using matching slugs or SectionImpl when you need explicit remapping.
func WithShort ¶ added in v0.2.10
func WithShort(s string) CommandDescriptionOption
func WithSource ¶ added in v0.2.10
func WithSource(s string) CommandDescriptionOption
func WithStripParentsPrefix ¶ added in v0.2.27
func WithStripParentsPrefix(prefixes []string) CommandDescriptionOption
func WithTags ¶ added in v0.5.31
func WithTags(tags ...string) CommandDescriptionOption
func WithType ¶ added in v0.5.30
func WithType(t string) CommandDescriptionOption
type CommandJsonSchema ¶ added in v0.5.29
type CommandJsonSchema struct {
Type string `json:"type"`
Description string `json:"description,omitempty"`
Properties map[string]*JsonSchemaProperty `json:"properties"`
Required []string `json:"required,omitempty"`
}
CommandJsonSchema represents the root JSON Schema for a command
type CommandWithMetadata ¶ added in v0.4.15
type ExitWithoutGlazeError ¶ added in v0.2.16
type ExitWithoutGlazeError struct{}
func (*ExitWithoutGlazeError) Error ¶ added in v0.2.16
func (e *ExitWithoutGlazeError) Error() string
type GlazeCommand ¶ added in v0.2.45
type GlazeCommand interface {
Command
// RunIntoGlazeProcessor is called to actually execute the command.
//
// NOTE(manuel, 2023-02-27) We can probably simplify this to only take resolved values
//
// The ps and GlazeProcessor calls could be replaced by a GlazeCommand specific section,
// which would allow the GlazeCommand to parse into a specific struct. The GlazeProcessor
// is just something created by the passed in GlazeSection anyway.
//
// When we are just left with building a convenience wrapper for Glaze based commands,
// instead of forcing it into the upstream interface.
//
// https://github.com/go-go-golems/glazed/issues/217
// https://github.com/go-go-golems/glazed/issues/216
// See https://github.com/go-go-golems/glazed/issues/173
RunIntoGlazeProcessor(ctx context.Context, parsedValues *values.Values, gp middlewares.Processor) error
}
type JsonSchemaProperty ¶ added in v0.5.29
type JsonSchemaProperty struct {
Type string `json:"type"`
Description string `json:"description,omitempty"`
Enum []string `json:"enum,omitempty"`
Default interface{} `json:"default,omitempty"`
Items *JsonSchemaProperty `json:"items,omitempty"`
Required bool `json:"-"`
Properties map[string]*JsonSchemaProperty `json:"properties,omitempty"`
AdditionalProperties *JsonSchemaProperty `json:"additionalProperties,omitempty"`
}
JsonSchemaProperty represents a property in the JSON Schema
type TemplateCommand ¶ added in v0.4.12
type TemplateCommand struct {
*CommandDescription
Template string
}
func NewTemplateCommand ¶ added in v0.4.36
func NewTemplateCommand(name string, template string, options ...CommandDescriptionOption) *TemplateCommand
func (*TemplateCommand) IsValid ¶ added in v0.4.12
func (t *TemplateCommand) IsValid() bool
func (*TemplateCommand) RunIntoWriter ¶ added in v0.4.12
type TemplateCommandDescription ¶ added in v0.4.12
type TemplateCommandDescription struct {
Name string `yaml:"name"`
Short string `yaml:"short"`
Long string `yaml:"long,omitempty"`
Layout []*layout.Section `yaml:"layout,omitempty"`
Flags []*fields.Definition `yaml:"flags,omitempty"`
Arguments []*fields.Definition `yaml:"arguments,omitempty"`
Schema schema.Schema `yaml:"schema,omitempty"`
Template string `yaml:"template"`
}
type TemplateCommandLoader ¶ added in v0.4.12
type TemplateCommandLoader struct{}
func (*TemplateCommandLoader) LoadCommandFromYAML ¶ added in v0.4.12
func (tcl *TemplateCommandLoader) LoadCommandFromYAML( s io.Reader, options ...CommandDescriptionOption, ) ([]Command, error)