Version: v0.0.0-...-d3fb95e Latest Latest

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

Go to latest
Published: Oct 4, 2018 License: Apache-2.0 Imports: 2 Imported by: 0




This section is empty.


View Source
var Dash = "-"

Dash -

View Source
var DashDash = "--"

DashDash --

View Source
var LongFlagPrefix = DashDash

LongFlagPrefix is the default prefix appended to multi-character flags in a command.

View Source
var ShortFlagPrefix = Dash

ShortFlagPrefix The default prefix applied to single-character flags in a command.


This section is empty.


type T

type T struct {
	// The prefix of the command.
	//   gitLog := commands.Cmd{First: []string{"git", "log"}}.Flag("short", true)
	First []string
	// Flags handles several different types when it comes to flag values:
	//   - nil: the flag will not be set.
	//   - string: the flag will be set to the string.
	//   - fmt.Stringer: the flag will be set to `value.String()`.
	//   - []string: the flag will be set once for each string in the slice. For
	//     example, {"add: []string{"etc", "usr", "opt"}} will be built into final
	//     arguments "--add", "etc", "--add", "usr", "--add", "opt"
	//   - bool: if the value is true, the flag is added without an argument.
	//   - any: flag will be added with the value printed using
	//     `fmt.Sprintf("%v", value)`
	Flags map[string]interface{}
	// Args are joined after all the flag options.
	Args []string
	// The prefix attatched to flags if the flags are longer than one character.
	// A nil pointer uses the default of "--".
	LongFlagPrefix *string
	// The prefix attatched to flags if the flags are one character long.
	// A nil pointer uses the default of "-".
	ShortFlagPrefix *string
	// A seperator between the last flag and the first arg.
	// A nil pointer omits the seperator.
	FlagsSeperator *string

command.T is a factory for creating *exec.Cmd structs. Create one manually, or use the builder function `New()`. Consider using the `T.Flag` and `T.Arg` methods to mutate your command, then use `T.Build()` to return an *exec.Cmd that's ready to run.

func New

func New(path string, more ...string) *T

Command returns a new *T with the given name and arguments.

func (*T) Arg

func (cmd *T) Arg(values ...string) *T

Arg adds all the given strings as positional arguments, and returns the Cmd.

func (*T) Build

func (cmd *T) Build() *exec.Cmd

Build an *exec.Cmd from this Cmd. This returns a new *exec.Cmd on each call, allowing you to use a Cmd as a factory.

func (*T) Flag

func (cmd *T) Flag(flag string, value interface{}) *T

Flag sets a flag to a value on this Cmd, and returns the Cmd.

func (*T) Join

func (cmd *T) Join(inner *T) *T

Join prepends this command to another command, mutating and returning the second command. This is useful for building multi-level commands.

TODO: copy instead of mutate?

func (*T) Slice

func (cmd *T) Slice() []string

Slice returns this command's arguments as a slice of strings.

func (*T) String

func (cmd *T) String() string

Source Files

Jump to

Keyboard shortcuts

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