common

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const CrosfleetToolTag = "crosfleet-tool"

Tag to add to Buildbucket builds to indicate which crosfleet subcommand was used to launch the build.

Variables

CmpOpts enables comparisons of the listed protos with unexported fields.

View Source
var JSONPBUnmarshaler = jsonpb.Unmarshaler{AllowUnknownFields: true}

JSONPBUnmarshaler unmarshals JSON into proto messages.

Functions

func CLIPrompt

func CLIPrompt(reason string, defaultResponse bool) (bool, error)

CLIPrompt prompts the user for a y/n input on CLI.

func ErrToString

func ErrToString(e error) string

ErrToString enables safe conversions of errors to strings. Returns an empty string for nil errors.

func GetUserEmail

func GetUserEmail(ctx context.Context, flags *authcli.Flags) (string, error)

GetUserEmail parses the given auth flags and returns the email of the authenticated crosfleet user.

func MapToStruct

func MapToStruct(m map[string]interface{}) (*structpb.Struct, error)

MapToStruct constructs a Struct from the given map[string]interface{}. The map keys must be valid UTF-8. The map values can be any of Go's basic types (bool, string, number type, byte, or rune), a proto message (in the form protoreflect.ProtoMessage), or a nested map[string]interface{} that fulfils the same requirements recursively.

NOTE: This function is just a modified version of structpb.NewStruct(), with added logic to handle the case where the map value is a proto message. This is necessary because Buildbucket request interfaces are almost always implemented as proto messages at some level.

func OffsetTimestamp

func OffsetTimestamp(minutes int64) *timestamppb.Timestamp

OffsetTimestamp returns a timestamp offset from the current time by the given number of minutes.

func ToKeyvalSlice

func ToKeyvalSlice(keyvals map[string]string) []string

ToKeyvalSlice converts a key-val map to a slice of "key:val" strings.

func WriteCrosfleetUIPromptStderr

func WriteCrosfleetUIPromptStderr(args []string)

WriteCrosfleetUIPromptStderr writes a prompt to Stderr for users to visit the go/my-crosfleet PLX dashboard to track their crosfleet-launched tasks, as long as the CLI args do NOT include the -json flag. If -json WAS included, the function does nothing.

NOTE: Parsing the -json flag here must happen separately from the normal CLIPrinter functions, since unlike those functions, this is run at the level of the outer "run"/"dut" commands, which don't have native access to the -json flag passed to their subcommands (e.g. "run test" or "dut lease").

Types

type CLIPrinter

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

CLIPrinter handles all command line output.

func (*CLIPrinter) Register

func (p *CLIPrinter) Register(fl *flag.FlagSet)

Register parses the -json flag.

func (*CLIPrinter) RegisterFromSubcmdArgs

func (p *CLIPrinter) RegisterFromSubcmdArgs(args []string)

RegisterFromSubcmdArgs parses the -json flag directly from a list of args intended for a subcommand. This function is used to read the -json flag at the outer command level, e.g. dutcmd and runcmd.

func (*CLIPrinter) WriteJSONStdout

func (p *CLIPrinter) WriteJSONStdout(output proto.Message)

WriteJSONStdout writes the given proto message as JSON (followed by a line break) to Stdout, as long as the CLI command WAS passed the -json flag. If -json was NOT passed, the function does nothing.

func (*CLIPrinter) WriteTextStderr

func (p *CLIPrinter) WriteTextStderr(output string, outputArgs ...interface{})

WriteTextStderr writes the given human-readable output string (followed by a line break) to Stderr, as long as the CLI command was NOT passed the -json flag. If -json WAS passed, the function does nothing.

func (*CLIPrinter) WriteTextStdout

func (p *CLIPrinter) WriteTextStdout(output string, outputArgs ...interface{})

WriteTextStdout writes the given human-readable output string (followed by a line break) to Stdout, as long as the CLI command was NOT passed the -json flag. If -json WAS passed, the function does nothing.

type EnvFlags

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

EnvFlags controls selection of the environment: either prod (default) or dev.

func (EnvFlags) Env

func (f EnvFlags) Env() site.Environment

Env returns the environment, either dev or prod.

func (*EnvFlags) Register

func (f *EnvFlags) Register(fl *flag.FlagSet)

Register parses the -dev flag.

Jump to

Keyboard shortcuts

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