cmd

package
v0.0.0-...-00a1a7c Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2021 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Provides command handlers for the "blank" program.

Index

Constants

View Source
const (
	BlankCommandName = "blank"
)
View Source
const FlagLineFormat = "  %-13s  %s\n"

The fmt string used by WriteFlagUsage.

View Source
const HelpCommandName = "help"
View Source
const MakeCommandName = "make"
View Source
const UpdateCommandName = "update"

Variables

View Source
var Blank = &BlankCommand{
	&Info{
		Line: "%s [options] [command [command_options]...]",
		Desc: "Program to generate blank dev projects.",
	},

	[]*Flag{
		{Name: "-a", Desc: fmt.Sprintf("append `path` to %s", vBLANK_PATH)},
		{Name: "-P", Desc: fmt.Sprintf("set `paths` as %s", vBLANK_PATH)},
	},

	[]Command{
		Make,
		Update,
		Help,
	},
}

The default "blank" command instance.

View Source
var Help = &HelpCommand{
	info: &Info{
		Line: "%s [command]",
		Desc: "Show help screen.",
	},
}

The default "help" subcommand instance.

View Source
var Make = &MakeCommand{
	info: &Info{
		Line: "%s [options] [target] ...",
		Desc: "Generate blank dev projects using makefiles.",
	},
}

The default "make" subcommand instance.

View Source
var Update = &UpdateCommand{
	info: &Info{
		Line: "%s [options] target [operation [path] json]...",
		Desc: "Update/patch config files.",
	},

	flags: []*Flag{
		{
			Name: "-i, --in",
			Desc: fmt.Sprintf("read target as `t` (%s)", fileTypesStr),
		},
		{
			Name: "-o, --out",
			Desc: fmt.Sprintf("output as `t` (%s)", fileTypesStr),
		},
	},

	ops: []*Flag{
		{Name: "-s", Desc: "set new values only"},
		{Name: "-m", Desc: "merge values"},
		{Name: "-a", Desc: `concatenate array values (implies "-m")`},
	},
}

The default "update" subcommand instance.

Functions

func Main

func Main(args []string)

Run the main "blank" program.

func RunWithHelp

func RunWithHelp(c Command, args []string, p ...string)

Run command c, intercepting first -h or --help argument.

func UnquoteUsage

func UnquoteUsage(desc string) (name string, usage string)

Extracts a back-quoted name from the usage string for a flag and returns it and the un-quoted usage.

Given "a `name` to show" it returns ("name", "a name to show"). If there are no back quotes, the name is an educated guess of the type of the flag's value, or the empty string if the flag is boolean.

func WriteCommandUsage

func WriteCommandUsage(w io.Writer, c Command, p ...string)

Write program help screen.

The p argument is this command's parents' names, if any.

func WriteFlagUsage

func WriteFlagUsage(w io.Writer, f *Flag)

Write a flag's usage line.

Types

type BlankCommand

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

The main "blank" command type.

func (*BlankCommand) Flags

func (c *BlankCommand) Flags() []*Flag

func (*BlankCommand) Help

func (c *BlankCommand) Help() string

Returns a help screen containing a list of sub-commands and environment variables.

func (*BlankCommand) Info

func (c *BlankCommand) Info() *Info

func (*BlankCommand) Name

func (c *BlankCommand) Name() string

func (*BlankCommand) Run

func (c *BlankCommand) Run(args []string) error

type Command

type Command interface {
	Named
	Informative
	Runnable
	Flagged
}

A command.

type Flag

type Flag struct {
	Name string // The flag names
	Desc string // The flag description.
}

Encapsulates only "informational" details about a flag. Used by WriteFlagUsage and WriteCommandUsage to display the help screen.

type Flagged

type Flagged interface {
	Flags() []*Flag
}

Provides the Flags method, for commands to provide a list of command-line flags.

type HelpCommand

type HelpCommand struct {
	NoFlags
	NoHelp
	// contains filtered or unexported fields
}

The "help" subcommand type.

func (*HelpCommand) Info

func (c *HelpCommand) Info() *Info

func (*HelpCommand) Name

func (c *HelpCommand) Name() string

func (*HelpCommand) Run

func (c *HelpCommand) Run(args []string) error

type Info

type Info struct {
	Line string
	Desc string
}

A command's usage and short description.

type Informative

type Informative interface {
	Info() *Info
	Help() string // Returns longer help message
}

Provides the Info and Help methods, for commands to provide detailed info in the help screen.

type MakeCommand

type MakeCommand struct {
	NoFlags
	// contains filtered or unexported fields
}

The "make" subcommand type.

func (*MakeCommand) Help

func (c *MakeCommand) Help() string

func (*MakeCommand) Info

func (c *MakeCommand) Info() *Info

func (*MakeCommand) Name

func (c *MakeCommand) Name() string

func (*MakeCommand) Run

func (c *MakeCommand) Run(args []string) error

type Named

type Named interface {
	Name() string
}

A uniquely named command.

type NoFlags

type NoFlags struct{}

Embedable struct that implements an empty "Flags" method.

func (*NoFlags) Flags

func (n *NoFlags) Flags() []*Flag

type NoHelp

type NoHelp struct{}

Embeddable struct that implements an empty "Help" method.

func (*NoHelp) Help

func (n *NoHelp) Help() string

type Runnable

type Runnable interface {
	Run([]string) error
}

Provides the Run method, for commands to implement their run function.

type UpdateCommand

type UpdateCommand struct {
	NoHelp
	// contains filtered or unexported fields
}

The "update" subcommand type.

func (*UpdateCommand) Flags

func (c *UpdateCommand) Flags() []*Flag

func (*UpdateCommand) Help

func (c *UpdateCommand) Help() string

func (*UpdateCommand) Info

func (c *UpdateCommand) Info() *Info

func (*UpdateCommand) Name

func (c *UpdateCommand) Name() string

func (*UpdateCommand) Run

func (c *UpdateCommand) Run(args []string) error

Jump to

Keyboard shortcuts

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