schema

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2025 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

type Argument struct {
	// Name of the argument, which must match the regular expression `^[a-z][a-z0-9]*$` and be unique in arguments of the command which the argument belongs to.
	// This property is required.
	Name string `json:"name,omitempty" yaml:"name,omitempty"`

	// Description of the argument.
	// The default value is an empty string.
	Description string `json:"description,omitempty" yaml:"description,omitempty"`

	// Type of the value that is assignable to the argument.
	// The default value is "string".
	Type Type `json:"type,omitempty" yaml:"type,omitempty"`

	// Whether the argument is variadic (i.e. can have zero or more values).
	// It can be true only if this argument is the last argument in the arguments of the belonging command.
	// The default value is false.
	Variadic bool `json:"variadic,omitempty" yaml:"variadic,omitempty"`
}

Argument represents a positional required argument in command line arguments.

type Command

type Command struct {
	// Description of the command.
	// The default value is an empty string.
	Description string `json:"description,omitempty" yaml:"description,omitempty"`

	// A collection of options, which is a mapping from option names to options.
	// The default value is an empty object.
	// A property name is a name of an option, which must match the regular expression `^(-[a-z][a-z0-9]*)+$` and be unique in options of the command.
	Options map[string]Option `json:"options,omitempty" yaml:"options,omitempty"`

	// A list of arguments.
	// The default value is an empty array.
	Arguments []Argument `json:"arguments,omitempty" yaml:"arguments,omitempty"`

	// A collection of subcommands, which is a mapping from subcommand names to child commands.
	// The default value is an empty object.
	// A property name is a name of a subcommand, which must match the regular expression `^[a-z][a-z0-9]*$` and be unique in subcommands of the command.
	Subcommands map[string]Command `json:"subcommands,omitempty" yaml:"subcommands,omitempty"`
}

Command represents a root command or a subcommand of the program. It may have options, arguments, and subcommands recursively.

func (Command) Walk

func (cmd Command) Walk(path []string, f func(cmd Command, path []string) error) error

type Option

type Option struct {
	// Short name of the option, which must match the regular expression `^-[a-z]$` and be unique in options of the command which the option belongs to.
	// If short is not specified then short name for this option is not available.
	Short string `json:"short,omitempty" yaml:"short,omitempty"`

	// Description of the option.
	// The default value is an empty string.
	Description string `json:"description,omitempty" yaml:"description,omitempty"`

	// Type of the value that is assignable to this option.
	// The default value is "string".
	Type Type `json:"type,omitempty" yaml:"type,omitempty"`

	// Whether the option of typed boolean has a negated version.
	// If true then the option can be specified with a negation prefix `-no` in the command line arguments.
	// The default value is false.
	Negation bool `json:"negation,omitempty" yaml:"negation,omitempty"`

	// String value representing the default value of the option.
	// It must be a string that can be parsed as a value of the option type.
	// If not specified, the following values corresponding to the option type.
	// - boolean: "false"
	// - string: ""
	// - integer: "0"
	Default string `json:"default,omitempty" yaml:"default,omitempty"`

	// Whether the option can be specified multiple times.
	// If true then the option can be specified multiple times in the command line arguments.
	// The default value is false.
	Repeated bool `json:"repeated,omitempty" yaml:"repeated,omitempty"`

	// Whether the option propagates to subcommands.
	// If true then the option is available in all subcommands of the command which the option belongs to.
	// The default value is false.
	Propagates bool `json:"propagates,omitempty" yaml:"propagates,omitempty"`
}

Option represents an optional argument in command line arguments.

type PathCommand

type PathCommand struct {
	Path    []string
	Command Command
}

type Program

type Program struct {
	// Name of the program.
	// The default value is an empty string.
	Name string `json:"name,omitempty" yaml:"name,omitempty"`

	// Version of the program.
	// The default value is an empty string.
	Version string `json:"version,omitempty" yaml:"version,omitempty"`

	// Embedded Command fields
	Command `yaml:",inline"`
}

Program is a root command that may have a name and a version. It consists of commands recursively.

type Schema

type Schema struct {
	Program Program
	// contains filtered or unexported fields
}

func Load

func Load(reader io.Reader) (Schema, error)

Load loads a CLI schema from a JSON data.

func (Schema) ListCommand

func (s Schema) ListCommand() (commands []PathCommand)

func (Schema) PropagateOptions

func (s Schema) PropagateOptions() Schema

PropagateOptions creates a deep copy of the Schema.

func (Schema) Validate

func (s Schema) Validate() error

type Type

type Type string

Type represents a type of a value that can be assigned to an option or an argument. One of "string", "integer", or "boolean" is available.

const (
	TypeEmpty   Type = ""
	TypeString  Type = "string"
	TypeInteger Type = "integer"
	TypeBoolean Type = "boolean"
)

Jump to

Keyboard shortcuts

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