plugin

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DiscoveryCommandName = "_plugin_commands"

Variables

This section is empty.

Functions

func NewDiscoveryCommand

func NewDiscoveryCommand(output io.Writer, rootCmd *cobra.Command) *cobra.Command

NewDiscoveryCommand creates a hidden command returning a description of the passed command hierarchy as JSON.

Types

type CommandSpec

type CommandSpec struct {
	Use                        string            `json:"use"`
	Aliases                    []string          `json:"aliases,omitempty"`
	SuggestFor                 []string          `json:"suggest_for,omitempty"`
	Short                      string            `json:"short,omitempty"`
	Long                       string            `json:"long,omitempty"`
	Example                    string            `json:"example,omitempty"`
	Deprecated                 string            `json:"deprecated,omitempty"`
	Annotations                map[string]string `json:"annotations,omitempty"`
	Version                    string            `json:"version,omitempty"`
	TraverseChildren           bool              `json:"traverse_children,omitempty"`
	Hidden                     bool              `json:"hidden,omitempty"`
	DisableAutoGenTag          bool              `json:"disable_auto_gen_tag,omitempty"`
	DisableFlagsInUseLine      bool              `json:"disable_flags_in_use_line,omitempty"`
	DisableSuggestions         bool              `json:"disable_suggestions,omitempty"`
	SuggestionsMinimumDistance int               `json:"suggestions_minimum_distance,omitempty"`

	LocalFlags      []FlagSpec    `json:"local_flags,omitempty"`
	PersistentFlags []FlagSpec    `json:"persistent_flags,omitempty"`
	Runnable        bool          `json:"runnable,omitempty"`
	SubCommands     []CommandSpec `json:"sub_commands,omitempty"`
}

CommandSpec is a serializable object that has all the information that describes a cobra.Command.

func SpecFromCommand

func SpecFromCommand(cmd *cobra.Command) CommandSpec

SpecFromCommand creates a CommandSpec describing a cobra.Command.

func (CommandSpec) ToCommand

func (c CommandSpec) ToCommand(runOverride func(*cobra.Command, []string) error) *cobra.Command

ToCommand creates a cobra.Command based on this CommandSpec.

type FlagSpec

type FlagSpec struct {
	Type                string              `json:"type,omitempty"`
	Name                string              `json:"name,omitempty"`
	Shorthand           string              `json:"shorthand,omitempty"`
	Usage               string              `json:"usage,omitempty"`
	DefaultValue        string              `json:"default_value,omitempty"`
	NoOptDefaultValue   string              `json:"no_opt_default_value,omitempty"`
	Deprecated          string              `json:"deprecated,omitempty"`
	Hidden              bool                `json:"hidden,omitempty"`
	ShorthandDeprecated string              `json:"shorthand_deprecated,omitempty"`
	Annotations         map[string][]string `json:"annotations,omitempty"`
}

FlagSpec is a serializable object that has all the information that describes a pflag.Flag.

func SpecFromFlag

func SpecFromFlag(flag *pflag.Flag) FlagSpec

SpecFromFlag creates a FlagSpec describing a flag.

func SpecsFromFlagset

func SpecsFromFlagset(flags *pflag.FlagSet) []FlagSpec

SpecsFromFlagset creates a slice of FlagSpecs from a pflag.FlagSet.

func (FlagSpec) ToFlag

func (spec FlagSpec) ToFlag() *pflag.Flag

ToFlag creates a pflag.Flag based on this FlagSpec.

type Spec

type Spec struct {
	Commands CommandSpec `json:"commands"`
}

Spec describes a CLI plugin in a serializable format.

Jump to

Keyboard shortcuts

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