Command Line Provider
The command line provider parses command-line arguments into JSON configuration.
rule.For<AppSettings>().FromCommandLine("--app:")How It Works
- Scans arguments for entries matching the switch prefix (default
--) - Parses key-value pairs from the matched arguments
- Converts flat keys to nested JSON (same nesting rules as environment variables)
This provider is static — command-line arguments don't change during process lifetime.
Argument Formats
The parser supports several formats:
# Key=value (single argument)
--MaxRetries=10
# Key value (two arguments)
--MaxRetries 10
# Boolean flag (no value = "true")
--EnableLogging
# Nested keys with : or __
--Database:Host=localhost
--Database__Port=5432Values that start with a switch prefix
In the two-argument --key value form, a value that itself begins with a switch prefix (e.g. --port -5) is parsed as a boolean flag (--port → true), not as the value -5. Use the = form for such values: --port=-5.
Prefix Filtering
Filter arguments by a prefix to avoid collisions:
// Only arguments starting with "--app:"
rule.For<AppSettings>().FromCommandLine("--app:")dotnet run --app:MaxRetries=10 --app:Debug=true --other:Ignored=yesProduces { "MaxRetries": 10, "Debug": true } for AppSettings. Arguments starting with --other: are ignored.
Custom Switch Prefixes ADV
By default, the parser looks for --. You can add other prefixes:
// Accept both - and -- as switch prefixes
rule.For<AppSettings>().FromCommandLine(["-", "--"])dotnet run -MaxRetries=10 --Debug=trueWhen multiple prefixes match, the longest prefix wins.
Common Pattern
Command-line arguments as the highest-priority override:
rule => [
rule.For<AppSettings>().FromFile("appsettings.json").Required(),
rule.For<AppSettings>().FromEnvironment("APP_"),
rule.For<AppSettings>().FromCommandLine("--app:"), // Highest priority
]Dynamic Options ADV
Use the factory overload for custom parsing:
rule.For<AppSettings>().FromCommandLine(accessor =>
new CommandLineRuleOptions(
Args: args,
SwitchPrefixes: ["--", "-"],
Prefix: "app"))