configflags

package
v1.3.1-rc1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllowListLocalPathsFlags = []Definition{
	{
		FlagName:     "allow-listed-local-paths",
		ConfigPath:   types.NodeAllowListedLocalPaths,
		DefaultValue: Default.Node.AllowListedLocalPaths,
		Description:  "Local paths that are allowed to be mounted into jobs",
	},
}
View Source
var CapacityFlags = []Definition{
	{
		FlagName:             "ignore-physical-resource-limits",
		ConfigPath:           types.NodeComputeCapacityIgnorePhysicalResourceLimits,
		DefaultValue:         Default.Node.Compute.Capacity.IgnorePhysicalResourceLimits,
		Description:          `When set the compute node will ignore is physical resource limits`,
		EnvironmentVariables: []string{"BACALHAU_CAPACITY_MANAGER_OVER_COMMIT"},
	},
	{
		FlagName:     "limit-total-cpu",
		ConfigPath:   types.NodeComputeCapacityTotalResourceLimitsCPU,
		DefaultValue: Default.Node.Compute.Capacity.TotalResourceLimits.CPU,
		Description:  `Total CPU core limit to run all jobs (e.g. 500m, 2, 8).`,
	},
	{
		FlagName:     "limit-total-memory",
		ConfigPath:   types.NodeComputeCapacityTotalResourceLimitsMemory,
		DefaultValue: Default.Node.Compute.Capacity.TotalResourceLimits.Memory,
		Description:  `Total Memory limit to run all jobs  (e.g. 500Mb, 2Gb, 8Gb).`,
	},
	{
		FlagName:     "limit-total-gpu",
		ConfigPath:   types.NodeComputeCapacityTotalResourceLimitsGPU,
		DefaultValue: Default.Node.Compute.Capacity.TotalResourceLimits.GPU,
		Description:  `Total GPU limit to run all jobs (e.g. 1, 2, or 8).`,
	},
	{
		FlagName:     "limit-job-cpu",
		ConfigPath:   types.NodeComputeCapacityJobResourceLimitsCPU,
		DefaultValue: Default.Node.Compute.Capacity.JobResourceLimits.CPU,
		Description:  `Job CPU core limit to run all jobs (e.g. 500m, 2, 8).`,
	},
	{
		FlagName:     "limit-job-memory",
		ConfigPath:   types.NodeComputeCapacityDefaultJobResourceLimitsMemory,
		DefaultValue: Default.Node.Compute.Capacity.JobResourceLimits.Memory,
		Description:  `Job Memory limit to run all jobs  (e.g. 500Mb, 2Gb, 8Gb).`,
	},
	{
		FlagName:     "limit-job-gpu",
		ConfigPath:   types.NodeComputeCapacityJobResourceLimitsGPU,
		DefaultValue: Default.Node.Compute.Capacity.JobResourceLimits.GPU,
		Description:  `Job GPU limit to run all jobs (e.g. 1, 2, or 8).`,
	},
}
View Source
var ClientAPIFlags = []Definition{
	{
		FlagName:     "api-host",
		DefaultValue: Default.Node.ClientAPI.Host,
		ConfigPath:   types.NodeClientAPIHost,
		Description: `The host for the client and server to communicate on (via REST).
Ignored if BACALHAU_API_HOST environment variable is set.`,
		EnvironmentVariables: []string{"BACALHAU_API_HOST"},
	},
	{
		FlagName:     "api-port",
		DefaultValue: Default.Node.ClientAPI.Port,
		ConfigPath:   types.NodeClientAPIPort,
		Description: `The port for the client and server to communicate on (via REST).
Ignored if BACALHAU_API_PORT environment variable is set.`,
		EnvironmentVariables: []string{"BACALHAU_API_PORT"},
	},
	{
		FlagName:             "tls",
		DefaultValue:         Default.Node.ClientAPI.ClientTLS.UseTLS,
		ConfigPath:           types.NodeClientAPIClientTLSUseTLS,
		Description:          `Instructs the client to use TLS`,
		EnvironmentVariables: []string{"BACALHAU_API_TLS"},
	},
	{
		FlagName:     "cacert",
		DefaultValue: Default.Node.ClientAPI.ClientTLS.CACert,
		ConfigPath:   types.NodeClientAPIClientTLSCACert,
		Description: `The location of a CA certificate file when self-signed certificates
	are used by the server`,
		EnvironmentVariables: []string{"BACALHAU_API_CACERT"},
	},
	{
		FlagName:             "insecure",
		DefaultValue:         Default.Node.ClientAPI.ClientTLS.Insecure,
		ConfigPath:           types.NodeClientAPIClientTLSInsecure,
		Description:          `Enables TLS but does not verify certificates`,
		EnvironmentVariables: []string{"BACALHAU_API_INSECURE"},
	},
}
View Source
var ComputeStorageFlags = []Definition{
	{
		FlagName:             "compute-execution-store-type",
		ConfigPath:           types.NodeComputeExecutionStoreType,
		DefaultValue:         Default.Node.Compute.ExecutionStore.Type,
		Description:          "The type of store used by the compute node (BoltDB)",
		EnvironmentVariables: []string{"BACALHAU_COMPUTE_STORE_TYPE"},
	},
	{
		FlagName:             "compute-execution-store-path",
		ConfigPath:           types.NodeComputeExecutionStorePath,
		DefaultValue:         Default.Node.Compute.ExecutionStore.Path,
		Description:          "The path used for the compute execution store when using BoltDB",
		EnvironmentVariables: []string{"BACALHAU_COMPUTE_STORE_PATH"},
	},
}
View Source
var ComputeTimeoutFlags = []Definition{
	{
		FlagName:     "job-execution-timeout-bypass-client-id",
		ConfigPath:   types.NodeComputeJobTimeoutsJobExecutionTimeoutClientIDBypassList,
		DefaultValue: Default.Node.Compute.JobTimeouts.JobExecutionTimeoutClientIDBypassList,
		Description:  `List of IDs of clients that are allowed to bypass the job execution timeout check`,
	},
	{
		FlagName:     "job-negotiation-timeout",
		ConfigPath:   types.NodeComputeJobTimeoutsJobNegotiationTimeout,
		DefaultValue: Default.Node.Compute.JobTimeouts.JobNegotiationTimeout,
		Description:  `Timeout value to hold a bid for a job.`,
	},
	{
		FlagName:     "min-job-execution-timeout",
		ConfigPath:   types.NodeComputeJobTimeoutsMinJobExecutionTimeout,
		DefaultValue: Default.Node.Compute.JobTimeouts.MinJobExecutionTimeout,
		Description:  `The minimum execution timeout this compute node supports. Jobs with lower timeout requirements will not be bid on.`,
	},
	{
		FlagName:     "max-job-execution-timeout",
		ConfigPath:   types.NodeComputeJobTimeoutsMaxJobExecutionTimeout,
		DefaultValue: Default.Node.Compute.JobTimeouts.MaxJobExecutionTimeout,
		Description:  `The maximum execution timeout this compute node supports. Jobs with higher timeout requirements will not be bid on.`,
	},
	{
		FlagName:     "default-job-execution-timeout",
		ConfigPath:   types.NodeComputeJobTimeoutsJobExecutionTimeoutClientIDBypassList,
		DefaultValue: Default.Node.Compute.JobTimeouts.DefaultJobExecutionTimeout,
		Description:  `default value for the execution timeout this compute node will assign to jobs with no timeout requirement defined.`,
	},
}

Default is the default value used by flags. It will be overridden by any values in the config file. We can configure the default flag values by setting `Default` to a different config environment.

View Source
var DisabledFeatureFlags = []Definition{
	{
		FlagName:     "disable-engine",
		ConfigPath:   types.NodeDisabledFeaturesEngines,
		DefaultValue: Default.Node.DisabledFeatures.Engines,
		Description:  "Engine types to disable",
	},
	{
		FlagName:     "disabled-publisher",
		ConfigPath:   types.NodeDisabledFeaturesPublishers,
		DefaultValue: Default.Node.DisabledFeatures.Publishers,
		Description:  "Publisher types to disable",
	},
	{
		FlagName:     "disable-storage",
		ConfigPath:   types.NodeDisabledFeaturesStorages,
		DefaultValue: Default.Node.DisabledFeatures.Storages,
		Description:  "Storage types to disable",
	},
}
View Source
var DockerManifestCacheFlags = []Definition{
	{
		FlagName:             "docker-manifest-cache-size",
		ConfigPath:           types.NodeComputeManifestCacheSize,
		DefaultValue:         Default.Node.Compute.ManifestCache.Size,
		Description:          `Specifies the number of items that can be held in the manifest cache`,
		EnvironmentVariables: []string{"BACALHAU_DOCKER_MANIFEST_CACHE_SIZE"},
	},
	{
		FlagName:             "docker-manifest-cache-duration",
		ConfigPath:           types.NodeComputeManifestCacheDuration,
		DefaultValue:         Default.Node.Compute.ManifestCache.Duration,
		Description:          `The default time-to-live for each record in the manifest cache`,
		EnvironmentVariables: []string{"BACALHAU_DOCKER_MANIFEST_CACHE_DURATION"},
	},
	{
		FlagName:             "docker-manifest-cache-frequency",
		ConfigPath:           types.NodeComputeManifestCacheFrequency,
		DefaultValue:         Default.Node.Compute.ManifestCache.Frequency,
		Description:          `The frequency that the checks for stale records is performed`,
		EnvironmentVariables: []string{"BACALHAU_DOCKER_MANIFEST_CACHE_FREQUENCY"},
	},
}
View Source
var IPFSFlags = []Definition{
	{
		FlagName:             "ipfs-swarm-addrs",
		ConfigPath:           types.NodeIPFSSwarmAddresses,
		DefaultValue:         Default.Node.IPFS.SwarmAddresses,
		Description:          "IPFS multiaddress to connect the in-process IPFS node to - cannot be used with --ipfs-connect.",
		EnvironmentVariables: []string{"BACALHAU_IPFS_SWARM_ADDRESSES"},
		Deprecated:           true,
		DeprecatedMessage:    ipfsEmbeddedDeprecationMessage,
	},
	{
		FlagName:             "ipfs-swarm-key",
		ConfigPath:           types.NodeIPFSSwarmKeyPath,
		DefaultValue:         Default.Node.IPFS.SwarmKeyPath,
		Description:          "Optional IPFS swarm key required to connect to a private IPFS swarm",
		EnvironmentVariables: []string{"BACALHAU_IPFS_SWARM_KEY"},
		Deprecated:           true,
		DeprecatedMessage:    ipfsEmbeddedDeprecationMessage,
	},
	{
		FlagName:     "ipfs-connect",
		ConfigPath:   types.NodeIPFSConnect,
		DefaultValue: Default.Node.IPFS.Connect,
		Description:  "The ipfs host multiaddress to connect to, otherwise an in-process IPFS node will be created if not set.",
	},
	{
		FlagName:     "private-internal-ipfs",
		ConfigPath:   types.NodeIPFSPrivateInternal,
		DefaultValue: Default.Node.IPFS.PrivateInternal,
		Description: "Whether the in-process IPFS node should auto-discover other nodes, including the public IPFS network - " +
			"cannot be used with --ipfs-connect. " +
			"Use \"--private-internal-ipfs=false\" to disable. " +
			"To persist a local Ipfs node, set BACALHAU_SERVE_IPFS_PATH to a valid path.",
		Deprecated:        true,
		DeprecatedMessage: ipfsEmbeddedDeprecationMessage,
	},
	{
		FlagName:             "ipfs-serve-path",
		ConfigPath:           types.NodeIPFSServePath,
		DefaultValue:         Default.Node.IPFS.ServePath,
		Description:          "path local Ipfs node will persist data to",
		EnvironmentVariables: []string{"BACALHAU_SERVE_IPFS_PATH"},
		Deprecated:           true,
		DeprecatedMessage:    ipfsEmbeddedDeprecationMessage,
	},
	{
		FlagName:          "ipfs-profile",
		ConfigPath:        types.NodeIPFSProfile,
		DefaultValue:      Default.Node.IPFS.Profile,
		Description:       "profile for internal IPFS node",
		Deprecated:        true,
		DeprecatedMessage: ipfsEmbeddedDeprecationMessage,
	},
	{
		FlagName:          "ipfs-swarm-listen-addresses",
		ConfigPath:        types.NodeIPFSSwarmListenAddresses,
		DefaultValue:      Default.Node.IPFS.SwarmListenAddresses,
		Description:       "addresses the internal IPFS node will listen on for swarm connections",
		Deprecated:        true,
		DeprecatedMessage: ipfsEmbeddedDeprecationMessage,
	},
	{
		FlagName:          "ipfs-gateway-listen-addresses",
		ConfigPath:        types.NodeIPFSGatewayListenAddresses,
		DefaultValue:      Default.Node.IPFS.GatewayListenAddresses,
		Description:       "addresses the internal IPFS node will listen on for gateway connections",
		Deprecated:        true,
		DeprecatedMessage: ipfsEmbeddedDeprecationMessage,
	},
	{
		FlagName:          "ipfs-api-listen-addresses",
		ConfigPath:        types.NodeIPFSAPIListenAddresses,
		DefaultValue:      Default.Node.IPFS.APIListenAddresses,
		Description:       "addresses the internal IPFS node will listen on for API connections",
		Deprecated:        true,
		DeprecatedMessage: ipfsEmbeddedDeprecationMessage,
	},
}
View Source
var JobSelectionFlags = []Definition{
	{
		FlagName:     "job-selection-data-locality",
		ConfigPath:   types.NodeComputeJobSelectionLocality,
		DefaultValue: Default.Node.Compute.JobSelection.Locality,
		Description:  `Only accept jobs that reference data we have locally ("local") or anywhere ("anywhere").`,
	},
	{
		FlagName:     "job-selection-reject-stateless",
		ConfigPath:   types.NodeComputeJobSelectionRejectStatelessJobs,
		DefaultValue: Default.Node.Compute.JobSelection.RejectStatelessJobs,
		Description:  `Reject jobs that don't specify any data.`,
	},
	{
		FlagName:     "job-selection-accept-networked",
		ConfigPath:   types.NodeComputeJobSelectionAcceptNetworkedJobs,
		DefaultValue: Default.Node.Compute.JobSelection.AcceptNetworkedJobs,
		Description:  `Accept jobs that require network access.`,
	},
	{
		FlagName:     "job-selection-probe-http",
		ConfigPath:   types.NodeComputeJobSelectionProbeHTTP,
		DefaultValue: Default.Node.Compute.JobSelection.ProbeHTTP,
		Description:  `Use the result of a HTTP POST to decide if we should take on the job.`,
	},
	{
		FlagName:     "job-selection-probe-exec",
		ConfigPath:   types.NodeComputeJobSelectionProbeExec,
		DefaultValue: Default.Node.Compute.JobSelection.ProbeExec,
		Description:  `Use the result of a exec an external program to decide if we should take on the job.`,
	},
}
View Source
var JobTranslationFlags = []Definition{
	{
		FlagName:     "requester-job-translation-enabled",
		DefaultValue: Default.Node.Requester.TranslationEnabled,
		ConfigPath:   types.NodeRequesterTranslationEnabled,
		Description:  `Whether jobs should be translated at the requester node or not. Default: false`,
	},
}
View Source
var LabelFlags = []Definition{
	{
		FlagName:     "labels",
		ConfigPath:   types.NodeLabels,
		DefaultValue: Default.Node.Labels,

		Description: `Labels to be associated with the node that can be used for node selection and filtering. (e.g. --labels key1=value1,key2=value2)`,
	},
}
View Source
var Libp2pFlags = []Definition{
	{
		FlagName:     "peer",
		ConfigPath:   types.NodeLibp2pPeerConnect,
		DefaultValue: Default.Node.Libp2p.PeerConnect,
		Description: `A comma-separated list of libp2p multiaddress to connect to. ` +
			`Use "none" to avoid connecting to any peer, ` +
			`"env" to connect to the default peer list of your active environment (see BACALHAU_ENVIRONMENT env var).`,
		Deprecated: true,
		DeprecatedMessage: "The libp2p transport will be deprecated in a future version in favour of using " +
			"--orchestrators to specify a requester node to connect to.",
	},
	{
		FlagName:     "swarm-port",
		ConfigPath:   types.NodeLibp2pSwarmPort,
		DefaultValue: Default.Node.Libp2p.SwarmPort,
		Description:  `The port to listen on for swarm connections.`,
		Deprecated:   true,
		DeprecatedMessage: "The libp2p transport will be deprecated in a future version in favour of using " +
			"--orchestrators to specify a requester node to connect to.",
	},
}
View Source
var LocalPublisherFlags = []Definition{
	{
		FlagName:     "local-publisher-address",
		DefaultValue: Default.Node.Compute.LocalPublisher.Address,
		ConfigPath:   types.NodeComputeLocalPublisherAddress,
		Description:  `The address for the local publisher's server to bind to`,
	},
	{
		FlagName:     "local-publisher-port",
		DefaultValue: Default.Node.Compute.LocalPublisher.Port,
		ConfigPath:   types.NodeComputeLocalPublisherPort,
		Description:  `The port for the local publisher's server to bind to (default: 6001)`,
	},
	{
		FlagName:     "local-publisher-directory",
		DefaultValue: Default.Node.Compute.LocalPublisher.Directory,
		ConfigPath:   types.NodeComputeLocalPublisherDirectory,
		Description:  `The directory where the local publisher will store content`,
	},
}
View Source
var LogFlags = []Definition{
	{
		FlagName:     "log-mode",
		DefaultValue: logger.LogModeDefault,
		ConfigPath:   types.NodeLoggingMode,
		Description:  `Log format: 'default','station','json','combined','event'`,
	},
}
View Source
var NetworkFlags = []Definition{
	{
		FlagName:          "network",
		ConfigPath:        types.NodeNetworkType,
		DefaultValue:      Default.Node.Network.Type,
		Description:       `Inter-node network layer type (e.g. nats, libp2p).`,
		Deprecated:        true,
		DeprecatedMessage: "The libp2p transport will be deprecated in a future version in favor of NATS",
	},
	{
		FlagName:     "network-port",
		ConfigPath:   types.NodeNetworkPort,
		DefaultValue: Default.Node.Network.Port,
		Description:  `Port to listen for connections from other nodes. Applies to orchestrator nodes.`,
	},
	{
		FlagName:     "network-store-dir",
		ConfigPath:   types.NodeNetworkStoreDir,
		DefaultValue: Default.Node.Network.StoreDir,
		Description:  `Directory that network can use for storage`,
	},
	{
		FlagName:     "orchestrators",
		ConfigPath:   types.NodeNetworkOrchestrators,
		DefaultValue: Default.Node.Network.Orchestrators,
		Description:  `Comma-separated list of orchestrators to connect to. Applies to compute nodes.`,
	},
	{
		FlagName:     "advertised-address",
		ConfigPath:   types.NodeNetworkAdvertisedAddress,
		DefaultValue: Default.Node.Network.AdvertisedAddress,
		Description:  `Address to advertise to compute nodes to connect to.`,
	},
	{
		FlagName:     "cluster-name",
		ConfigPath:   types.NodeNetworkClusterName,
		DefaultValue: Default.Node.Network.Cluster.Name,
		Description:  `Name of the cluster to join.`,
	},
	{
		FlagName:     "cluster-port",
		ConfigPath:   types.NodeNetworkClusterPort,
		DefaultValue: Default.Node.Network.Cluster.Port,
		Description:  `Port to listen for connections from other orchestrators to form a cluster.`,
	},
	{
		FlagName:     "cluster-advertised-address",
		ConfigPath:   types.NodeNetworkClusterAdvertisedAddress,
		DefaultValue: Default.Node.Network.Cluster.AdvertisedAddress,
		Description:  `Address to advertise to other orchestrators to connect to.`,
	},
	{
		FlagName:     "cluster-peers",
		ConfigPath:   types.NodeNetworkClusterPeers,
		DefaultValue: Default.Node.Network.Cluster.Peers,
		Description:  `Comma-separated list of other orchestrators to connect to to form a cluster.`,
	},
}
View Source
var NodeInfoStoreFlags = []Definition{
	{
		FlagName:     "node-info-store-ttl",
		ConfigPath:   types.NodeNodeInfoStoreTTL,
		DefaultValue: Default.Node.NodeInfoStoreTTL,
		Description: `Sets the duration for which node information is retained in the node info store after which it
is automatically removed from the store.`,
	},
}
View Source
var NodeNameFlags = []Definition{
	{
		FlagName:     "name",
		ConfigPath:   types.NodeName,
		DefaultValue: "",
		Description:  `The name of the node. If not set, the node name will be generated automatically based on the chosen name provider.`,
	},
	{
		FlagName:     "name-provider",
		ConfigPath:   types.NodeNameProvider,
		DefaultValue: Default.Node.NameProvider,
		Description:  `The name provider to use to generate the node name, if no name is set.`,
	},
}
View Source
var NodeTypeFlags = []Definition{
	{
		FlagName:     "node-type",
		ConfigPath:   types.NodeType,
		DefaultValue: Default.Node.Type,
		Description:  `Whether the node is a compute, requester or both.`,
	},
}
View Source
var PublishingFlags = []Definition{
	{
		FlagName:     "default-publisher",
		DefaultValue: Default.Node.Requester.DefaultPublisher,
		ConfigPath:   types.NodeRequesterDefaultPublisher,
		Description:  `A default publisher to apply to all jobs without a publisher`,
	},
}
View Source
var RequesterJobStorageFlags = []Definition{
	{
		FlagName:             "requester-job-store-type",
		ConfigPath:           types.NodeRequesterJobStoreType,
		DefaultValue:         Default.Node.Requester.JobStore.Type,
		Description:          "The type of job store used by the requester node (BoltDB)",
		EnvironmentVariables: []string{"BACALHAU_JOB_STORE_TYPE"},
	},
	{
		FlagName:             "requester-job-store-path",
		ConfigPath:           types.NodeRequesterJobStorePath,
		DefaultValue:         Default.Node.Requester.JobStore.Path,
		Description:          "The path used for the requester job store store when using BoltDB",
		EnvironmentVariables: []string{"BACALHAU_JOB_STORE_PATH"},
	},
}
View Source
var RequesterTLSFlags = []Definition{
	{
		FlagName:     "autocert",
		DefaultValue: Default.Node.ServerAPI.TLS.AutoCert,
		ConfigPath:   types.NodeServerAPITLSAutoCert,
		Description: `Specifies a host name for which ACME is used to obtain a TLS Certificate.
Using this option results in the API serving over HTTPS`,
		EnvironmentVariables: []string{"BACALHAU_AUTO_TLS"},
	},
	{
		FlagName:             "tlscert",
		DefaultValue:         Default.Node.ServerAPI.TLS.ServerCertificate,
		ConfigPath:           types.NodeServerAPITLSServerCertificate,
		Description:          `Specifies a TLS certificate file to be used by the requester node`,
		EnvironmentVariables: []string{"BACALHAU_TLS_CERT"},
	},
	{
		FlagName:             "tlskey",
		DefaultValue:         Default.Node.ServerAPI.TLS.ServerKey,
		ConfigPath:           types.NodeServerAPITLSServerKey,
		Description:          `Specifies a TLS key file matching the certificate to be used by the requester node`,
		EnvironmentVariables: []string{"BACALHAU_TLS_KEY"},
	},
	{
		FlagName:             "self-signed",
		DefaultValue:         Default.Node.ServerAPI.TLS.SelfSigned,
		ConfigPath:           types.NodeServerAPITLSSelfSigned,
		Description:          `Specifies whether to auto-generate a self-signed certificate for the requester node`,
		EnvironmentVariables: []string{"BACALHAU_TLS_SELFSIGNED"},
	},
}
View Source
var ServerAPIFlags = []Definition{
	{
		FlagName:             "port",
		DefaultValue:         Default.Node.ServerAPI.Port,
		ConfigPath:           types.NodeServerAPIPort,
		Description:          `The port to server on.`,
		EnvironmentVariables: []string{"BACALHAU_SERVER_PORT"},
	},
	{
		FlagName:             "host",
		DefaultValue:         Default.Node.ServerAPI.Host,
		ConfigPath:           types.NodeServerAPIHost,
		Description:          `The host to serve on.`,
		EnvironmentVariables: []string{"BACALHAU_SERVER_HOST"},
	},
}
View Source
var WebUIFlags = []Definition{
	{
		FlagName:     "web-ui",
		ConfigPath:   types.NodeWebUIEnabled,
		DefaultValue: Default.Node.WebUI.Enabled,
		Description:  `Whether to start the web UI alongside the bacalhau node.`,
	},
	{
		FlagName:     "web-ui-port",
		ConfigPath:   types.NodeWebUIPort,
		DefaultValue: Default.Node.WebUI.Port,
		Description:  `The port number to listen on for web-ui connections.`,
	},
}

Functions

func BindFlags

func BindFlags(cmd *cobra.Command, register map[string][]Definition) error

BindFlags binds flags from a command to Viper using the provided definitions. This method should be called in command `PreRun`

func FlagNameForKey added in v1.1.0

func FlagNameForKey(key string, def ...Definition) string

FlagNameForKey accepts a configuration key and slice of Definition's containing the key. It returns the name of the flag corresponding to the key prefixed with `--`, or panics if the key is not part of the definition.

func PreRun added in v1.1.2

func PreRun(flags map[string][]Definition) func(*cobra.Command, []string) error

PreRun returns a run hook that binds the passed flag sets onto the command.

func RegisterFlags

func RegisterFlags(cmd *cobra.Command, register map[string][]Definition) error

RegisterFlags adds flags to the command based on provided definitions. This method should be called before the command runs to register flags accordingly.

Types

type Definition

type Definition struct {
	FlagName             string
	ConfigPath           string
	DefaultValue         interface{}
	Description          string
	EnvironmentVariables []string
	Deprecated           bool
	DeprecatedMessage    string
}

Definition serves as a bridge between Cobra's command-line flags and Viper's configuration management. Each instance of `Definition` maps a flag (as presented to the user via the CLI) to its corresponding configuration setting in Viper. Here's a breakdown:

  • FlagName: The name of the flag as it appears on the command line.
  • ConfigPath: The path/key used by Viper to store and retrieve the flag's value. This path can represent nested configuration settings. It is also the environment variable (replace '.' with '_')
  • DefaultValue: The default value for the flag, used both in Cobra (when the flag is not explicitly provided) and in Viper (as the initial configuration value).
  • Description: A human-readable description of the flag's purpose, shown in help messages and documentation.

By defining flags in this manner, we establish a clear and consistent pattern for integrating Cobra and Viper, ensuring that command-line interactions seamlessly reflect and influence the underlying configuration state.

func FlagDefForKey added in v1.1.0

func FlagDefForKey(key string, def ...Definition) Definition

FlagDefForKey accepts a configuration key and slice of Definition's containing the key. It returns the Definition for the specific key or panics if the key is not part of the definition.

Jump to

Keyboard shortcuts

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