cut

package module
v0.0.0-...-85cd551 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2016 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attach

func Attach(c Command, binders []Binder, cmds ...*cobra.Command) (cc *cobra.Command)

Attach command. If command implements Binder it will be also evaluated

func OverrideEnv

func OverrideEnv(flagSet *pflag.FlagSet, prefix string, flags ...string) (err error)

Override unchanged flags with values from environment

Types

type Binder

type Binder interface {
	Bind(cc *cobra.Command)
}

Binder can bound some options to cobra.

type Command

type Command interface{}

type Environment

type Environment struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	WD     string
}
Environment Binder may be used to automatic bound to OS streams

and working directory.

func run(args []string, stdin io.Reader, stdout, stderr io.Writer) {
	env := &Environment{
		Stdin:  stdin,
		Stdout: stdout,
		Stderr: stderr,
	}
	root := Attach(
		&RootCmd{}, []Binder{env},
			Attach(&MyCommand{Environment: env}, nil),
	)
	root.SetArgs(args)
	err = root.Execute()
}

func (*Environment) Bind

func (e *Environment) Bind(cc *cobra.Command)

type Runnable

type Runnable interface {

	// Run command with rest of args
	Run(args ...string) (err error)
}

Jump to

Keyboard shortcuts

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