Skip to content

v3.2.0

Choose a tag to compare

@windischb windischb released this 23 Oct 10:27
· 62 commits to develop since this release
1d976d5

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 /verbose

All 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=production

3. 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=5432

5. Three Argument Formats

  • Key-value with equals: --key=value
  • Key-value with space: --key value
  • Boolean flags: --verbose (parsed as true)

🔧 Architecture Improvements

Enhanced ProviderOptions vs QueryOptions separation across CommandLine, Environment, and FileSource providers:

  • ProviderOptions contains provider-level configuration (shared across queries)
  • QueryOptions contains 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 tests
    • EmojiPrefixTest: 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 --verbose

Prefix 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=8080

Coexist 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?

  1. Maximum Flexibility: Accept any prefix style or combination
  2. Self-Documenting: Use semantic prefixes that match your domain
  3. Cross-Platform: Support both Unix (-, --) and Windows (/) conventions
  4. No Conflicts: Works alongside ASP.NET Core and other CLI libraries
  5. Reactive: Same reactive patterns as other Cocoar providers
  6. Type-Safe: Full integration with Cocoar's strongly-typed configuration

📦 What's Included

  • New CommandLineArgumentProvider
  • Extension methods: .FromCommandLine()
  • CommandLineRuleOptions for configuration
  • Full test coverage (24 unit tests + 6 integration tests)
  • Comprehensive documentation

🔗 Related

🙏 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