Back to godoc.org

Package flag

v0.0.0-...-d4769a7
Latest Go to latest

The latest major version is .

Published: Aug 1, 2020 | License: Apache-2.0 | Module: github.com/luci/luci-go

Overview

Package flag provides the utilities for implementing command line flags.

Index

Examples

func BoolSlice

func BoolSlice(b *[]bool) flag.Getter

BoolSlice returns a flag.Getter which reads flags into the given []bool pointer.

func CommaList

func CommaList(s *[]string) flag.Getter

CommaList returns a flag.Getter for parsing a comma separated flag argument into a string slice.

func FieldSlice

func FieldSlice(f *[]googleapi.Field) flag.Getter

FieldSlice returns a flag.Getter which reads flags into the given []googleapi.Field pointer.

func GRPCMetadata

func GRPCMetadata(md metadata.MD) flag.Getter

GRPCMetadata returns a flag.Getter for parsing gRPC metadata from a a set of colon-separated strings. Example: -f a:1 -f a:2 -f b:3 Panics if md is nil.

func Int32

func Int32(i *int32) flag.Getter

Int32 returns a flag.Getter which reads flags into the given int32 pointer.

func Int64Slice

func Int64Slice(i *[]int64) flag.Getter

Int64Slice returns a flag.Getter which reads flags into the given []int64 pointer.

func JSONMap

func JSONMap(m *map[string]string) flag.Value

JSONMap returns a flag.Value that can be passed to flag.Var to parse a JSON string into a map.

func MessageSliceFlag

func MessageSliceFlag(msgSlicePtr interface{}) flag.Getter

MessageSliceFlag returns a new flag for a slice of pointer to concrete proto message struct which implements the proto.Message interface. Expect input to be of type *[]*B where B is concrete struct of proto message like pb.Build. A flag value must be a JSON string of the provided concrete proto message.

Example

Code:

var builds []*pb.Build
fs := flag.NewFlagSet("test", flag.ContinueOnError)
flag := MessageSliceFlag(&builds)
fs.Var(flag, "build", "Test Proto Message")
fs.Parse([]string{"-build",
	"{\"id\": 111111, \"status\": \"SUCCESS\"}"})
marshaler := &jsonpb.Marshaler{Indent: "  "}
jsonMsg, _ := marshaler.MarshalToString(builds[0])
fmt.Println(jsonMsg)
{
  "id": "111111",
  "status": "SUCCESS"
}

func StringPairs

func StringPairs(m strpair.Map) flag.Getter

StringPairs returns a flag.Getter for parsing strpair.Map from a a set of colon-separated strings. Example: -f a:1 -f a:2 -f b:3 Panics if m is nil.

func StringSlice

func StringSlice(s *[]string) flag.Getter

StringSlice returns a flag.Getter which reads flags into the given []string pointer.

func Time

func Time(t *time.Time) flag.Getter

Time returns a flag.Getter which parses a string into a time.Time pointer.

The timestamp to parse must be formatted as stiptime: https://chromium.googlesource.com/infra/infra/infra_libs/+/b2e2c9948c327b88b138d8bd60ec4bb3a957be78/time_functions/README.md

Caveat: Leap seconds are not supported due to a limitation in go's time library: https://github.com/golang/go/issues/15247

type Choice

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

Choice is an implementation of flag.Value for parsing a multiple-choice string.

func NewChoice

func NewChoice(output *string, choices ...string) Choice

NewChoice creates a Choice value

func (Choice) Set

func (f Choice) Set(s string) error

Set implements the flag.Value interface.

func (Choice) String

func (f Choice) String() string

String implements the flag.Value interface.

type RelativeTime

type RelativeTime struct {
	T *time.Time
	// contains filtered or unexported fields
}

RelativeTime is an implementation of flag.Value for parsing a time by a relative day offset.

func (RelativeTime) Set

func (f RelativeTime) Set(s string) error

Set implements the flag.Value interface.

func (RelativeTime) String

func (f RelativeTime) String() string

String implements the flag.Value interface.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier