base

package
v0.0.0-...-a0a3655 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package base contains code shared by other CLI subpackages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectErrorMessages

func CollectErrorMessages(err error, in []string) (out []string)

CollectErrorMessages traverses err (which can be a MultiError, recursively), and appends all error messages there to 'in', returning the resulting slice.

They are eventually used in JSON output and printed to stderr.

func GenerateConfigs

func GenerateConfigs(ctx context.Context, inputFile string, meta, flags *lucicfg.Meta) (lucicfg.Output, error)

GenerateConfigs executes the Starlark script and assembles final values for meta config.

It is a common part of subcommands that generate configs.

'meta' is initial Meta config with default parameters, it will be mutated in-place to contain the final parameters (based on lucicfg.config(...) calls in Starlark and the config populated via CLI flags, passed as 'flags'). 'flags' are also mutated in-place to rebase ConfigDir onto cwd.

func MissingFlagError

func MissingFlagError(flag string) error

MissingFlagError is CommandLineError about a missing flag.

func NewCLIError

func NewCLIError(msg string, args ...interface{}) error

NewCLIError returns new CommandLineError.

func ValidateOutput

func ValidateOutput(ctx context.Context, output lucicfg.Output, svc ConfigServiceFactory, host string, failOnWarns bool) ([]*lucicfg.ValidationResult, error)

ValidateOutput splits the output into 0 or more config sets and sends them for validation to LUCI Config.

It is a common part of subcommands that validate configs.

It is allowed for 'host' to be empty. This causes a warning and the validation is skipped.

If failOnWarn is true, treat warnings from LUCI Config as errors.

Dumps validation errors to the logger. In addition to detailed validation results, also returns a multi-error with all validation and RPC errors.

Types

type CommandLineError

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

CommandLineError is used to tag errors related to command line arguments.

Subcommand.Done(..., err) will print the usage string if it finds such error.

type ConfigServiceFactory

type ConfigServiceFactory func(ctx context.Context, host string) (*config.Service, error)

ConfigServiceFactory returns LUCI Config RPC client that sends requests to the given host.

This is usually just subcommand.ConfigService.

type Parameters

type Parameters struct {
	AuthOptions       auth.Options // mostly for client ID and client secret
	ConfigServiceHost string       // e.g. "luci-config.appspot.com"
}

Parameters can be used to customize CLI defaults.

type Subcommand

type Subcommand struct {
	subcommands.CommandRunBase

	Meta lucicfg.Meta // meta config settable via CLI flags
	// contains filtered or unexported fields
}

Subcommand is a base of all subcommands.

It defines some common flags, such as logging and JSON output parameters, and some common methods to report errors and dump JSON output.

It's Init() method should be called from within CommandRun to register base flags.

func (*Subcommand) AddMetaFlags

func (c *Subcommand) AddMetaFlags()

AddMetaFlags registers c.Meta in the FlagSet.

Used by subcommands that end up executing Starlark.

func (*Subcommand) CheckArgs

func (c *Subcommand) CheckArgs(args []string, minPosCount, maxPosCount int) bool

CheckArgs checks command line args.

It ensures all required positional and flag-like parameters are set. Setting maxPosCount to -1 indicates there is unbounded number of positional arguments allowed.

Returns true if they are, or false (and prints to stderr) if not.

func (*Subcommand) ConfigService

func (c *Subcommand) ConfigService(ctx context.Context, host string) (*config.Service, error)

ConfigService returns a wrapper around LUCI Config API.

It is ready for making authenticated RPCs. 'host' is a hostname of the service to hit, e.g. "luci-config.appspot.com".

func (*Subcommand) DefaultMeta

func (c *Subcommand) DefaultMeta() lucicfg.Meta

DefaultMeta returns Meta values to use by default if not overridden via flags or via lucicfg.config(...).

func (*Subcommand) Done

func (c *Subcommand) Done(result interface{}, err error) int

Done is called as the last step of processing a subcommand.

It dumps the command result (or an error) to the JSON output file, prints the error message and generates the process exit code.

func (*Subcommand) Init

func (c *Subcommand) Init(params Parameters)

Init registers common flags.

func (*Subcommand) ModifyContext

func (c *Subcommand) ModifyContext(ctx context.Context) context.Context

ModifyContext implements cli.ContextModificator.

Jump to

Keyboard shortcuts

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