func FlagsForClient(ccfg *ClientConfig, flagset *flag.FlagSet) { flagset.DurationVar(&ccfg.IdleTimeout, "timeout", DefaultIdleTimeout, "amount of idle time before timeout") flagset.IntVar(&ccfg.IdleConnectionsToInstance, "maxidle", DefaultIdleConnectionsToInstance, "maximum number of idle connections to a particular instance") flagset.IntVar(&ccfg.MaxConnectionsToInstance, "maxconns", DefaultMaxConnectionsToInstance, "maximum number of concurrent connections to a particular instance") flagset.StringVar(&ccfg.Region, "region", GetDefaultEnvVar("SKYNET_REGION", DefaultRegion), "region client is located in") flagset.StringVar(&ccfg.Host, "host", GetDefaultEnvVar("SKYNET_HOST", DefaultRegion), "host client is located in") }
// ApplyWithError populates the flag given the flag set and environment func (f DurationFlag) ApplyWithError(set *flag.FlagSet) error { if f.EnvVar != "" { for _, envVar := range strings.Split(f.EnvVar, ",") { envVar = strings.TrimSpace(envVar) if envVal, ok := syscall.Getenv(envVar); ok { envValDuration, err := time.ParseDuration(envVal) if err != nil { return fmt.Errorf("could not parse %s as duration for flag %s: %s", envVal, f.Name, err) } f.Value = envValDuration break } } } eachName(f.Name, func(name string) { if f.Destination != nil { set.DurationVar(f.Destination, name, f.Value, f.Usage) return } set.Duration(name, f.Value, f.Usage) }) return nil }
// AddFlags adds libkbfs flags to the given FlagSet. Returns an // InitParams that will be filled in once the given FlagSet is parsed. func AddFlags(flags *flag.FlagSet) *InitParams { var params InitParams flags.BoolVar(¶ms.Debug, "debug", BoolForString(os.Getenv("KBFS_DEBUG")), "Print debug messages") flags.StringVar(¶ms.CPUProfile, "cpuprofile", "", "write cpu profile to file") flags.StringVar(¶ms.BServerAddr, "bserver", GetDefaultBServer(), "host:port of the block server") flags.StringVar(¶ms.MDServerAddr, "mdserver", GetDefaultMDServer(), "host:port of the metadata server") flags.BoolVar(¶ms.ServerInMemory, "server-in-memory", false, "use in-memory server (and ignore -bserver, -mdserver, and -server-root)") flags.StringVar(¶ms.ServerRootDir, "server-root", "", "directory to put local server files (and ignore -bserver and -mdserver)") flags.StringVar(¶ms.LocalUser, "localuser", "", "fake local user (used only with -server-in-memory or -server-root)") flags.DurationVar(¶ms.TLFValidDuration, "tlf-valid", tlfValidDurationDefault, "time tlfs are valid before redoing identification") flags.BoolVar(¶ms.LogToFile, "log-to-file", false, fmt.Sprintf("Log to default file: %s", defaultLogPath())) flags.StringVar(¶ms.LogFileConfig.Path, "log-file", "", "Path to log file") flags.DurationVar(¶ms.LogFileConfig.MaxAge, "log-file-max-age", 30*24*time.Hour, "Maximum age of a log file before rotation") params.LogFileConfig.MaxSize = 128 * 1024 * 1024 flag.Var(SizeFlag{¶ms.LogFileConfig.MaxSize}, "log-file-max-size", "Maximum size of a log file before rotation") // The default is to *DELETE* old log files for kbfs. flag.IntVar(¶ms.LogFileConfig.MaxKeepFiles, "log-file-max-keep-files", 3, "Maximum number of log files for this service, older ones are deleted. 0 for infinite.") if getRunMode() != libkb.ProductionRunMode { flag.BoolVar(¶ms.EnableSharingBeforeSignup, "enable-sharing-before-signup", false, "enable sharing before signup") } return ¶ms }
// registerFlags defines all cfssl command flags and associates their values with variables. func registerFlags(c *Config, f *flag.FlagSet) { f.StringVar(&c.Hostname, "hostname", "", "Hostname for the cert, could be a comma-separated hostname list") f.StringVar(&c.CertFile, "cert", "", "Client certificate that contains the public key") f.StringVar(&c.CSRFile, "csr", "", "Certificate signature request file for new public key") f.StringVar(&c.CAFile, "ca", "", "CA used to sign the new certificate") f.StringVar(&c.CAKeyFile, "ca-key", "", "CA private key") f.StringVar(&c.TLSCertFile, "tls-cert", "", "Other endpoint CA to set up TLS protocol") f.StringVar(&c.TLSKeyFile, "tls-key", "", "Other endpoint CA private key") f.StringVar(&c.TrustAnchorFile, "trust-anchors", "", "Trust anchors for client TLS verification") f.BoolVar(&c.RequireClientTLSCertificates, "client-auth", false, "Require client TLS verification") f.StringVar(&c.KeyFile, "key", "", "private key for the certificate") f.StringVar(&c.IntermediatesFile, "intermediates", "", "intermediate certs") f.StringVar(&c.CABundleFile, "ca-bundle", "", "path to root certificate store") f.StringVar(&c.IntBundleFile, "int-bundle", "", "path to intermediate certificate store") f.StringVar(&c.Stats, "stats", "", "period for statistics printing") f.StringVar(&c.Address, "address", "127.0.0.1", "Address to bind") f.IntVar(&c.Port, "port", 8888, "Port to bind") f.StringVar(&c.ConfigFile, "config", "", "path to configuration file") f.StringVar(&c.Profile, "profile", "", "signing profile to use") f.BoolVar(&c.IsCA, "initca", false, "initialise new CA") f.BoolVar(&c.RenewCA, "renewca", false, "re-generate a CA certificate from existing CA certificate/key") f.StringVar(&c.IntDir, "int-dir", "", "specify intermediates directory") f.StringVar(&c.Flavor, "flavor", "ubiquitous", "Bundle Flavor: ubiquitous, optimal and force.") f.StringVar(&c.Metadata, "metadata", "", "Metadata file for root certificate presence. The content of the file is a json dictionary (k,v): each key k is SHA-1 digest of a root certificate while value v is a list of key store filenames.") f.StringVar(&c.Domain, "domain", "", "remote server domain name") f.StringVar(&c.IP, "ip", "", "remote server ip") f.StringVar(&c.Remote, "remote", "", "remote CFSSL server") f.StringVar(&c.Label, "label", "", "key label to use in remote CFSSL server") f.StringVar(&c.AuthKey, "authkey", "", "key to authenticate requests to remote CFSSL server") f.StringVar(&c.ResponderFile, "responder", "", "Certificate for OCSP responder") f.StringVar(&c.ResponderKeyFile, "responder-key", "", "private key for OCSP responder certificate") f.StringVar(&c.Status, "status", "good", "Status of the certificate: good, revoked, unknown") f.StringVar(&c.Reason, "reason", "0", "Reason code for revocation") f.StringVar(&c.RevokedAt, "revoked-at", "now", "Date of revocation (YYYY-MM-DD)") f.DurationVar(&c.Interval, "interval", 4*helpers.OneDay, "Interval between OCSP updates (default: 96h)") f.BoolVar(&c.List, "list", false, "list possible scanners") f.StringVar(&c.Family, "family", "", "scanner family regular expression") f.StringVar(&c.Scanner, "scanner", "", "scanner regular expression") f.DurationVar(&c.Timeout, "timeout", 5*time.Minute, "duration (ns, us, ms, s, m, h) to scan each host before timing out") f.StringVar(&c.CSVFile, "csv", "", "file containing CSV of hosts") f.IntVar(&c.NumWorkers, "num-workers", 10, "number of workers to use for scan") f.IntVar(&c.MaxHosts, "max-hosts", 100, "maximum number of hosts to scan") f.StringVar(&c.Responses, "responses", "", "file to load OCSP responses from") f.StringVar(&c.Path, "path", "/", "Path on which the server will listen") f.StringVar(&c.Password, "password", "0", "Password for accessing PKCS #12 data passed to bundler") f.StringVar(&c.Usage, "usage", "", "usage of private key") f.StringVar(&c.PGPPrivate, "pgp-private", "", "file to load a PGP Private key decryption") f.StringVar(&c.Serial, "serial", "", "certificate serial number") f.StringVar(&c.DBConfigFile, "db-config", "", "certificate db configuration file") if pkcs11.Enabled { f.StringVar(&c.Module, "pkcs11-module", "", "PKCS #11 module") f.StringVar(&c.Token, "pkcs11-token", "", "PKCS #11 token") f.StringVar(&c.PIN, "pkcs11-pin", os.Getenv("USER_PIN"), "PKCS #11 user PIN") f.StringVar(&c.PKCS11Label, "pkcs11-label", "", "PKCS #11 label") } }
// registerFlags defines all cfssl command flags and associates their values with variables. func registerFlags(c *cli.Config, f *flag.FlagSet) { f.BoolVar(&c.List, "list", false, "list possible scanners") f.StringVar(&c.Family, "family", "", "scanner family regular expression") f.StringVar(&c.Scanner, "scanner", "", "scanner regular expression") f.DurationVar(&c.Timeout, "timeout", 5*time.Minute, "duration (ns, us, ms, s, m, h) to scan each host before timing out") f.StringVar(&c.IP, "ip", "", "remote server ip") f.StringVar(&c.CABundleFile, "ca-bundle", "", "path to root certificate store") f.IntVar(&log.Level, "loglevel", log.LevelInfo, "Log level") }
// registerFlags defines all cfssl command flags and associates their values with variables. func registerFlags(c *Config, f *flag.FlagSet) { f.StringVar(&c.Hostname, "hostname", "", "Hostname for the cert, could be a comma-separated hostname list") f.StringVar(&c.CertFile, "cert", "", "Client certificate that contains the public key") f.StringVar(&c.CSRFile, "csr", "", "Certificate signature request file for new public key") f.StringVar(&c.CAFile, "ca", "", "CA used to sign the new certificate") f.StringVar(&c.CAKeyFile, "ca-key", "", "CA private key") f.StringVar(&c.TLSCertFile, "tls-cert", "", "Other endpoint CA to set up TLS protocol") f.StringVar(&c.TLSKeyFile, "tls-key", "", "Other endpoint CA private key") f.StringVar(&c.MutualTLSCAFile, "mutual-tls-ca", "", "Mutual TLS - require clients be signed by this CA ") f.StringVar(&c.MutualTLSCNRegex, "mutual-tls-cn", "", "Mutual TLS - regex for whitelist of allowed client CNs") f.StringVar(&c.TLSRemoteCAs, "tls-remote-ca", "", "CAs to trust for remote TLS requests") f.StringVar(&c.MutualTLSCertFile, "mutual-tls-client-cert", "", "Mutual TLS - client certificate to call remote instance requiring client certs") f.StringVar(&c.MutualTLSKeyFile, "mutual-tls-client-key", "", "Mutual TLS - client key to call remote instance requiring client certs") f.StringVar(&c.KeyFile, "key", "", "private key for the certificate") f.StringVar(&c.IntermediatesFile, "intermediates", "", "intermediate certs") f.StringVar(&c.CABundleFile, "ca-bundle", "", "path to root certificate store") f.StringVar(&c.IntBundleFile, "int-bundle", "", "path to intermediate certificate store") f.StringVar(&c.Address, "address", "127.0.0.1", "Address to bind") f.IntVar(&c.Port, "port", 8888, "Port to bind") f.StringVar(&c.ConfigFile, "config", "", "path to configuration file") f.StringVar(&c.Profile, "profile", "", "signing profile to use") f.BoolVar(&c.IsCA, "initca", false, "initialise new CA") f.BoolVar(&c.RenewCA, "renewca", false, "re-generate a CA certificate from existing CA certificate/key") f.StringVar(&c.IntDir, "int-dir", "", "specify intermediates directory") f.StringVar(&c.Flavor, "flavor", "ubiquitous", "Bundle Flavor: ubiquitous, optimal and force.") f.StringVar(&c.Metadata, "metadata", "", "Metadata file for root certificate presence. The content of the file is a json dictionary (k,v): each key k is SHA-1 digest of a root certificate while value v is a list of key store filenames.") f.StringVar(&c.Domain, "domain", "", "remote server domain name") f.StringVar(&c.IP, "ip", "", "remote server ip") f.StringVar(&c.Remote, "remote", "", "remote CFSSL server") f.StringVar(&c.Label, "label", "", "key label to use in remote CFSSL server") f.StringVar(&c.AuthKey, "authkey", "", "key to authenticate requests to remote CFSSL server") f.StringVar(&c.ResponderFile, "responder", "", "Certificate for OCSP responder") f.StringVar(&c.ResponderKeyFile, "responder-key", "", "private key for OCSP responder certificate") f.StringVar(&c.Status, "status", "good", "Status of the certificate: good, revoked, unknown") f.StringVar(&c.Reason, "reason", "0", "Reason code for revocation") f.StringVar(&c.RevokedAt, "revoked-at", "now", "Date of revocation (YYYY-MM-DD)") f.DurationVar(&c.Interval, "interval", 4*helpers.OneDay, "Interval between OCSP updates (default: 96h)") f.BoolVar(&c.List, "list", false, "list possible scanners") f.StringVar(&c.Family, "family", "", "scanner family regular expression") f.StringVar(&c.Scanner, "scanner", "", "scanner regular expression") f.DurationVar(&c.Timeout, "timeout", 5*time.Minute, "duration (ns, us, ms, s, m, h) to scan each host before timing out") f.StringVar(&c.CSVFile, "csv", "", "file containing CSV of hosts") f.IntVar(&c.NumWorkers, "num-workers", 10, "number of workers to use for scan") f.IntVar(&c.MaxHosts, "max-hosts", 100, "maximum number of hosts to scan") f.StringVar(&c.Responses, "responses", "", "file to load OCSP responses from") f.StringVar(&c.Path, "path", "/", "Path on which the server will listen") f.StringVar(&c.CRL, "crl", "", "CRL URL Override") f.StringVar(&c.Password, "password", "0", "Password for accessing PKCS #12 data passed to bundler") f.StringVar(&c.Usage, "usage", "", "usage of private key") f.StringVar(&c.PGPPrivate, "pgp-private", "", "file to load a PGP Private key decryption") f.StringVar(&c.PGPName, "pgp-name", "", "PGP public key name, can be a comma-sepearted key name list") f.StringVar(&c.Serial, "serial", "", "certificate serial number") f.StringVar(&c.CNOverride, "cn", "", "certificate common name (CN)") f.StringVar(&c.AKI, "aki", "", "certificate issuer (authority) key identifier") f.StringVar(&c.DBConfigFile, "db-config", "", "certificate db configuration file") f.IntVar(&log.Level, "loglevel", log.LevelInfo, "Log level (0 = DEBUG, 5 = FATAL)") }
func FlagsForService(scfg *ServiceConfig, flagset *flag.FlagSet) { if scfg.DoozerConfig == nil { scfg.DoozerConfig = &DoozerConfig{} } FlagsForDoozer(scfg.DoozerConfig, flagset) flagset.StringVar(&scfg.UUID, "uuid", UUID(), "UUID for this service") flagset.StringVar(&scfg.Region, "region", GetDefaultEnvVar("SKYNET_REGION", DefaultRegion), "region service is located in") flagset.StringVar(&scfg.Version, "version", DefaultVersion, "version of service") flagset.DurationVar(&scfg.DoozerUpdateInterval, "dzupdate", DefaultDoozerUpdateInterval, "ns to wait before sending the next status update") }
func FlagsForClient(ccfg *ClientConfig, flagset *flag.FlagSet) { if ccfg.DoozerConfig == nil { ccfg.DoozerConfig = &DoozerConfig{} } FlagsForDoozer(ccfg.DoozerConfig, flagset) flagset.DurationVar(&ccfg.IdleTimeout, "timeout", DefaultIdleTimeout, "amount of idle time before timeout") flagset.IntVar(&ccfg.IdleConnectionsToInstance, "maxidle", DefaultIdleConnectionsToInstance, "maximum number of idle connections to a particular instance") flagset.IntVar(&ccfg.MaxConnectionsToInstance, "maxconns", DefaultMaxConnectionsToInstance, "maximum number of concurrent connections to a particular instance") }
func (cmd *GroupCreate) RegisterFlags(f *flag.FlagSet) { cmd.GroupThrottler.RegisterFlags(f) cmd.groupValues.RegisterFlags(f) f.StringVar(&cmd.file, "f", "", "JSON-encoded Machine specification file.") f.IntVar(&cmd.count, "n", 1, "Number of machines to be created.") f.BoolVar(&cmd.dry, "dry", false, "Dry run, tells the status of machines for the users.") f.DurationVar(&cmd.pullmongo, "pullmongo", 20*time.Minute, "Timeout for the build, pulls jMachine.status.state for status.") f.BoolVar(&cmd.eventer, "eventer", false, "Use kloud eventer instead of pulling MongoDB.") }
// registerFlags defines all cfssl command flags and associates their values with variables. func registerFlags(c *cli.Config, f *flag.FlagSet) { f.BoolVar(&c.List, "list", false, "list possible scanners") f.StringVar(&c.Family, "family", "", "scanner family regular expression") f.StringVar(&c.Scanner, "scanner", "", "scanner regular expression") f.DurationVar(&c.Timeout, "timeout", 5*time.Minute, "duration (ns, us, ms, s, m, h) to scan each host before timing out") f.StringVar(&c.CSVFile, "csv", "", "file containing CSV of hosts") f.IntVar(&c.NumWorkers, "num-workers", 10, "number of workers to use for scan") f.IntVar(&c.MaxHosts, "max-hosts", 100, "maximum number of hosts to scan") f.StringVar(&c.IP, "ip", "", "remote server ip") f.StringVar(&c.CABundleFile, "ca-bundle", "", "path to root certificate store") }
// registerFlags defines all cfssl command flags and associates their values with variables. func registerFlags(c *Config, f *flag.FlagSet) { f.StringVar(&c.Hostname, "hostname", "", "Hostname for the cert, could be a comma-separated hostname list") f.StringVar(&c.CertFile, "cert", "", "Client certificate that contains the public key") f.StringVar(&c.CSRFile, "csr", "", "Certificate signature request file for new public key") f.StringVar(&c.CAFile, "ca", "ca.pem", "CA used to sign the new certificate") f.StringVar(&c.CAKeyFile, "ca-key", "ca-key.pem", "CA private key") f.StringVar(&c.KeyFile, "key", "", "private key for the certificate") f.StringVar(&c.IntermediatesFile, "intermediates", "", "intermediate certs") f.StringVar(&c.CABundleFile, "ca-bundle", "/etc/cfssl/ca-bundle.crt", "Bundle to be used for root certificates pool") f.StringVar(&c.IntBundleFile, "int-bundle", "/etc/cfssl/int-bundle.crt", "Bundle to be used for intermediate certificates pool") f.StringVar(&c.Address, "address", "127.0.0.1", "Address to bind") f.IntVar(&c.Port, "port", 8888, "Port to bind") f.StringVar(&c.ConfigFile, "config", "", "path to configuration file") f.StringVar(&c.Profile, "profile", "", "signing profile to use") f.BoolVar(&c.IsCA, "initca", false, "initialise new CA") f.StringVar(&c.IntDir, "int-dir", "/etc/cfssl/intermediates", "specify intermediates directory") f.StringVar(&c.Flavor, "flavor", "ubiquitous", "Bundle Flavor: ubiquitous, optimal and force.") f.StringVar(&c.Metadata, "metadata", "/etc/cfssl/ca-bundle.crt.metadata", "Metadata file for root certificate presence. The content of the file is a json dictionary (k,v): each key k is SHA-1 digest of a root certificate while value v is a list of key store filenames.") f.StringVar(&c.Domain, "domain", "", "remote server domain name") f.StringVar(&c.IP, "ip", "", "remote server ip") f.StringVar(&c.Remote, "remote", "", "remote CFSSL server") f.StringVar(&c.Label, "label", "", "key label to use in remote CFSSL server") f.StringVar(&c.AuthKey, "authkey", "", "key to authenticate requests to remote CFSSL server") f.StringVar(&c.ResponderFile, "responder", "", "Certificate for OCSP responder") f.StringVar(&c.Status, "status", "good", "Status of the certificate: good, revoked, unknown") f.IntVar(&c.Reason, "reason", 0, "Reason code for revocation") f.StringVar(&c.RevokedAt, "revoked-at", "now", "Date of revocation (YYYY-MM-DD)") f.Int64Var(&c.Interval, "interval", int64(4*helpers.OneDay), "Interval between OCSP updates, in seconds (default: 4 days)") f.BoolVar(&c.List, "list", false, "list possible scanners") f.StringVar(&c.Family, "family", "", "scanner family regular expression") f.StringVar(&c.Scanner, "scanner", "", "scanner regular expression") f.DurationVar(&c.Timeout, "timeout", 0, "duration (ns, us, ms, s, m, h) to scan each host before timing out") f.StringVar(&c.Responses, "responses", "", "file to load OCSP responses from") f.StringVar(&c.Path, "path", "/", "Path on which the server will listen") f.StringVar(&c.Password, "password", "0", "Password for accessing PKCS #12 data passed to bundler") f.BoolVar(&c.UseLocal, "uselocal", false, "serve local static files as opposed to compiled ones") f.StringVar(&c.Usage, "usage", "dev", "usage of private key") if pkcs11.Enabled { f.StringVar(&c.Module, "pkcs11-module", "", "PKCS #11 module") f.StringVar(&c.Token, "pkcs11-token", "", "PKCS #11 token") f.StringVar(&c.PIN, "pkcs11-pin", os.Getenv("USER_PIN"), "PKCS #11 user PIN") f.StringVar(&c.PKCS11Label, "pkcs11-label", "", "PKCS #11 label") } }
func (m *gocoverdir) setupFlags(fs *flag.FlagSet) { fs.StringVar(&m.args.covermode, "covermode", "", "Same as -covermode in 'go test'. If running with -race, probably best not to set this.") fs.IntVar(&m.args.cpu, "cpu", -1, "Same as -cpu in 'go test'") fs.BoolVar(&m.args.race, "race", false, "Same as -race in 'go test'") fs.DurationVar(&m.args.timeout, "timeout", time.Second*3, "Same as -timeout in 'go test'") coveroutdir := os.Getenv("GOCOVERDIR_DIR") if coveroutdir == "" { coveroutdir = os.TempDir() } fs.StringVar(&m.args.coverprofile, "coverprofile", filepath.Join(coveroutdir, "coverage.out"), "Same as -coverprofile in 'go test', but will be a combined cover profile.") fs.IntVar(&m.args.depth, "depth", 10, "Directory depth to search.") fs.StringVar(&m.args.ignoreDirs, "ignoredirs", ".git:Godeps:vendor", "Color separated path of directories to ignore") fs.StringVar(&m.args.logfile, "logfile", "-", "Logfile to print debug output to. Empty means be silent unless there is an error, then dump to stderr") fs.BoolVar(&m.args.printcoverage, "printcoverage", false, "Print coverage amount to stdout") fs.Float64Var(&m.args.requiredcoverage, "requiredcoverage", 0.0, "Program will fatal if coverage is < this value") fs.BoolVar(&m.args.htmlcoverage, "htmlcoverage", false, "If true, will generate coverage output in a temp file") }
// Apply populates the flag given the flag set and environment func (f DurationFlag) Apply(set *flag.FlagSet) { if f.EnvVars != nil { for _, envVar := range f.EnvVars { if envVal := os.Getenv(envVar); envVal != "" { envValDuration, err := time.ParseDuration(envVal) if err == nil { f.Value = envValDuration break } } } } for _, name := range f.Names() { if f.Destination != nil { set.DurationVar(f.Destination, name, f.Value, f.Usage) continue } set.Duration(name, f.Value, f.Usage) } }
// Apply populates the flag given the flag set and environment func (f DurationFlag) Apply(set *flag.FlagSet) { if f.EnvVar != "" { for _, envVar := range strings.Split(f.EnvVar, ",") { envVar = strings.TrimSpace(envVar) if envVal := os.Getenv(envVar); envVal != "" { envValDuration, err := time.ParseDuration(envVal) if err == nil { f.Value = envValDuration break } } } } eachName(f.Name, func(name string) { if f.Destination != nil { set.DurationVar(f.Destination, name, f.Value, f.Usage) return } set.Duration(name, f.Value, f.Usage) }) }
func (c *config) addflags(s *flag.FlagSet) { timeout := s.Duration("timeout", -1, "Time after which the attempt(s) will be interrupted. "+validTimeUnits) s.DurationVar(timeout, "t", -1, "Shortcut for --timeout") c.timeout = timeout maxAttempts := s.Int("max-attempts", 1, "Maximum number of attempts to make (unlimitted: -1)") s.IntVar(maxAttempts, "a", 1, "Shortcut for --max-attempts") c.maxAttempts = maxAttempts delay := s.Duration("retry-delay", 1*time.Second, "Delay between attempts. "+validTimeUnits) s.DurationVar(delay, "d", 1*time.Second, "Shortcut for --retry-delay") c.retryDelay = delay attemptTimeout := s.Duration("attempt-timeout", -1, "Time after which each individual attempt will be interrupted. "+validTimeUnits) s.DurationVar(attemptTimeout, "at", -1, "Shortcut for --attempt-timeout") c.attemptTimeout = attemptTimeout }
// Add the flags accepted by run to the supplied flag set, returning the // variables into which the flags will parse. func populateFlagSet(fs *flag.FlagSet) (flags *flagStorage) { flags = new(flagStorage) flags.MountOptions = make(map[string]string) fs.Var( mountpkg.OptionValue(flags.MountOptions), "o", "Additional system-specific mount options. Be careful!") fs.Int64Var( &flags.Uid, "uid", -1, "If non-negative, the UID that owns all inodes. The default is the UID of "+ "the gcsfuse process.") fs.Int64Var( &flags.Gid, "gid", -1, "If non-negative, the GID that owns all inodes. The default is the GID of "+ "the gcsfuse process.") fs.UintVar( &flags.FileMode, "file-mode", 0644, "Permissions bits for files. Default is 0644.") fs.UintVar( &flags.DirMode, "dir-mode", 0755, "Permissions bits for directories. Default is 0755.") fs.StringVar( &flags.TempDir, "temp-dir", "", "The temporary directory in which to store local copies of GCS objects. "+ "If empty, the system default (probably /tmp) will be used.") fs.Int64Var( &flags.TempDirLimit, "temp-dir-bytes", 1<<31, "A desired limit on the number of bytes used in --temp-dir. May be "+ "exceeded for dirty files that have not been flushed or closed.") fs.Uint64Var( &flags.GCSChunkSize, "gcs-chunk-size", 1<<24, "If set to a non-zero value N, split up GCS objects into multiple "+ "chunks of size at most N when reading, and do not read or cache "+ "unnecessary chunks.") fs.BoolVar( &flags.ImplicitDirs, "implicit-dirs", false, "Implicitly define directories based on their content. See "+ "docs/semantics.md.") fs.DurationVar( &flags.StatCacheTTL, "stat-cache-ttl", time.Minute, "How long to cache StatObject results from GCS.") fs.DurationVar( &flags.TypeCacheTTL, "type-cache-ttl", time.Minute, "How long to cache name -> file/dir type mappings in directory inodes.") fs.Float64Var( &flags.OpRateLimitHz, "limit-ops-per-sec", 5.0, "If positive, a limit on the rate at which we send requests to GCS, "+ "measured over a 30-second window.") fs.Float64Var( &flags.EgressBandwidthLimitBytesPerSecond, "limit-bytes-per-sec", -1, "If positive, a limit on the GCS -> gcsfuse bandwidth for reading "+ "objects, measured over a 30-second window.") return }
func (cmd *s3log) Init(flags *flag.FlagSet, log *log.Logger) { flags.StringVar(&cmd.URI, "uri", "s3://koding-client/user", "") flags.DurationVar(&cmd.Time, "t", 7*24*time.Hour, "") }
// AddFlags adds configuration flags to the given FlagSet. func (c *Config) AddFlags(fs *flag.FlagSet) { fs.StringVar(&c.ServerAddr, "http", c.ServerAddr, "Address in form of ip:port to listen on for HTTP") fs.StringVar(&c.TLSServerAddr, "https", c.TLSServerAddr, "Address in form of ip:port to listen on for HTTPS") fs.StringVar(&c.TLSCertFile, "cert", c.TLSCertFile, "X.509 certificate file for HTTPS server") fs.StringVar(&c.TLSKeyFile, "key", c.TLSKeyFile, "X.509 key file for HTTPS server") fs.StringVar(&c.APIPrefix, "api-prefix", c.APIPrefix, "URL prefix for API endpoints") fs.StringVar(&c.CORSOrigin, "cors-origin", c.CORSOrigin, "CORS origin API endpoints") fs.DurationVar(&c.ReadTimeout, "read-timeout", c.ReadTimeout, "Read timeout for HTTP and HTTPS client conns") fs.DurationVar(&c.WriteTimeout, "write-timeout", c.WriteTimeout, "Write timeout for HTTP and HTTPS client conns") fs.StringVar(&c.PublicDir, "public", c.PublicDir, "Public directory to serve at the {prefix}/ endpoint") fs.StringVar(&c.DB, "db", c.DB, "IP database file or URL") fs.DurationVar(&c.UpdateInterval, "update", c.UpdateInterval, "Database update check interval") fs.DurationVar(&c.RetryInterval, "retry", c.RetryInterval, "Max time to wait before retrying to download database") fs.BoolVar(&c.UseXForwardedFor, "use-x-forwarded-for", c.UseXForwardedFor, "Use the X-Forwarded-For header when available (e.g. behind proxy)") fs.BoolVar(&c.Silent, "silent", c.Silent, "Disable HTTP and HTTPS log request details") fs.BoolVar(&c.LogToStdout, "logtostdout", c.LogToStdout, "Log to stdout instead of stderr") fs.BoolVar(&c.LogTimestamp, "logtimestamp", c.LogTimestamp, "Prefix non-access logs with timestamp") fs.StringVar(&c.RedisAddr, "redis", c.RedisAddr, "Redis address in form of host:port[,host:port] for quota") fs.DurationVar(&c.RedisTimeout, "redis-timeout", c.RedisTimeout, "Redis read/write timeout") fs.StringVar(&c.MemcacheAddr, "memcache", c.MemcacheAddr, "Memcache address in form of host:port[,host:port] for quota") fs.DurationVar(&c.MemcacheTimeout, "memcache-timeout", c.MemcacheTimeout, "Memcache read/write timeout") fs.StringVar(&c.RateLimitBackend, "quota-backend", c.RateLimitBackend, "Backend for rate limiter: map, redis, or memcache") fs.Uint64Var(&c.RateLimitLimit, "quota-max", c.RateLimitLimit, "Max requests per source IP per interval; set 0 to turn quotas off") fs.DurationVar(&c.RateLimitInterval, "quota-interval", c.RateLimitInterval, "Quota expiration interval, per source IP querying the API") fs.StringVar(&c.InternalServerAddr, "internal-server", c.InternalServerAddr, "Address in form of ip:port to listen on for metrics and pprof") }
// Register fields in the given struct that have the tag `flag:"name,desc"`. // Nested structs are supported as long as the field is a struct value field and not pointer to a struct. // Exception to this is the use of StringList which needs to be a pointer. The StringList type implements // the Set and String methods required by the flag package and is dynamically allocated when registering its flag. // See the test case for example. func RegisterFlags(name string, val interface{}, fs *flag.FlagSet) { t := reflect.TypeOf(val).Elem() v := reflect.Indirect(reflect.ValueOf(val)) // the actual value of val for i := 0; i < t.NumField(); i++ { field := t.Field(i) if field.Anonymous && field.Type.Kind() == reflect.Struct { RegisterFlags(name+"."+field.Name, v.Field(i).Addr().Interface(), fs) continue } // See https://golang.org/ref/spec#Uniqueness_of_identifiers exported := field.PkgPath == "" if exported { tag := field.Tag spec := tag.Get("flag") if spec == "" { continue } // Bind the flag based on the tag spec f, d := "", "" p := strings.Split(spec, ",") if len(p) == 1 { // Just one field, use it as description f = fmt.Sprintf("%s.%s", name, strings.ToLower(field.Name)) d = strings.Trim(p[0], " ") } else { // More than one, the first is the name of the flag f = strings.Trim(p[0], " ") d = strings.Trim(p[1], " ") } fv := v.Field(i).Interface() if v.Field(i).CanAddr() { ptr := v.Field(i).Addr().Interface() // The pointer value switch fv := fv.(type) { case bool: fs.BoolVar(ptr.(*bool), f, fv, d) case string: fs.StringVar(ptr.(*string), f, fv, d) case uint: fs.UintVar(ptr.(*uint), f, fv, d) case uint64: fs.Uint64Var(ptr.(*uint64), f, fv, d) case int64: fs.Int64Var(ptr.(*int64), f, fv, d) case int: fs.IntVar(ptr.(*int), f, fv, d) case float64: fs.Float64Var(ptr.(*float64), f, fv, d) case time.Duration: fs.DurationVar(ptr.(*time.Duration), f, fv, d) case []time.Duration: if len(fv) == 0 { // Special case where we allocate an empty list - otherwise it's default. v.Field(i).Set(reflect.ValueOf([]time.Duration{})) } fs.Var(&durationListProxy{list: ptr.(*[]time.Duration)}, f, d) default: // We only register if the field is a concrete vale and not a pointer // since we don't automatically allocate zero value structs to fill the field slot. switch field.Type.Kind() { case reflect.String: fs.Var(&aliasProxy{ fieldType: field.Type, ptr: ptr, fromString: stringFromString, toString: func(v interface{}) string { return fmt.Sprint("%v", v) }, }, f, d) case reflect.Bool: fs.Var(&aliasProxy{ fieldType: field.Type, ptr: ptr, fromString: boolFromString, toString: func(v interface{}) string { return fmt.Sprint("%v", v) }, }, f, d) case reflect.Float64: fs.Var(&aliasProxy{ fieldType: field.Type, ptr: ptr, fromString: float64FromString, toString: func(v interface{}) string { return fmt.Sprint("%v", v) }, }, f, d) case reflect.Int: fs.Var(&aliasProxy{ fieldType: field.Type, ptr: ptr, fromString: intFromString, toString: func(v interface{}) string { return fmt.Sprint("%v", v) }, }, f, d) case reflect.Int64: fs.Var(&aliasProxy{ fieldType: field.Type, ptr: ptr, fromString: int64FromString, toString: func(v interface{}) string { return fmt.Sprint("%v", v) }, }, f, d) case reflect.Uint: fs.Var(&aliasProxy{ fieldType: field.Type, ptr: ptr, fromString: uintFromString, toString: func(v interface{}) string { return fmt.Sprint("%v", v) }, }, f, d) case reflect.Uint64: fs.Var(&aliasProxy{ fieldType: field.Type, ptr: ptr, fromString: uint64FromString, toString: func(v interface{}) string { return fmt.Sprint("%v", v) }, }, f, d) case reflect.Struct: RegisterFlags(f, ptr, fs) case reflect.Slice: et := field.Type.Elem() proxy := &sliceProxy{ fieldType: field.Type, elemType: et, slice: ptr, defaults: reflect.ValueOf(fv).Len() > 0, toString: func(v interface{}) string { return fmt.Sprint("%v", v) }, } fs.Var(proxy, f, d) switch { // Checking for string is placed here first because other types are // convertible to string as well. case reflect.TypeOf(string("")).ConvertibleTo(et): proxy.fromString = stringFromString case reflect.TypeOf(bool(true)).ConvertibleTo(et): proxy.fromString = boolFromString case reflect.TypeOf(float64(1.)).ConvertibleTo(et): proxy.fromString = float64FromString case reflect.TypeOf(int(1)).ConvertibleTo(et): proxy.fromString = intFromString case reflect.TypeOf(int64(1)).ConvertibleTo(et): proxy.fromString = int64FromString case reflect.TypeOf(uint(1)).ConvertibleTo(et): proxy.fromString = uintFromString case reflect.TypeOf(uint64(1)).ConvertibleTo(et): proxy.fromString = uint64FromString case reflect.TypeOf(time.Second).AssignableTo(et): proxy.fromString = durationFromString } } } } } } }