flags

package
v0.0.0-...-ba1c585 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2017 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package flags implements utilities to augment the standard Go flag package. It defines commonly used Vanadium flags, and implementations of the flag.Value interface for those flags to ensure that only valid values of those flags are supplied. Some of these flags may also be specified using environment variables directly and are documented accordingly; in these cases the command line value takes precedence over the environment variable.

Flags are defined as 'groups' of related flags so that the caller may choose which ones to use without having to be burdened with the full set. The groups may be used directly or via the Flags type that aggregates multiple groups. In all cases, the flags are registered with a supplied flag.FlagSet and hence are not forced onto the command line unless the caller passes in flag.CommandLine as the flag.FlagSet to use.

In general, this package will be used by vanadium profiles and the runtime implementations, but can also be used by any application that wants access to the flags and environment variables it supports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultNamespaceRoot

func DefaultNamespaceRoot() string

DefaultNamespaceRoot gets the default value of --v23.namespace.root

func SetDefaultHostPort

func SetDefaultHostPort(s string)

SetDefaultHostPort sets the default host and port used when --v23.tcp.address is not provided. It must be called before flags are parsed for it to take effect.

func SetDefaultNamespaceRoot

func SetDefaultNamespaceRoot(root string)

SetDefaultNamespaceRoot sets the default value for --v23.namespace.root

func SetDefaultProtocol

func SetDefaultProtocol(protocol string)

SetDefaultProtocol sets the default protocol used when --v23.tcp.protocol is not provided. It must be called before flags are parsed for it to take effect.

Types

type FlagGroup

type FlagGroup int

FlagGroup is the type for identifying groups of related flags.

const (
	// Runtime identifies the flags and associated environment variables
	// used by the Vanadium process runtime. Namely:
	// --v23.namespace.root (which may be repeated to supply multiple values)
	// --v23.credentials
	// --v23.vtrace.sample-rate
	// --v23.vtrace.dump-on-shutdown
	// --v23.vtrace.cache-size
	// --v23.vtrace.collect-regexp
	Runtime FlagGroup = iota
	// Listen identifies the flags typically required to configure
	// rpc.ListenSpec. Namely:
	// --v23.tcp.protocol
	// --v23.tcp.address
	// --v23.proxy
	// --v23.i18n-catalogue
	Listen
	// --v23.permissions.file (which may be repeated to supply multiple values)
	// Permissions files are named - i.e. --v23.permissions.file=<name>:<file>
	// with the name "runtime" reserved for use by the runtime. "file" is
	// a JSON-encoded representation of the Permissions type defined in the
	// VDL package v.io/v23/security/access
	// -v23.permissions.literal
	Permissions
)

type Flags

type Flags struct {
	FlagSet *flag.FlagSet
	// contains filtered or unexported fields
}

Flags represents the set of flag groups created by a call to CreateAndRegister.

func CreateAndRegister

func CreateAndRegister(fs *flag.FlagSet, groups ...FlagGroup) *Flags

CreateAndRegister creates a new set of flag groups as specified by the supplied flag group parameters and registers them with the supplied flag.FlagSet.

func (*Flags) Args

func (f *Flags) Args() []string

Args returns the unparsed args, as per flag.Args.

func (*Flags) HasGroup

func (f *Flags) HasGroup(group FlagGroup) bool

HasGroup returns group if the supplied FlagGroup has been created for these Flags.

func (*Flags) ListenFlags

func (f *Flags) ListenFlags() ListenFlags

ListenFlags returns a copy of the Listen flag group stored in Flags. This copy will contain default values if the Listen flag group was not specified when CreateAndRegister was called. The HasGroup method can be used for testing to see if any given group was configured.

func (*Flags) Parse

func (f *Flags) Parse(args []string, cfg map[string]string) error

Parse parses the supplied args, as per flag.Parse. The config can optionally specify flag overrides.

func (*Flags) PermissionsFlags

func (f *Flags) PermissionsFlags() PermissionsFlags

PermissionsFlags returns a copy of the Permissions flag group stored in Flags. This copy will contain default values if the Permissions flag group was not specified when CreateAndRegister was called. The HasGroup method can be used for testing to see if any given group was configured.

func (*Flags) RuntimeFlags

func (f *Flags) RuntimeFlags() RuntimeFlags

RuntimeFlags returns the Runtime flag subset stored in its Flags instance.

type IPFlag

type IPFlag struct{ net.IP }

IPFlag implements flag.Value in order to provide validation of IP addresses in the flag package.

func (IPFlag) Get

func (ip IPFlag) Get() interface{}

Implements flag.Value.Get

func (*IPFlag) Set

func (ip *IPFlag) Set(s string) error

Implements flag.Value.Set

func (IPFlag) String

func (ip IPFlag) String() string

Implements flag.Value.String

type IPHostPortFlag

type IPHostPortFlag struct {
	Address string
	Host    string
	IP      []*net.IPAddr
	Port    string
}

IPHostPortFlag implements flag.Value to provide validation of the command line value it is set to. The allowed format is <host>:<port> in ip4 and ip6 formats. The host may be specified as a hostname or as an IP address (v4 or v6). If a hostname is used and it resolves to multiple IP addresses then all of those addresses are stored in IPHostPort.

func (IPHostPortFlag) Get

func (ip IPHostPortFlag) Get() interface{}

Implements flag.Value.Get

func (*IPHostPortFlag) Set

func (ip *IPHostPortFlag) Set(s string) error

Implements flag.Value.Set

func (IPHostPortFlag) String

func (ip IPHostPortFlag) String() string

Implements flag.Value.String

type ListenAddrs

type ListenAddrs []struct {
	Protocol, Address string
}

ListenAddrs is the set of listen addresses captured from the command line. ListenAddrs mirrors rpc.ListenAddrs.

type ListenFlags

type ListenFlags struct {
	Addrs ListenAddrs
	Proxy string
	// contains filtered or unexported fields
}

ListenFlags contains the values of the Listen flag group.

type PermissionsFlags

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

PermissionsFlags contains the values of the PermissionsFlags flag group.

func (PermissionsFlags) PermissionsFile

func (af PermissionsFlags) PermissionsFile(name string) string

PermissionsFile returns the file which is presumed to contain Permissions information associated with the supplied name parameter.

func (PermissionsFlags) PermissionsLiteral

func (af PermissionsFlags) PermissionsLiteral() string

type RuntimeFlags

type RuntimeFlags struct {
	// NamespaceRoots may be initialized by ref.EnvNamespacePrefix* enivornment
	// variables as well as --v23.namespace.root. The command line
	// will override the environment.
	NamespaceRoots []string

	// Credentials may be initialized by the ref.EnvCredentials
	// environment variable. The command line will override the environment.
	Credentials string // TODO(cnicolaou): provide flag.Value impl

	// I18nCatalogue may be initialized by the ref.EnvI18nCatalogueFiles
	// environment variable.  The command line will override the
	// environment.
	I18nCatalogue string

	// Vtrace flags control various aspects of Vtrace.
	Vtrace VtraceFlags
	// contains filtered or unexported fields
}

RuntimeFlags contains the values of the Runtime flag group.

type TCPProtocolFlag

type TCPProtocolFlag struct {
	Protocol string
}

TCPProtocolFlag implements flag.Value to provide validation of the command line values passed to it: tcp, tcp4, tcp6, ws, ws4, ws6, wsh, wsh4, and wsh6 being the only allowed values.

func (TCPProtocolFlag) Get

func (t TCPProtocolFlag) Get() interface{}

Implements flag.Value.Get

func (*TCPProtocolFlag) Set

func (t *TCPProtocolFlag) Set(s string) error

Implements flag.Value.Set

func (TCPProtocolFlag) String

func (t TCPProtocolFlag) String() string

Implements flag.Value.String

type VtraceFlags

type VtraceFlags struct {
	// VtraceSampleRate is the rate (from 0.0 - 1.0) at which
	// vtrace traces started by this process are sampled for collection.
	SampleRate float64

	// VtraceDumpOnShutdown tells the runtime to dump all stored traces
	// to Stderr at shutdown if true.
	DumpOnShutdown bool

	// VtraceCacheSize is the number of traces to cache in memory.
	// TODO(mattr): Traces can be of widely varying size, we should have
	// some better measurement then just number of traces.
	CacheSize int

	// LogLevel is the level of vlogs that should be collected as part of
	// the trace
	LogLevel int

	// SpanRegexp matches a regular expression against span names and
	// annotations and forces any trace matching trace to be collected.
	CollectRegexp string
}

Jump to

Keyboard shortcuts

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