flags

package
v0.0.0-...-c8a5df3 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package flags defines command-line flags to make them consistent between binaries. Not all flags make sense for all binaries.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Config ("config") names the configuration file to use.
	Config = defaultConfigFile

	// ServerConfigFile is the server configuration file
	ServerConfigFile = defaultServerConfigFile

	// HTTPAddr ("http") is the network address on which to listen for
	// incoming insecure network connections.
	HTTPAddr = defaultHTTPAddr

	// Store is the store to target.
	Store = "default"

	// Log ("log") sets the level of logging (implements flag.Value).
	Log logFlag

	// Audit ("audit") request that an audit of the inventory is performed
	// when initializing.
	Audit = false

	// ResetDB ("dbreset") resets the inventory database
	ResetDB = false

	// Simulate ("simulate") enable simulation
	Simulate = false

	// EmulateDevices ("emulate-dev") enable emulation of devices
	EmulateDevices = false

	// Version causes the program to print its release version and exit.
	// The printed version is only meaningful in released binaries.
	Version = false
)
View Source
var Client = []string{
	"config", "log", "store",
}

Client is the set of flags most useful in clients. It can be passed as the argument to Parse to set up the package for a client.

View Source
var None = []string{}

None is the set of no flags. It is rarely needed as most programs use either the Server or Client set.

View Source
var Server = []string{
	"log", "simulate", "emulate-dev", "dbreset", "audit", "serverconfig",
}

Server is the set of flags most useful in servers. It can be passed as the argument to Parse to set up the package for a server.

Functions

func Args

func Args() []string

Args returns a slice of -flag=value strings that will recreate the state of the flags. Flags set to their default value are elided.

func Parse

func Parse(defaultList []string, extras ...string)

Parse registers the command-line flags for the given default flags list, plus any extra flag names, and calls flag.Parse. Passing no flag names in either list registers all flags. Passing an unknown name triggers a panic. The Server and Client variables contain useful default sets.

Examples:

flags.Parse(flags.Client) // Register all client flags.
flags.Parse(flags.Server, "cachedir") // Register all server flags plus cachedir.
flags.Parse(nil) // Register all flags.
flags.Parse(flags.None, "config", "endpoint") // Register only config and endpoint.

func ParseArgs

func ParseArgs(args, defaultList []string, extras ...string)

ParseArgs is the same as Parse but uses the provided argument list instead of those provided on the command line. For ParseArgs, the initial command name should not be provided.

func ParseArgsInto

func ParseArgsInto(fs *flag.FlagSet, args, defaultList []string, extras ...string)

ParseArgsInto is the same as ParseArgs but accepts a FlagSet argument instead of using the default flag.CommandLine FlagSet.

func ParseInto

func ParseInto(fs *flag.FlagSet, defaultList []string, extras ...string)

ParseInto is the same as Parse but accepts a FlagSet argument instead of using the default flag.CommandLine FlagSet.

func Register

func Register(names ...string)

Register registers the command-line flags for the given flag names. Unlike Parse, it may be called multiple times. Passing zero names install all flags. Passing an unknown name triggers a panic.

For example:

flags.Register("config", "endpoint") // Register Config and Endpoint.

or

flags.Register() // Register all flags.

func RegisterInto

func RegisterInto(fs *flag.FlagSet, names ...string)

RegisterInto is the same as Register but accepts a FlagSet argument instead of using the default flag.CommandLine FlagSet.

Types

This section is empty.

Jump to

Keyboard shortcuts

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