1package config
2
3import (
4	"flag"
5	"fmt"
6	"time"
7)
8
9// AddFlags adds the command line flags to the FlagSet, and sets the appropriate field in
10// LoadOpts.FlagValues as the value receiver.
11func AddFlags(fs *flag.FlagSet, f *LoadOpts) {
12	add := func(p interface{}, name, help string) {
13		switch x := p.(type) {
14		case **bool:
15			fs.Var(newBoolPtrValue(x), name, help)
16		case **time.Duration:
17			fs.Var(newDurationPtrValue(x), name, help)
18		case **int:
19			fs.Var(newIntPtrValue(x), name, help)
20		case **string:
21			fs.Var(newStringPtrValue(x), name, help)
22		case *[]string:
23			fs.Var(newStringSliceValue(x), name, help)
24		case *map[string]string:
25			fs.Var(newStringMapValue(x), name, help)
26		default:
27			panic(fmt.Sprintf("invalid type: %T", p))
28		}
29	}
30
31	// command line flags ordered by flag name
32	add(&f.FlagValues.AdvertiseAddrLAN, "advertise", "Sets the advertise address to use.")
33	add(&f.FlagValues.AdvertiseAddrWAN, "advertise-wan", "Sets address to advertise on WAN instead of -advertise address.")
34	add(&f.FlagValues.BindAddr, "bind", "Sets the bind address for cluster communication.")
35	add(&f.FlagValues.Ports.Server, "server-port", "Sets the server port to listen on.")
36	add(&f.FlagValues.Bootstrap, "bootstrap", "Sets server to bootstrap mode.")
37	add(&f.FlagValues.BootstrapExpect, "bootstrap-expect", "Sets server to expect bootstrap mode.")
38	add(&f.FlagValues.ClientAddr, "client", "Sets the address to bind for client access. This includes RPC, DNS, HTTP, HTTPS and gRPC (if configured).")
39	add(&f.FlagValues.CheckOutputMaxSize, "check_output_max_size", "Sets the maximum output size for checks on this agent")
40	add(&f.ConfigFiles, "config-dir", "Path to a directory to read configuration files from. This will read every file ending in '.json' as configuration in this directory in alphabetical order. Can be specified multiple times.")
41	add(&f.ConfigFiles, "config-file", "Path to a file in JSON or HCL format with a matching file extension. Can be specified multiple times.")
42	fs.StringVar(&f.ConfigFormat, "config-format", "", "Config files are in this format irrespective of their extension. Must be 'hcl' or 'json'")
43	add(&f.FlagValues.DataDir, "data-dir", "Path to a data directory to store agent state.")
44	add(&f.FlagValues.Datacenter, "datacenter", "Datacenter of the agent.")
45	add(&f.FlagValues.DefaultQueryTime, "default-query-time", "the amount of time a blocking query will wait before Consul will force a response. This value can be overridden by the 'wait' query parameter.")
46	add(&f.DevMode, "dev", "Starts the agent in development mode.")
47	add(&f.FlagValues.DisableHostNodeID, "disable-host-node-id", "Setting this to true will prevent Consul from using information from the host to generate a node ID, and will cause Consul to generate a random node ID instead.")
48	add(&f.FlagValues.DisableKeyringFile, "disable-keyring-file", "Disables the backing up of the keyring to a file.")
49	add(&f.FlagValues.Ports.DNS, "dns-port", "DNS port to use.")
50	add(&f.FlagValues.DNSDomain, "domain", "Domain to use for DNS interface.")
51	add(&f.FlagValues.DNSAltDomain, "alt-domain", "Alternate domain to use for DNS interface.")
52	add(&f.FlagValues.EnableScriptChecks, "enable-script-checks", "Enables health check scripts.")
53	add(&f.FlagValues.EnableLocalScriptChecks, "enable-local-script-checks", "Enables health check scripts from configuration file.")
54	add(&f.FlagValues.HTTPConfig.AllowWriteHTTPFrom, "allow-write-http-from", "Only allow write endpoint calls from given network. CIDR format, can be specified multiple times.")
55	add(&f.FlagValues.EncryptKey, "encrypt", "Provides the gossip encryption key.")
56	add(&f.FlagValues.Ports.GRPC, "grpc-port", "Sets the gRPC API port to listen on (currently needed for Envoy xDS only).")
57	add(&f.FlagValues.Ports.HTTP, "http-port", "Sets the HTTP API port to listen on.")
58	add(&f.FlagValues.Ports.HTTPS, "https-port", "Sets the HTTPS API port to listen on.")
59	add(&f.FlagValues.StartJoinAddrsLAN, "join", "Address of an agent to join at start time. Can be specified multiple times.")
60	add(&f.FlagValues.StartJoinAddrsWAN, "join-wan", "Address of an agent to join -wan at start time. Can be specified multiple times.")
61	add(&f.FlagValues.LogLevel, "log-level", "Log level of the agent.")
62	add(&f.FlagValues.LogJSON, "log-json", "Output logs in JSON format.")
63	add(&f.FlagValues.LogFile, "log-file", "Path to the file the logs get written to")
64	add(&f.FlagValues.LogRotateBytes, "log-rotate-bytes", "Maximum number of bytes that should be written to a log file")
65	add(&f.FlagValues.LogRotateDuration, "log-rotate-duration", "Time after which log rotation needs to be performed")
66	add(&f.FlagValues.LogRotateMaxFiles, "log-rotate-max-files", "Maximum number of log file archives to keep")
67	add(&f.FlagValues.MaxQueryTime, "max-query-time", "the maximum amount of time a blocking query can wait before Consul will force a response. Consul applies jitter to the wait time. The jittered time will be capped to MaxQueryTime.")
68	add(&f.FlagValues.NodeName, "node", "Name of this node. Must be unique in the cluster.")
69	add(&f.FlagValues.NodeID, "node-id", "A unique ID for this node across space and time. Defaults to a randomly-generated ID that persists in the data-dir.")
70	add(&f.FlagValues.NodeMeta, "node-meta", "An arbitrary metadata key/value pair for this node, of the format `key:value`. Can be specified multiple times.")
71	add(&f.FlagValues.ReadReplica, "non-voting-server", "(Enterprise-only) DEPRECATED: -read-replica should be used instead")
72	add(&f.FlagValues.ReadReplica, "read-replica", "(Enterprise-only) This flag is used to make the server not participate in the Raft quorum, and have it only receive the data replication stream. This can be used to add read scalability to a cluster in cases where a high volume of reads to servers are needed.")
73	add(&f.FlagValues.PidFile, "pid-file", "Path to file to store agent PID.")
74	add(&f.FlagValues.RPCProtocol, "protocol", "Sets the protocol version. Defaults to latest.")
75	add(&f.FlagValues.RaftProtocol, "raft-protocol", "Sets the Raft protocol version. Defaults to latest.")
76	add(&f.FlagValues.DNSRecursors, "recursor", "Address of an upstream DNS server. Can be specified multiple times.")
77	add(&f.FlagValues.PrimaryGateways, "primary-gateway", "Address of a mesh gateway in the primary datacenter to use to bootstrap WAN federation at start time with retries enabled. Can be specified multiple times.")
78	add(&f.FlagValues.RejoinAfterLeave, "rejoin", "Ignores a previous leave and attempts to rejoin the cluster.")
79	add(&f.FlagValues.RetryJoinIntervalLAN, "retry-interval", "Time to wait between join attempts.")
80	add(&f.FlagValues.RetryJoinIntervalWAN, "retry-interval-wan", "Time to wait between join -wan attempts.")
81	add(&f.FlagValues.RetryJoinLAN, "retry-join", "Address of an agent to join at start time with retries enabled. Can be specified multiple times.")
82	add(&f.FlagValues.RetryJoinWAN, "retry-join-wan", "Address of an agent to join -wan at start time with retries enabled. Can be specified multiple times.")
83	add(&f.FlagValues.RetryJoinMaxAttemptsLAN, "retry-max", "Maximum number of join attempts. Defaults to 0, which will retry indefinitely.")
84	add(&f.FlagValues.RetryJoinMaxAttemptsWAN, "retry-max-wan", "Maximum number of join -wan attempts. Defaults to 0, which will retry indefinitely.")
85	add(&f.FlagValues.SerfAllowedCIDRsLAN, "serf-lan-allowed-cidrs", "Networks (eg: 192.168.1.0/24) allowed for Serf LAN. Can be specified multiple times.")
86	add(&f.FlagValues.SerfAllowedCIDRsWAN, "serf-wan-allowed-cidrs", "Networks (eg: 192.168.1.0/24) allowed for Serf WAN (other datacenters). Can be specified multiple times.")
87	add(&f.FlagValues.SerfBindAddrLAN, "serf-lan-bind", "Address to bind Serf LAN listeners to.")
88	add(&f.FlagValues.Ports.SerfLAN, "serf-lan-port", "Sets the Serf LAN port to listen on.")
89	add(&f.FlagValues.SegmentName, "segment", "(Enterprise-only) Sets the network segment to join.")
90	add(&f.FlagValues.SerfBindAddrWAN, "serf-wan-bind", "Address to bind Serf WAN listeners to.")
91	add(&f.FlagValues.Ports.SerfWAN, "serf-wan-port", "Sets the Serf WAN port to listen on.")
92	add(&f.FlagValues.ServerMode, "server", "Switches agent to server mode.")
93	add(&f.FlagValues.EnableSyslog, "syslog", "Enables logging to syslog.")
94	add(&f.FlagValues.UIConfig.Enabled, "ui", "Enables the built-in static web UI server.")
95	add(&f.FlagValues.UIConfig.ContentPath, "ui-content-path", "Sets the external UI path to a string. Defaults to: /ui/ ")
96	add(&f.FlagValues.UIConfig.Dir, "ui-dir", "Path to directory containing the web UI resources.")
97	add(&f.HCL, "hcl", "hcl config fragment. Can be specified multiple times.")
98}
99