cmd

package module
v0.0.0-...-7abcd66 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2018 License: MIT Imports: 9 Imported by: 3

README

cmd

helper lib for creating cmdline tools

Why?

I've been build a few cmdline tools lately using the same base structure underneath, and copying changes back and forth between projects so I decided to turn it into a little helper library.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Err = log.New(os.Stderr, "", 0)
View Source
var ErrParseArgs = errors.New("could not parse arguments")
View Source
var Out = log.New(os.Stdout, "", 0)

Functions

This section is empty.

Types

type Command

type Command interface {
	Name() string
	Args() string
	Desc() string
	Help() string
	Register(*flag.FlagSet)
	Run(Context, []string) error
}

type Context

type Context interface {
	WorkingDir() string
}

type Environment

type Environment struct {
	WorkingDir string
	Args       []string
	Env        []string
	// contains filtered or unexported fields
}

func (*Environment) GetDefaultContext

func (e *Environment) GetDefaultContext() Context

func (*Environment) GetStdio

func (e *Environment) GetStdio() (io.Writer, io.Writer)

type ErrNoDefaultCommand

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

ErrNoDefaultCommand is returned when the default command is called but no command is provided to handle it.

func (*ErrNoDefaultCommand) Error

func (e *ErrNoDefaultCommand) Error() string

Error implements the error interface

type ErrNoSuchCommand

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

ErrNoSuchCommand is returned when the requested command is not found

func (*ErrNoSuchCommand) Error

func (e *ErrNoSuchCommand) Error() string

Error implements the error interface

type Program

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

func NewProgram

func NewProgram(name string, desc string, root Command, cmds []Command) (*Program, error)

func (*Program) Run

func (p *Program) Run(args []string, fn func(*Environment, Command, []string) error) error

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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