|
| 1 | +package command |
| 2 | + |
| 3 | +type Command struct { |
| 4 | + Name string `yaml:"name" json:"name" jsonschema_description:"Name of the command"` |
| 5 | + Aliases []string `yaml:"aliases,omitempty" json:"aliases,omitempty" jsonschema_description:"Aliases of the command"` |
| 6 | + Description string `yaml:"description,omitempty" json:"description,omitempty" jsonschema_description:"Description of the command"` |
| 7 | + Group string `yaml:"group,omitempty" json:"group,omitempty" jsonschema_description:"Group of the command"` |
| 8 | + Hidden bool `yaml:"hidden,omitempty" json:"hidden,omitempty" jsonschema_description:"Hidden state of the command"` |
| 9 | + Parsing Parsing `yaml:"parsing,omitempty" json:"parsing,omitempty" jsonschema_description:"Flag parsing mode of the command" jsonschema:"enum=interspersed,enum=non-interspersed,enum=disabled"` |
| 10 | + |
| 11 | + Flags map[string]string `yaml:"flags,omitempty" json:"flags,omitempty" jsonschema_description:"Flags of the command with their description"` |
| 12 | + PersistentFlags map[string]string `yaml:"persistentflags,omitempty" json:"persistentflags,omitempty" jsonschema_description:"Persistent flags of the command with their description"` |
| 13 | + ExclusiveFlags [][]string `yaml:"exclusiveflags,omitempty" json:"exclusiveflags,omitempty" jsonschema_description:"Flags that are mutually exclusive"` |
| 14 | + Run string `yaml:"run,omitempty" json:"run,omitempty" jsonschema_description:"Command or script to execute in runnable mode"` |
| 15 | + Completion struct { |
| 16 | + Flag map[string][]string `yaml:"flag,omitempty" json:"flag,omitempty" jsonschema_description:"Flag completion"` |
| 17 | + Positional [][]string `yaml:"positional,omitempty" json:"positional,omitempty" jsonschema_description:"Positional completion"` |
| 18 | + PositionalAny []string `yaml:"positionalany,omitempty" json:"positionalany,omitempty" jsonschema_description:"Positional completion for every other position"` |
| 19 | + Dash [][]string `yaml:"dash,omitempty" json:"dash,omitempty" jsonschema_description:"Dash completion"` |
| 20 | + DashAny []string `yaml:"dashany,omitempty" json:"dashany,omitempty" jsonschema_description:"Dash completion of every other position"` |
| 21 | + } `yaml:"completion,omitempty" json:"completion,omitempty" jsonschema_description:"Completion definition"` |
| 22 | + Commands []Command `yaml:"commands,omitempty" json:"commands,omitempty" jsonschema_description:"Subcommands of the command"` |
| 23 | + |
| 24 | + Documentation struct { |
| 25 | + Command string `yaml:"command,omitempty" json:"command,omitempty" jsonschema_description:"Documentation of the command"` |
| 26 | + Flag map[string]string `yaml:"flag,omitempty" json:"flag,omitempty" jsonschema_description:"Documentation of flags"` |
| 27 | + Positional []string `yaml:"positional,omitempty" json:"positional,omitempty" jsonschema_description:"Documentation of positional arguments"` |
| 28 | + PositionalAny string `yaml:"positionalany,omitempty" json:"positionalany,omitempty" jsonschema_description:"Documentation of other positional arguments"` |
| 29 | + Dash []string `yaml:"dash,omitempty" json:"dash,omitempty" jsonschema_description:"Documentation of dash arguments"` |
| 30 | + DashAny string `yaml:"dashany,omitempty" json:"dashany,omitempty" jsonschema_description:"Documentation of other dash arguments"` |
| 31 | + } `yaml:"documentation,omitempty" json:"documentation,omitempty" jsonschema_description:"Documentation"` |
| 32 | + Examples map[string]string `yaml:"examples,omitempty" json:"examples,omitempty" jsonschema_description:"Examples"` |
| 33 | +} |
| 34 | + |
| 35 | +func (c *Command) AddFlag(f Flag) { |
| 36 | + switch { |
| 37 | + case f.Persistent: |
| 38 | + if c.PersistentFlags == nil { |
| 39 | + c.PersistentFlags = make(map[string]string) |
| 40 | + } |
| 41 | + c.PersistentFlags[f.format()] = f.Usage |
| 42 | + |
| 43 | + default: |
| 44 | + if c.Flags == nil { |
| 45 | + c.Flags = make(map[string]string) |
| 46 | + } |
| 47 | + c.Flags[f.format()] = f.Usage |
| 48 | + } |
| 49 | +} |
0 commit comments