cmd

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	EmptyCommand
	Arguments []string
	Options   []CommandOption
	Method    func(args []string, options map[string]string) error
}

func (*Command) Call

func (c *Command) Call(args ...string) error

type CommandFork

type CommandFork struct {
	EmptyCommand
	Commands []InternalCommand
}

func (*CommandFork) Call

func (c *CommandFork) Call(args ...string) error

type CommandOption

type CommandOption struct {
	Name        string
	Description string
	HasValue    bool
}

type EmptyCommand

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

func (*EmptyCommand) Call

func (c *EmptyCommand) Call(_ ...string) error

func (*EmptyCommand) Description

func (c *EmptyCommand) Description() string

func (*EmptyCommand) Name

func (c *EmptyCommand) Name() string

type ErrCommandNotFound

type ErrCommandNotFound struct {
	Name string
}

func NewErrCommandNotFound

func NewErrCommandNotFound(name string) *ErrCommandNotFound

func (*ErrCommandNotFound) Error

func (e *ErrCommandNotFound) Error() string

type ErrInvalidArguments

type ErrInvalidArguments struct {
	Expected string
}

func NewInvalidArgumentsError

func NewInvalidArgumentsError(expected string) *ErrInvalidArguments

func (*ErrInvalidArguments) Error

func (e *ErrInvalidArguments) Error() string

type InternalCommand

type InternalCommand interface {
	Name() string
	Description() string

	Call(args ...string) error
}
Example
b := NewCommand(
	"b", "b",
	nil, nil,
	func(args []string, options map[string]string) error {
		return nil
	},
)
a := NewCommandFork("a", "a", b)
root := NewCommandFork("root", "root", a)
fmt.Println(root.Call("a", "b"))
fmt.Println(root.Call("a"))
fmt.Println(root.Call("b"))
Output:

<nil>
command "" not found
command "b" not found

func NewCommand

func NewCommand(
	name, description string,
	arguments []string,
	options []CommandOption,
	method func(args []string, options map[string]string) error,
) InternalCommand

func NewCommandFork

func NewCommandFork(
	name, description string,
	subCommands ...InternalCommand,
) InternalCommand

Jump to

Keyboard shortcuts

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