oclispec

package
v0.0.0-...-a36ccc7 Latest Latest
Warning

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

Go to latest
Published: May 25, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustValidateDocumentJSON

func MustValidateDocumentJSON(document []byte)

MustValidateDocumentJSON is a wrapper of ValidateDocumentJSON that panics if the document is invalid.

func MustValidateDocumentYAML

func MustValidateDocumentYAML(document []byte)

MustValidateDocumentYAML is a wrapper of ValidateDocumentYAML that panics if the document is invalid.

func ValidateDocumentJSON

func ValidateDocumentJSON(document []byte) error

ValidateDocumentJSON validates the given JSON document against the OpenCLI Specification. Any validation errors are returned. If no error is returned, the document is valid.

func ValidateDocumentYAML

func ValidateDocumentYAML(document []byte) error

ValidateDocumentYAML validates the given YAML document against the OpenCLI Specification. Any validation errors are returned. If no error is returned, the document is valid.

func Versions

func Versions() []string

Versions returns a list of supported OpenCLI Specification versions.

Types

type AlternativeSource

type AlternativeSource struct {
	Type                string
	EnvironmentVariable string
	File                FileSource
}

type Argument

type Argument struct {
	Name        string
	Summary     string
	Description string
	Type        string
	Variadic    bool
	Choices     []Choice
	Required    bool
	Default     DefaultValue
}

Argument represents an OpenCLI command argument.

type Choice

type Choice struct {
	Value       string
	Description string
}

type Command

type Command struct {
	Line                 string // The full command line as defined in the OpenCLI Spec Document
	Name                 string // The command part of the command line
	LeafName             string // The final command in the command line
	Params               string // The args/flags part of the command line
	Aliases              []string
	Summary              string
	Description          string
	Arguments            []Argument
	Flags                []Flag
	Hidden               bool
	Group                bool
	CmdSpecificExitCodes []ExitCode
	ExitCodes            []ExitCode
}

Command represents n OpenCLI command.

func (Command) BadUserInputErrorCode

func (cmd Command) BadUserInputErrorCode() int

func (Command) CanceledErrorCode

func (cmd Command) CanceledErrorCode() int

func (Command) FixedEnumeratedArgs

func (cmd Command) FixedEnumeratedArgs() bool

EnumeratedArgs returns true if any fixed arguments on the command contain enumerated values.

func (Command) FixedEnumeratedFlags

func (cmd Command) FixedEnumeratedFlags() bool

EnumeratedFlags returns true if any fixed type flags on the command contain enumerated values.

func (Command) InternalCliErrorCode

func (cmd Command) InternalCliErrorCode() int

func (Command) NotImplementedCode

func (cmd Command) NotImplementedCode() int

func (Command) UnauthenticatedErrorCode

func (cmd Command) UnauthenticatedErrorCode() int

func (Command) UnauthorizedErrorCode

func (cmd Command) UnauthorizedErrorCode() int

func (Command) VariadicEnumeratedArgs

func (cmd Command) VariadicEnumeratedArgs() bool

EnumeratedArgs returns true if any variadic arguments on the command contain enumerated values.

func (Command) VariadicEnumeratedFlags

func (cmd Command) VariadicEnumeratedFlags() bool

EnumeratedFlags returns true if any variadic type flags on the command contain enumerated values.

func (Command) VisibleFlags

func (cmd Command) VisibleFlags() bool

NonHiddenFlags returns true if there are any flags for the given command where Hidden isfalse.

type CommandTrie

type CommandTrie struct {
	Root *CommandTrieNode
	// contains filtered or unexported fields
}

CommandTrie is a data structure similar to a [Trie](https://en.wikipedia.org/wiki/Trie). Instead of each node containing letters in a string, it contains a command in the command line. This allows us to ensure that grouping commands that may not otherwise be defined in the OpenCLI Doc are accounted for. Grouping commands are commands that are not executable and exist only as an internal node in the trie (not a leaf).

func (*CommandTrie) Insert

func (t *CommandTrie) Insert(cmdLine string, cmd oclifile.Command)

type CommandTrieNode

type CommandTrieNode struct {
	Name     string
	Command  Command
	Commands []*CommandTrieNode
}

CommandTrieNode represents a hierarchical view of the CLI command structure.

type ConfigFile

type ConfigFile struct {
	Format string
	Path   string
}

type Contact

type Contact struct {
	Name  string
	Email string
	URL   string
}

Contact represents contact information for maintainers of the CLI described by the OpenCLI document.

type DefaultValue

type DefaultValue struct {
	IsSet  bool
	Bool   bool
	String string
}

type Document

type Document struct {
	OpenCLIVersion string
	Info           Info
	Install        []Install
	Global         Global
	CommandTrie    *CommandTrie
}

Document represents the OpenCLI document.

func UnmarshalJSON

func UnmarshalJSON(path string) (Document, error)

UnmarshalJSON ummarshalls the given JSON file into an Document domain object.

func UnmarshalYAML

func UnmarshalYAML(path string) (Document, error)

UnmarshalYAML ummarshalls the given YAML file into an Document domain object.

func (Document) AltSourcesEnv

func (d Document) AltSourcesEnv() bool

func (Document) AltSourcesJSON

func (d Document) AltSourcesJSON() bool

func (Document) AltSourcesTOML

func (d Document) AltSourcesTOML() bool

func (Document) AltSourcesYAML

func (d Document) AltSourcesYAML() bool

func (Document) Arguments

func (d Document) Arguments() bool

Arguments returns true if any of the commands have arguments.

func (Document) BadUserInputErrorCode

func (d Document) BadUserInputErrorCode() int

func (Document) FixedEnumeratedArgs

func (d Document) FixedEnumeratedArgs() bool

EnumeratedArgs returns true if any fixed arguments on any commands contain enumerated values.

func (Document) FixedEnumeratedFlags

func (d Document) FixedEnumeratedFlags() bool

EnumeratedFlags returns true if any fixed type flags on any commands contain enumerated values.

func (Document) Flags

func (d Document) Flags() bool

Flags returns true if any of the commands have flags.

func (Document) InternalCliErrorCode

func (d Document) InternalCliErrorCode() int

func (Document) VariadicEnumeratedArgs

func (d Document) VariadicEnumeratedArgs() bool

EnumeratedArgs returns true if any variadic arguments on any commands contain enumerated values.

func (Document) VariadicEnumeratedFlags

func (d Document) VariadicEnumeratedFlags() bool

EnumeratedFlags returns true if any variadic type flags on any commands contain enumerated values.

func (Document) VisibleFlags

func (d Document) VisibleFlags() bool

VisibleFlags returns true if any of the commands have visible flags.

type ExitCode

type ExitCode struct {
	Code        int
	Status      string
	Summary     string
	Description string
}

ExitCode represents a possible exit code of a CLI command

type FileSource

type FileSource struct {
	Name     string
	Path     string
	Format   string
	Property string
}

type Flag

type Flag struct {
	Name        string
	Aliases     []string
	Hint        string
	Summary     string
	Description string
	Type        string
	Variadic    bool
	Choices     []Choice
	Hidden      bool
	Required    bool
	Default     DefaultValue
	AltSources  []AlternativeSource
}

Flag represents an OpenCLI command flag.

type Global

type Global struct {
	ExitCodes   []ExitCode
	Flags       []Flag
	ConfigFiles map[string]ConfigFile
}

Global contains information that applies to the CLI regardless of command context.

type Info

type Info struct {
	Title       string
	Summary     string
	Description string
	License     License
	Contact     Contact
	Binary      string
	Version     string
}

Info represents the metadata about the CLI described by the OpenCLI document.

type Install

type Install struct {
	Name        string
	Command     string
	URL         string
	Description string
}

Install represents information about ways a user can install the CLI.

type License

type License struct {
	Name   string
	SpdxID string
	URL    string
}

License represents the license information for the CLI described by the OpenCLI document.

Jump to

Keyboard shortcuts

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