flags

package
v0.0.0-...-3f1964b Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: Apache-2.0 Imports: 9 Imported by: 27

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 (
	// BlockSize ("blocksize") is the block size used when writing large files.
	// The default is 1MB; it can be no larger than 1GB.
	BlockSize = defaultBlockSize

	// CacheDir ("cachedir") specifies the directory for the various file
	// caches.
	CacheDir = defaultCacheDir

	// CacheSize ("cachesize") specifies the maximum bytes used by
	// the various file caches. This is only approximate.
	CacheSize = defaultCacheSize

	// Config ("config") names the Upspin configuration file to use.
	Config = defaultConfig

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

	// HTTPSAddr ("https") is the network address on which to listen for
	// incoming secure network connections.
	HTTPSAddr = defaultHTTPSAddr

	// InsecureHTTP ("insecure") specifies whether to serve insecure HTTP
	// on HTTPAddr, instead of serving HTTPS (secured by TLS) on HTTPSAddr.
	InsecureHTTP = false

	// LetsEncryptCache ("letscache") is the location of a file in which
	// the Let's Encrypt certificates are stored. The containing directory
	// should be owner-accessible only (chmod 0700).
	LetsEncryptCache = defaultLetsEncryptCache

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

	// NetAddr ("addr") is the publicly accessible network address of this
	// server.
	NetAddr = ""

	// ServerConfig ("serverconfig") specifies configuration options for
	// servers in "key=value" pairs.
	ServerConfig []string

	// ServerKind ("kind") is the implementation kind of this server.
	ServerKind = defaultServerKind

	// Prudent ("prudent") sets an extra security mode in the client to
	// check for malicious or buggy servers, at possible cost in
	// performance or convenience. Specifically, one check is that the
	// writer listed in a directory entry is either the owner or a user
	// currently with write permission. This protects against a forged
	// directory entry at the cost of potentially blocking a legitimate
	// file written by a user who no longer has write permission.
	Prudent = false

	// TLSCertFile and TLSKeyFile ("tls") specify the location of a TLS
	// certificate/key pair used for serving TLS (HTTPS).
	TLSCertFile = ""
	TLSKeyFile  = ""

	// Version causes the program to print its release version and exit.
	// The printed version is only meaningful in released binaries.
	Version = false
)

The Parse and Register functions bind these variables to their respective command-line flags.

View Source
var Client = []string{
	"config", "log", "blocksize", "prudent",
}

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{
	"config", "log", "http", "https", "letscache", "tls", "addr", "insecure",
}

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