Repository navigation
v3.2.0
Release v3.2.0: CommandLine Provider
🎉 What's New
CommandLine Provider
Unlike traditional command-line parsers that lock you into specific prefix styles, our provider gives you complete freedom to choose what fits your application best.
✨ Key Features
1. Multiple Switch Prefixes Simultaneously
Accept any combination of prefix styles in a single command line:
rule.For<AppConfig>().FromCommandLine(["--", "-", "/"])dotnet run --host=server1 -port=9000 /verboseAll three styles work together seamlessly!
2. Semantic Prefixes for Self-Documenting CLIs
Create intuitive, domain-specific command-line interfaces:
rule.For<TargetConfig>().FromCommandLine(["@"]),
rule.For<IssueConfig>().FromCommandLine(["#"]),
rule.For<EnvConfig>().FromCommandLine(["%"])invoke.exe @host=10.10.10.10 #ticket=456 %env=production3. Flexible API
// Default (uses "--")
.FromCommandLine()
// With prefix filtering
.FromCommandLine("app_")
// Custom switch prefix
.FromCommandLine(["-"])
// Multiple prefixes
.FromCommandLine(["--", "-", "/"])
// Both prefix filtering and custom switches
.FromCommandLine("app_", ["@", "#"])4. Nested Configuration Support
Use : or __ separators for hierarchical configuration:
dotnet run --database:host=localhost --database:port=5432
# or
dotnet run --database__host=localhost --database__port=54325. Three Argument Formats
- Key-value with equals:
--key=value - Key-value with space:
--key value - Boolean flags:
--verbose(parsed astrue)
🔧 Architecture Improvements
Enhanced ProviderOptions vs QueryOptions separation across CommandLine, Environment, and FileSource providers:
ProviderOptionscontains provider-level configuration (shared across queries)QueryOptionscontains query-specific parameters (different per rule)- Enables proper provider sharing and rule-specific configuration
🧹 Cleanup
Removed 4 unused FileSystemObservable files (~140 lines) - the existing FileWatcherObservable is battle-tested and handles all file watching needs.
📚 Documentation
- CommandLine Provider README: Comprehensive guide with examples and use cases
- Main README: Updated with CommandLine provider examples
- Test Examples:
CommandLineExample: 6 comprehensive integration testsEmojiPrefixTest: Proof that Unicode prefixes work (because why not? 😏)
🚀 Usage Examples
Basic Usage
builder.Services.AddCocoarConfiguration(rule => [
rule.For<AppConfig>().FromCommandLine()
]);dotnet run --host=localhost --port=8080 --verbosePrefix Filtering
builder.Services.AddCocoarConfiguration(rule => [
rule.For<AppConfig>().FromCommandLine("app_"),
rule.For<DatabaseConfig>().FromCommandLine("db_")
]);dotnet run --app_host=localhost --db_connection="Server=dbserver"Cross-Platform Compatibility
Accept both Unix and Windows conventions:
rule.For<AppConfig>().FromCommandLine(["--", "/"])dotnet run --host=localhost /port=8080Coexist with Other CLI Parsers
Use unique prefixes to avoid conflicts with ASP.NET Core or other libraries:
var builder = WebApplication.CreateBuilder(args); // ASP.NET uses -- and -
builder.Services.AddCocoarConfiguration(rule => [
// Your app uses semantic prefixes - zero conflicts!
rule.For<AppConfig>().FromCommandLine(["@", "#"])
]);dotnet run --urls=http://localhost:5000 @feature=premium #issue=123🎯 Why Use CommandLine Provider?
- Maximum Flexibility: Accept any prefix style or combination
- Self-Documenting: Use semantic prefixes that match your domain
- Cross-Platform: Support both Unix (
-,--) and Windows (/) conventions - No Conflicts: Works alongside ASP.NET Core and other CLI libraries
- Reactive: Same reactive patterns as other Cocoar providers
- Type-Safe: Full integration with Cocoar's strongly-typed configuration
📦 What's Included
- New
CommandLineArgumentProvider - Extension methods:
.FromCommandLine() CommandLineRuleOptionsfor configuration- Full test coverage (24 unit tests + 6 integration tests)
- Comprehensive documentation
🔗 Related
- Closes #33
- See CHANGELOG.md for full details
🙏 Credits
Thanks to everyone who provided feedback on command-line parsing requirements. Your input shaped this provider!
Full Changelog: v3.1.1...v3.2.0