Documentation
¶
Index ¶
- Constants
- Variables
- func CLIPrompt(reason string, defaultResponse bool) (bool, error)
- func ErrToString(e error) string
- func GetUserEmail(ctx context.Context, flags *authcli.Flags) (string, error)
- func MapToStruct(m map[string]interface{}) (*structpb.Struct, error)
- func OffsetTimestamp(minutes int64) *timestamppb.Timestamp
- func PrintCmdError(a subcommands.Application, err error)
- func ProtoToStructVal(msg protoreflect.ProtoMessage) (*structpb.Value, error)
- func ToKeyvalSlice(keyvals map[string]string) []string
- func WriteCrosfleetUIPromptStderr(args []string)
- type CLIPrinter
- func (p *CLIPrinter) GetErr() io.Writer
- func (p *CLIPrinter) GetOut() io.Writer
- func (p *CLIPrinter) Register(fl *flag.FlagSet)
- func (p *CLIPrinter) WriteJSONStdout(output proto.Message)
- func (p *CLIPrinter) WriteTextStderr(output string, outputArgs ...interface{})
- func (p *CLIPrinter) WriteTextStdout(output string, outputArgs ...interface{})
- type EnvFlags
Constants ¶
const CrosfleetToolTag = "crosfleet-tool"
Tag to add to Buildbucket builds to indicate which crosfleet subcommand was used to launch the build.
Variables ¶
var CmpOpts = cmpopts.IgnoreUnexported( api.ContainerInfo{}, api.CTPFilter{}, buildapi.ContainerImageInfo{}, buildbucketpb.Build{}, buildbucketpb.BuilderID{}, buildbucketpb.RequestedDimension{}, buildbucketpb.StringPair{}, chromiumos.BuildTarget{}, duration.Duration{}, test_platform.Request{}, test_platform.Request_Test{}, test_platform.Request_TestPlan{}, test_platform.Request_Test_Autotest{}, test_platform.Request_Test_Autotest_{}, test_platform.Request_Params{}, test_platform.Request_Params_HardwareAttributes{}, test_platform.Request_Params_SecondaryDevice{}, test_platform.Request_Params_SoftwareAttributes{}, test_platform.Request_Params_SoftwareDependency{}, test_platform.Request_Params_FreeformAttributes{}, test_platform.Request_Params_Scheduling{}, test_platform.Request_Params_Decorations{}, test_platform.Request_Params_Retry{}, test_platform.Request_Params_Metadata{}, test_platform.Request_Params_Time{}, test_platform.Request_Suite{}, test_platform.ServiceVersion{}, structpb.ListValue{}, structpb.Struct{}, structpb.Value{})
CmpOpts enables comparisons of the listed protos with unexported fields.
var JSONPBUnmarshaler = jsonpb.Unmarshaler{AllowUnknownFields: true}
JSONPBUnmarshaler unmarshals JSON into proto messages.
Functions ¶
func ErrToString ¶
ErrToString enables safe conversions of errors to strings. Returns an empty string for nil errors.
func GetUserEmail ¶
GetUserEmail parses the given auth flags and returns the email of the authenticated crosfleet user.
func MapToStruct ¶
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 PrintCmdError ¶
func PrintCmdError(a subcommands.Application, err error)
PrintCmdError wraps the standard cmdlib.PrintError() function with a prompt to run `crosfleet login` if the error was LUCI auth-related.
func ProtoToStructVal ¶
func ProtoToStructVal(msg protoreflect.ProtoMessage) (*structpb.Value, error)
ProtoToStructVal converts a proto message to a *structpb.Value.
func ToKeyvalSlice ¶
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) GetErr ¶
func (p *CLIPrinter) GetErr() io.Writer
GetErr exposes the Stderr writer used by the CLI printer, returning nil if the -silent flag was passed.
func (*CLIPrinter) GetOut ¶
func (p *CLIPrinter) GetOut() io.Writer
GetOut exposes the Stdout writer used by the CLI printer, returning nil if the -silent flag was passed.
func (*CLIPrinter) Register ¶
func (p *CLIPrinter) Register(fl *flag.FlagSet)
Register parses the -json flag.
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.