luci: go.chromium.org/luci/common/cli Index | Files

package cli

import "go.chromium.org/luci/common/cli"

Package cli is a helper package for "github.com/maruel/subcommands".

It adds a non-intrusive integration with context.Context.

Index

Package Files

cli.go no_profile.go

func GetContext Uses

func GetContext(app subcommands.Application, cmd subcommands.CommandRun, env subcommands.Env) context.Context

GetContext sniffs ContextModificator in the app and in the cmd and uses them to derive a context for the command.

Embeds the subcommands.Env into the Context (if any), which can be accessed with the *env methods in this package.

Subcommands can use it to get an initial context in their 'Run' methods.

Returns the background context if app doesn't implement ContextModificator.

func Getenv Uses

func Getenv(ctx context.Context, key string) string

Getenv returns the given value from the embedded subcommands.Env, or "" if the value was unset and had no default.

func LookupEnv Uses

func LookupEnv(ctx context.Context, key string) subcommands.EnvVar

LookupEnv returns the given value from the embedded subcommands.Env as-is.

func MakeGetEnv Uses

func MakeGetEnv(ctx context.Context) func(string) string

MakeGetEnv returns a function bound to the supplied Context that has the same semantics as os.Getenv. This can be used to simplify environment compatibility.

type Application Uses

type Application struct {
    Name     string
    Title    string
    Context  func(context.Context) context.Context
    Commands []*subcommands.Command
    EnvVars  map[string]subcommands.EnvVarDefinition
    // contains filtered or unexported fields
}

Application is like subcommands.DefaultApplication, except it also implements ContextModificator.

func (*Application) GetCommands Uses

func (a *Application) GetCommands() []*subcommands.Command

GetCommands implements interface subcommands.Application.

func (*Application) GetEnvVars Uses

func (a *Application) GetEnvVars() map[string]subcommands.EnvVarDefinition

GetEnvVars implements interface subcommands.Application.

func (*Application) GetErr Uses

func (a *Application) GetErr() io.Writer

GetErr implements interface subcommands.Application.

func (*Application) GetName Uses

func (a *Application) GetName() string

GetName implements interface subcommands.Application.

func (*Application) GetOut Uses

func (a *Application) GetOut() io.Writer

GetOut implements interface subcommands.Application.

func (*Application) GetTitle Uses

func (a *Application) GetTitle() string

GetTitle implements interface subcommands.Application.

func (*Application) ModifyContext Uses

func (a *Application) ModifyContext(ctx context.Context) context.Context

ModifyContext implements interface ContextModificator.

'ctx' here is always context.Background().

type ContextModificator Uses

type ContextModificator interface {
    ModifyContext(context.Context) context.Context
}

ContextModificator takes a context, adds something, and returns a new one.

It is implemented by Application and can optionally by implemented by subcommands.CommandRun instances. It will be called by GetContext to modify initial context.

Package cli imports 4 packages (graph) and is imported by 25 packages. Updated 2018-08-19. Refresh now. Tools for package owners.