cli

package
v0.0.0-...-785fa05 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2018 License: MIT Imports: 8 Imported by: 0

README

cli package notes

Example usage

For a minimal usage example see the following file set:

Run the example

cd $GOPATH/src/github.com/gigawattio/go-commons/pkg/web/cli/example
go run example.go

Output:

Successfully started web service on addr=127.0.0.1:8080
^C
Interrupt signal detected, shutting down..

Additional notes

A few variables in the package gopkg.in/urface/cli.v2 do get temporarily overridden during the invocation of Cli.Main() until the function is done running. The overrides are:

  • cliv2.OsExiter is temporarily set to a NOP function.
  • cliv2.ErrWriter is temporarily set to the value of Cli.App.ErrWriter.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultBindAddr    = "127.0.0.1:8080"
	DefaultServiceUser = os.Getenv("USER")
)
View Source
var (
	AppNameRequiredError            = errors.New("AppName must not be empty")
	WebServiceProviderRequiredError = errors.New("WebServiceProvider must not be nil")
	NilWebServiceError              = errors.New("WebServiceProvider produced a nil WebService without any error")
)

Functions

func ErrorExit

func ErrorExit(w io.Writer, err error, statusCode int)

Types

type Cli

type Cli struct {
	App                *cliv2.App
	WebServiceProvider interfaces.WebServiceProvider
	Args               []string
	Install            bool   // NB: Flag variable.
	Uninstall          bool   // NB: Flag variable.
	ServiceUser        string // NB: Flag variable.
	BindAddr           string // NB: Flag variable.
	ExitOnError        bool   // true triggers os.exit upon error from Main().
	// contains filtered or unexported fields
}

Cli provides a command-line-interface in-a-box for web-services.

func New

func New(options Options) (*Cli, error)

func (*Cli) DefaultAction

func (cli *Cli) DefaultAction(ctx *cliv2.Context) error

DefaultAction can be overriden by setting cli.App.Action after invoking `Init()`.

func (*Cli) Init

func (cli *Cli) Init() error

Init performs validation and when possible auto-populates absent fields with the `os` package equivalent (e.g. if `cli.App.Writer == nil` then it is set to `os.Stderr`) or other default value.

func (*Cli) Main

func (cli *Cli) Main() error

func (*Cli) RunWeb

func (cli *Cli) RunWeb(ctx *cliv2.Context) error

func (*Cli) ServiceManagementHandler

func (cli *Cli) ServiceManagementHandler() error

ServiceManagementHandler performs system service management updates.

type Options

type Options struct {
	AppName            string
	Usage              string
	Version            string
	Flags              []cliv2.Flag
	Stdout             io.Writer
	Stderr             io.Writer
	WebServiceProvider interfaces.WebServiceProvider
	Args               []string
	ExitOnError        bool // Exit on non-nil error during invocation of `Main()`.
}

Options provider for Cli struct.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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