mycmd

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 9 Imported by: 0

README

mycmd

Go library for building command line tools.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FullName

func FullName(c Command) []string

// FullName returns full name of command (rootName subName subName ...)

Types

type Base

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

func NewBase

func NewBase(name string, cfg Config) *Base

func (*Base) ErrWriter

func (c *Base) ErrWriter() io.Writer

OutWriter returns the error output writer.

func (Base) Execute

func (c Base) Execute() int

Execute executes the main processing of the command.

func (Base) ExecuteContext

func (c Base) ExecuteContext(ctx context.Context) int

ExecuteContext is the same as Execute() but accept a context as an argument.

func (Base) FS

func (c Base) FS() *wflag.FlagSet

FS returns FlagSet

func (*Base) Hidden

func (c *Base) Hidden() bool

If Hidden is true, this command will not be displayed in Usage.

func (Base) IsHelpRequested

func (c Base) IsHelpRequested(err error) bool

IsHelpRequested will return true when the help was requested in Parse.

func (Base) Name

func (c Base) Name() string

func (*Base) OutWriter

func (c *Base) OutWriter() io.Writer

OutWriter returns the standard output writer.

func (*Base) Parent

func (c *Base) Parent() Command

func (Base) Parse

func (c Base) Parse(args []string) error

Parse parses the flags

func (*Base) PrintError

func (c *Base) PrintError(msg string)

func (*Base) SetErrWriter

func (c *Base) SetErrWriter(w io.Writer)

func (*Base) SetOutWriter

func (c *Base) SetOutWriter(w io.Writer)

func (*Base) SetParent

func (c *Base) SetParent(parent Command)

func (Base) ShortDescription

func (c Base) ShortDescription() string

func (*Base) Usage

func (c *Base) Usage() string

type Command

type Command interface {
	Name() string
	ShortDescription() string
	Usage() string
	Parse(args []string) error
	IsHelpRequested(err error) bool
	Execute() int
	ExecuteContext(ctx context.Context) int
	SetOutWriter(w io.Writer)
	SetErrWriter(w io.Writer)
}

type Config

type Config struct {
	ShortDescription string
	ShortUsage       string
	Hidden           bool
}

type Help

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

func NewHelp

func NewHelp(root ParentCommand) *Help

func (*Help) Execute

func (c *Help) Execute() int

func (*Help) ExecuteContext

func (c *Help) ExecuteContext(ctx context.Context) int

func (*Help) IsHelpRequested

func (c *Help) IsHelpRequested(err error) bool

func (*Help) Name

func (c *Help) Name() string

func (*Help) Parent

func (c *Help) Parent() Command

func (*Help) Parse

func (c *Help) Parse(args []string) error

func (*Help) SetErrWriter

func (c *Help) SetErrWriter(w io.Writer)

func (*Help) SetOutWriter

func (c *Help) SetOutWriter(w io.Writer)

func (*Help) SetParent

func (c *Help) SetParent(parent Command)

func (*Help) ShortDescription

func (c *Help) ShortDescription() string

func (*Help) Usage

func (c *Help) Usage() string

type HelpSupported

type HelpSupported interface {
	FullHelpCommandName() string
}

type HiddenSupported

type HiddenSupported interface {
	Hidden() bool
}

type ParentBase

type ParentBase struct {
	*Base
	// contains filtered or unexported fields
}

func NewParentBase

func NewParentBase(name string, cfg Config) *ParentBase

func (*ParentBase) AddCommands

func (c *ParentBase) AddCommands(commands ...Command) *ParentBase

AddCommands add subcommands

func (*ParentBase) Commands

func (c *ParentBase) Commands() []Command

Commands returns subcommands.

func (*ParentBase) Execute

func (c *ParentBase) Execute() int

Execute executes the main processing of the command.

func (*ParentBase) ExecuteContext

func (c *ParentBase) ExecuteContext(ctx context.Context) int

ExecuteContext is the same as Execute() but accept a context as an argument.

func (*ParentBase) FullHelpCommandName

func (c *ParentBase) FullHelpCommandName() string

FullHelpCommandName returns full name of help command (rootName helpName subName)

func (*ParentBase) Parse

func (c *ParentBase) Parse(args []string) error

Parse parses the flags

func (*ParentBase) SetErrWriter

func (c *ParentBase) SetErrWriter(w io.Writer)

func (*ParentBase) SetOutWriter

func (c *ParentBase) SetOutWriter(w io.Writer)

func (*ParentBase) Usage

func (c *ParentBase) Usage() string

type ParentCommand

type ParentCommand interface {
	Command
	Commands() []Command
}

type Root

type Root struct {
	*ParentBase
}

func NewRoot

func NewRoot(name string) *Root

func (*Root) AddCommands

func (c *Root) AddCommands(commands ...Command) *Root

func (*Root) ParseAndExecute

func (c *Root) ParseAndExecute(args []string) int

ParseAndExecute parses and executes command.

type SubCommand

type SubCommand interface {
	Command
	Parent() Command
	SetParent(parent Command)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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