Structure
CommandLineArgumentsProvider
A configuration provider that sources values from command-line arguments.
- iOS 18.0+
- macOS 15.0+
- tvOS 18.0+
- visionOS 2.0+
- watchOS 11.0+
struct CommandLineArgumentsProvider
Overview
Reads configuration values from CLI arguments with type conversion and secrets handling. Keys are encoded to CLI flags at lookup time.
Package traits
This type is guarded by the CommandLineArgumentsSupport package trait.
Key formats
--key value - A key-value pair with separate arguments.
--key=value - A key-value pair with an equals sign.
--flag - A Boolean flag, treated as true.
--key val1 val2 - Multiple values (arrays).
Configuration keys are transformed to CLI flags: ["http", "serverTimeout"] → --http-server-timeout.
Array handling
Arrays can be specified in multiple ways:
Space-separated: --tags swift configuration cli
Repeated flags: --tags swift --tags configuration --tags cli
Comma-separated: --tags swift,configuration,cli
Mixed: --tags swift,configuration --tags cli
All formats produce the same result when accessed as an array type.
Usage
// CLI: program --debug --host localhost --ports 8080 8443
let provider = CommandLineArgumentsProvider()
let config = ConfigReader(provider: provider)
let isDebug = config.bool(forKey: "debug", default: false) // true
let host = config.string(forKey: "host", default: "0.0.0.0") // "localhost"
let ports = config.intArray(forKey: "ports", default: []) // [8080, 8443]
With secrets
let provider = CommandLineArgumentsProvider(
secretsSpecifier: .specific(["--api-key"])
)
Custom arguments
let provider = CommandLineArgumentsProvider(
arguments: ["program", "--verbose", "--timeout", "30"],
secretsSpecifier: .dynamic { key, _ in key.contains("--secret") }
)
Topics
Creating a command line arguments provider
Relationships
Conforms To