cmd

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2020 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Example = CMD{
	Name:  "example",
	Alias: "ex",
	Short: "Example command for testing",
	Flags: &ExampleFlags{},
	Args:  &ExampleArgs{},
	Run:   ExampleRun,
}

Example fulfills the "example" subcommand

View Source
var GenManPages = CMD{
	Name:   "gen-man-pages",
	Alias:  "gmp",
	Short:  "Generate man-pages for the root command and each sub-command",
	Args:   &GenManPagesArgs{},
	Run:    GenManPagesRun,
	Hidden: true,
}

GenManPages fulfills the "gen-man-pages" subcommand

View Source
var Help = CMD{
	Name:  "help",
	Alias: "?",
	Short: "Get help with a specific subcommand",
	Args:  &HelpArgs{},
	Run:   HelpRun,
}

Help fulfills the "help" subcommand

View Source
var Hidden = CMD{
	Name:   "hidden",
	Alias:  "hi",
	Short:  "Hidden command for testing",
	Hidden: true,
	Args:   &HiddenArgs{},
	Run:    HiddenRun,
}

Hidden fulfills the "hidden" subcommand

Functions

func ExampleRun added in v1.1.0

func ExampleRun(r *RootCMD, c *CMD)

ExampleRun prints the usage for the requested command

func GenFlags added in v1.1.0

func GenFlags(man io.Writer, v interface{}) error

GenFlags prints out Flag structs in man-page format

func GenManPagesRun added in v1.1.0

func GenManPagesRun(r *RootCMD, c *CMD)

GenManPagesRun prints the usage for the requested command

func GenerateRootPage added in v1.1.0

func GenerateRootPage(r *RootCMD) error

GenerateRootPage generates a man-page for the root command

func GenerateSubPage added in v1.1.0

func GenerateSubPage(r *RootCMD, name string) error

GenerateSubPage generates a man-page for a single subcommand

func GenerateSubPages added in v1.1.0

func GenerateSubPages(r *RootCMD) error

GenerateSubPages generates a man-page for every subcommand

func HelpRun

func HelpRun(r *RootCMD, c *CMD)

HelpRun prints the usage for the requested command

func HiddenRun added in v1.1.0

func HiddenRun(r *RootCMD, c *CMD)

HiddenRun prints the usage for the requested command

func PrintFlags

func PrintFlags(flags interface{})

PrintFlags writes out the flags in a struct

func Usage

func Usage(r *RootCMD, c *CMD)

Usage prints a general usage statement

Types

type CMD

type CMD struct {
	Name   string
	Alias  string
	Short  string
	Hidden bool
	Args   interface{}
	Flags  interface{}
	Run    func(r *RootCMD, c *CMD)
}

CMD is a type for all commands

type ExampleArgs added in v1.1.0

type ExampleArgs struct {
	Args []string `desc:"Slice o' Args"`
}

ExampleArgs contains the arguments for the "example" subcommand

type ExampleFlags added in v1.1.0

type ExampleFlags struct {
	Boop bool `short:"b" long:"boop" desc:"You saw nothing"`
}

ExampleFlags contains the additional flags for the "example" subcommand

type GenManPagesArgs added in v1.1.0

type GenManPagesArgs struct{}

GenManPagesArgs contains the arguments for the "gen-man-pages" subcommand

type HelpArgs

type HelpArgs struct {
	Subcommand string `desc:"Command to get help for"`
}

HelpArgs contains the arguments for the "help" subcommand

type HiddenArgs added in v1.1.0

type HiddenArgs struct{}

HiddenArgs contains the arguments for the "hidden" subcommand

type RootCMD

type RootCMD struct {
	Name        string
	Short       string
	Subcommands map[string]*CMD
	Aliases     map[string]string
	Flags       interface{}
}

RootCMD is the main command that runs everything

func (*RootCMD) RegisterCMD

func (r *RootCMD) RegisterCMD(c *CMD)

RegisterCMD add a sub-command to this program

func (*RootCMD) Run

func (r *RootCMD) Run()

Run finds the appropriate CMD and executes it, or prints the global Usage

func (*RootCMD) Usage

func (r *RootCMD) Usage()

Usage prints the usage for this program

Jump to

Keyboard shortcuts

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