commands

package
v0.0.0-...-7f36856 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HelpOption = Option{
		Name:            "--help",
		Shortcut:        "-h",
		AcceptValue:     false,
		IsValueRequired: false,
		IsMultiple:      false,
		Description:     "Display this help message",
		Default:         Any{false},
		Hidden:          false,
	}
	VerboseOption = Option{
		Name:            "--verbose",
		Shortcut:        "-v|vv|vvv",
		AcceptValue:     false,
		IsValueRequired: false,
		IsMultiple:      false,
		Description:     "Increase the verbosity of messages",
		Default:         Any{false},
		Hidden:          false,
	}
	VersionOption = Option{
		Name:            "--version",
		Shortcut:        "-V",
		AcceptValue:     false,
		IsValueRequired: false,
		IsMultiple:      false,
		Description:     "Display this application version",
		Default:         Any{false},
		Hidden:          false,
	}
	YesOption = Option{
		Name:            "--yes",
		Shortcut:        "-y",
		AcceptValue:     false,
		IsValueRequired: false,
		IsMultiple:      false,
		Description: "Answer \"yes\" to confirmation questions; " +
			"accept the default value for other questions; disable interaction",
		Default: Any{false},
		Hidden:  false,
	}
	AnsiOption = Option{
		Name:            "--ansi",
		Shortcut:        "",
		AcceptValue:     false,
		IsValueRequired: false,
		IsMultiple:      false,
		Description:     "Force ANSI output",
		Default:         Any{false},
		Hidden:          true,
	}
	NoAnsiOption = Option{
		Name:            "--no-ansi",
		Shortcut:        "",
		AcceptValue:     false,
		IsValueRequired: false,
		IsMultiple:      false,
		Description:     "Disable ANSI output",
		Default:         Any{false},
		Hidden:          true,
	}
	NoOption = Option{
		Name:            "--no",
		Shortcut:        "-n",
		AcceptValue:     false,
		IsValueRequired: false,
		IsMultiple:      false,
		Description: "Answer \"no\" to confirmation questions; " +
			"accept the default value for other questions; disable interaction",
		Default: Any{false},
		Hidden:  true,
	}
	QuietOption = Option{
		Name:            "--quiet",
		Shortcut:        "-q",
		AcceptValue:     false,
		IsValueRequired: false,
		IsMultiple:      false,
		Description:     "Do not output any message",
		Default:         Any{false},
		Hidden:          true,
	}
)

Functions

func Execute

func Execute(cnf *config.Config) error

Execute is the main entrypoint to run the CLI.

Types

type Any

type Any struct {
	// contains filtered or unexported fields
}

func (Any) MarshalJSON

func (a Any) MarshalJSON() ([]byte, error)

func (*Any) String

func (a *Any) String() string

func (*Any) UnmarshalJSON

func (a *Any) UnmarshalJSON(text []byte) error

type Application

type Application struct {
	Name       string `json:"name"`
	Version    string `json:"version"`
	Executable string `json:"executable"`
}

type Argument

type Argument struct {
	Name        string      `json:"name"`
	IsRequired  YesNo       `json:"is_required"`
	IsArray     YesNo       `json:"is_array"`
	Description CleanString `json:"description"`
	Default     Any         `json:"default"`
}

type CleanString

type CleanString string

func (*CleanString) MarshalJSON

func (s *CleanString) MarshalJSON() ([]byte, error)

func (CleanString) String

func (s CleanString) String() string

func (*CleanString) UnmarshalJSON

func (s *CleanString) UnmarshalJSON(text []byte) error

type Command

type Command struct {
	Name        CommandName `json:"name"`
	Usage       []string    `json:"usage"`
	Aliases     []string    `json:"aliases"`
	Description CleanString `json:"description"`
	Help        CleanString `json:"help"`
	Examples    []Example   `json:"examples"`
	Definition  Definition  `json:"definition"`
	Hidden      bool        `json:"hidden"`
}

func (*Command) HelpPage

func (c *Command) HelpPage(cnf *config.Config) string

type CommandName

type CommandName struct {
	Namespace string
	Command   string
}

func (*CommandName) ContainsNamespace

func (n *CommandName) ContainsNamespace() bool

func (*CommandName) MarshalJSON

func (n *CommandName) MarshalJSON() ([]byte, error)

func (*CommandName) String

func (n *CommandName) String() string

func (*CommandName) UnmarshalJSON

func (n *CommandName) UnmarshalJSON(text []byte) error

type Definition

type Definition struct {
	Arguments *orderedmap.OrderedMap[string, Argument] `json:"arguments"`
	Options   *orderedmap.OrderedMap[string, Option]   `json:"options"`
}

type Example

type Example struct {
	Commandline string      `json:"commandline"`
	Description CleanString `json:"description"`
}

type Formatter

type Formatter interface {
	Format(*List, *config.Config) ([]byte, error)
}

type JSONListFormatter

type JSONListFormatter struct{}

func (*JSONListFormatter) Format

func (f *JSONListFormatter) Format(list *List, _ *config.Config) ([]byte, error)

type List

type List struct {
	Application Application `json:"application"`
	Commands    []*Command  `json:"commands"`
	Namespace   string      `json:"namespace,omitempty"`
	Namespaces  []Namespace `json:"namespaces,omitempty"`
}

func (*List) AddCommand

func (l *List) AddCommand(cmd *Command)

func (*List) DescribesNamespace

func (l *List) DescribesNamespace() bool

type MDListFormatter

type MDListFormatter struct{}

func (*MDListFormatter) Format

func (f *MDListFormatter) Format(list *List, cnf *config.Config) ([]byte, error)

type Namespace

type Namespace struct {
	ID       string   `json:"id"`
	Commands []string `json:"commands"` // the same as Command.Name
}

type Option

type Option struct {
	Name            string      `json:"name"`
	Shortcut        string      `json:"shortcut"`
	AcceptValue     YesNo       `json:"accept_value"`
	IsValueRequired YesNo       `json:"is_value_required"`
	IsMultiple      YesNo       `json:"is_multiple"`
	Description     CleanString `json:"description"`
	Default         Any         `json:"default"`
	Hidden          bool        `json:"hidden"`
}

func NoInteractionOption

func NoInteractionOption(cnf *config.Config) Option

func (*Option) GetName

func (o *Option) GetName() string

type RawListFormatter

type RawListFormatter struct{}

func (*RawListFormatter) Format

func (f *RawListFormatter) Format(list *List, _ *config.Config) ([]byte, error)

type TXTListFormatter

type TXTListFormatter struct{}

func (*TXTListFormatter) Format

func (f *TXTListFormatter) Format(list *List, cnf *config.Config) ([]byte, error)

type YesNo

type YesNo bool

func (YesNo) String

func (y YesNo) String() string

Jump to

Keyboard shortcuts

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