luci: Index | Files

package base

import ""

Package base contains code shared by other CLI subpackages.


Package Files

base.go errors.go generate.go validate.go

func CollectErrorMessages Uses

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 Uses

func GenerateConfigs(ctx context.Context, inputFile string, meta, flags *lucicfg.Meta, vars map[string]string) (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.

'vars' are a collection of k=v pairs passed via CLI flags as `-var k=v`. They are used to pre-set lucicfg.var(..., exposed_as=<k>) variables.

func MissingFlagError Uses

func MissingFlagError(flag string) error

MissingFlagError is CommandLineError about a missing flag.

func NewCLIError Uses

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

NewCLIError returns new CommandLineError.

func ValidateOutput Uses

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.

type CommandLineError Uses

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 Uses

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 Uses

type Parameters struct {
    AuthOptions       auth.Options // mostly for client ID and client secret
    ConfigServiceHost string       // e.g. ""

Parameters can be used to customize CLI defaults.

type Subcommand Uses

type Subcommand struct {

    Meta lucicfg.Meta        // meta config settable via CLI flags
    Vars stringmapflag.Value // all `-var k=v` 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 Uses

func (c *Subcommand) AddMetaFlags()

AddMetaFlags registers c.Meta in the FlagSet.

Used by subcommands that end up executing Starlark.

func (*Subcommand) CheckArgs Uses

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 Uses

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. "".

func (*Subcommand) DefaultMeta Uses

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 Uses

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 Uses

func (c *Subcommand) Init(params Parameters)

Init registers common flags.

func (*Subcommand) ModifyContext Uses

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

ModifyContext implements cli.ContextModificator.

Package base imports 20 packages (graph) and is imported by 5 packages. Updated 2020-05-31. Refresh now. Tools for package owners.