Skip to content

Conversation

@christerswahn
Copy link
Collaborator

@christerswahn christerswahn commented Jun 12, 2025

Adds methods to get usage help texts for a set of options, and for the options of a resolved configuration.
(This still uses the usage writer of ArgParser, which is still used internally. In the future this should be replaced.)

Added better usage examples in the doc comments.

Some code restructuring to split up large source files.

Summary by CodeRabbit

  • New Features

    • Introduced advanced configuration option types, including support for strings, enums, integers, date-times, durations, booleans, and multi-value options.
    • Added comprehensive validation, parsing, and formatting for all option types.
    • Enabled grouping of configuration options for better organization and validation.
    • Added support for dynamic configuration value resolution from multiple sources.
  • Refactor

    • Unified and streamlined the configuration options framework for improved extensibility and maintainability.
    • Delegated option parsing and validation logic to specialized modules.
  • Bug Fixes

    • Improved error handling and messaging for invalid option configurations.
  • Tests

    • Added tests to verify correct usage string generation for configuration options.

@coderabbitai
Copy link

coderabbitai bot commented Jun 12, 2025

📝 Walkthrough

Walkthrough

This update refactors the configuration option system by extracting option types, parsers, and validation logic into separate modules, introducing new abstractions for option definitions and brokers, and reorganizing exports and imports accordingly. Several new files are added, and existing files are updated to use the new modular structure. Additional tests are included for usage string reporting.

Changes

File(s) Change Summary
lib/src/config/config.dart Added exports for configuration_broker.dart, exceptions.dart, option_types.dart; reordered existing exports.
lib/src/config/config_parser.dart Added imports for configuration_broker.dart and option_types.dart.
lib/src/config/config_source_provider.dart Added import for options.dart.
lib/src/config/configuration.dart Removed in-file option/validation classes; now imports configuration_broker.dart, exceptions.dart, options.dart. Updated Configuration class to use new interfaces and methods.
lib/src/config/configuration_broker.dart New file: defines abstract ConfigurationBroker<O extends OptionDefinition> interface.
lib/src/config/exceptions.dart New file: defines InvalidOptionConfigurationError class.
lib/src/config/file_system_options.dart Changed import from configuration.dart to options.dart.
lib/src/config/multi_config_source.dart Added imports for configuration_broker.dart and options.dart.
lib/src/config/option_groups.dart Changed imports from configuration.dart to exceptions.dart and options.dart.
lib/src/config/option_types.dart New file: introduces typed option classes and parsers for strings, enums, ints, date-times, and durations.
lib/src/config/options.dart Refactored: adds generic option abstraction, parsers, option groups, and resolution logic; removes specialized option classes now in option_types.dart.
test/config/configuration_test.dart Added tests for the usage property of configuration options and resolved configurations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ArgParser
    participant Configuration
    participant OptionDefinition
    participant ConfigurationBroker
    participant ValueParser

    User->>Configuration: Initialize with OptionDefinitions
    Configuration->>ArgParser: Prepare options for parsing
    User->>Configuration: Request value for option
    Configuration->>OptionDefinition: resolveValue()
    OptionDefinition->>ConfigurationBroker: (if needed) valueOrNull(key, config)
    OptionDefinition->>ValueParser: parse(rawValue)
    OptionDefinition->>OptionDefinition: validateOptionValue(parsedValue)
    OptionDefinition-->>Configuration: Return resolved/validated value
Loading
sequenceDiagram
    participant User
    participant Configuration
    participant OptionDefinition

    User->>Configuration: Request usage
    Configuration->>OptionDefinition: Get usage string
    OptionDefinition-->>Configuration: Return usage/help text
    Configuration-->>User: Return usage/help text
Loading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@christerswahn christerswahn marked this pull request as ready for review June 12, 2025 11:34
@christerswahn christerswahn requested a review from SandPod June 12, 2025 11:35
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (4)
lib/src/config/exceptions.dart (1)

4-15: Consider extending Exception instead of Error

InvalidOptionConfigurationError represents a recoverable, user-level configuration mistake rather than a programming bug. Extending Exception (or creating a subtype of it) is more idiomatic in Dart for signalling input / configuration problems, while Error is intended for unrecoverable programming errors (e.g. assertion failures).

-class InvalidOptionConfigurationError extends Error {
+class InvalidOptionConfigurationError implements Exception {

Keeping the rest of the class unchanged preserves the API and toString formatting.

lib/src/config/option_types.dart (2)

41-63: Trim elements when splitting multi-string input

MultiStringOption splits on commas but keeps any surrounding whitespace, so "a, b ,c " yields ['a', ' b ', 'c '].
Add .trim() when mapping, or document the current behaviour explicitly.


196-203: Typo: mininum variable name

final mininum = min; – the misspelling makes the code look sloppy and complicates grepping later. Rename to minimum.

lib/src/config/options.dart (1)

245-252: Convert Iterable to List before passing to allowed

argParser.addOption expects List<String>?; pass .toList() to avoid implicit cast issues.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6081606 and ee32ee3.

📒 Files selected for processing (12)
  • lib/src/config/config.dart (1 hunks)
  • lib/src/config/config_parser.dart (1 hunks)
  • lib/src/config/config_source_provider.dart (1 hunks)
  • lib/src/config/configuration.dart (4 hunks)
  • lib/src/config/configuration_broker.dart (1 hunks)
  • lib/src/config/exceptions.dart (1 hunks)
  • lib/src/config/file_system_options.dart (1 hunks)
  • lib/src/config/multi_config_source.dart (1 hunks)
  • lib/src/config/option_groups.dart (1 hunks)
  • lib/src/config/option_types.dart (1 hunks)
  • lib/src/config/options.dart (1 hunks)
  • test/config/configuration_test.dart (1 hunks)
🔇 Additional comments (14)
lib/src/config/file_system_options.dart (1)

5-5: Import update looks correct

The switch from configuration.dart to options.dart aligns the file with the new modular structure and resolves the OptionDefinition symbol without introducing any side-effects.

lib/src/config/config_source_provider.dart (1)

4-4: Import aligns with refactor

Adding options.dart is required after relocating OptionDefinition; build will fail without it. No further changes needed.

lib/src/config/config_parser.dart (1)

7-9: New imports are necessary and correctly scoped

configuration_broker.dart supplies the ConfigurationBroker type used in parse, and option_types.dart provides the concrete option classes referenced throughout the file. No redundancy or unused-import warnings expected.

lib/src/config/option_groups.dart (1)

1-4: Imports match the new package boundaries

Replacing the broad configuration.dart import with fine-grained exceptions.dart and options.dart keeps dependencies minimal and prevents circular imports. Looks good.

lib/src/config/multi_config_source.dart (1)

3-4: LGTM! Necessary imports for the ConfigurationBroker implementation.

The imports correctly support the MultiDomainConfigBroker class which implements ConfigurationBroker<O> and uses OptionDefinition as a type constraint.

test/config/configuration_test.dart (2)

125-133: Good test coverage for the new usage feature on option lists.

The test correctly validates that the usage property on a list of options returns the expected help text format, showing the fromDefault function name in the usage string.


135-145: Good test coverage for the usage feature on Configuration instances.

The test validates that the usage getter on a resolved Configuration instance returns the same help text as when accessed directly from the option list, ensuring consistency.

lib/src/config/configuration_broker.dart (1)

1-12: Well-designed interface for configuration value resolution.

The ConfigurationBroker interface provides a clean abstraction for dynamic value resolution with appropriate type constraints and clear documentation. The design allows for flexible implementations that can resolve values from multiple sources and handle dependencies between options.

lib/src/config/config.dart (1)

6-12: Appropriate exports for the new modular configuration system.

The added exports correctly expose the new configuration infrastructure:

  • configuration_broker.dart - for dynamic value resolution
  • exceptions.dart - for error handling
  • option_types.dart - for typed option implementations
  • options.dart - for the option framework

The ordering logically places type definitions before the framework that uses them.

lib/src/config/configuration.dart (4)

5-7: Necessary imports for the refactored configuration system.

The imports correctly bring in the new modular components that handle option definitions, value resolution, and error handling.


11-42: Excellent documentation improvement with comprehensive example.

The updated documentation provides a clear, practical example that demonstrates:

  • Best practice of using enums for option definitions
  • Integration with command-line arguments and environment variables
  • Complete runnable code that developers can easily adapt

This significantly improves the developer experience for new users of the configuration system.


112-113: Clean implementation of the usage getter.

The getter appropriately delegates to the options collection, providing access to the usage help text functionality as intended by the PR objectives.


256-256: Good refactoring - delegating option logic to the option objects.

The changes correctly delegate value resolution and validation to the option objects themselves, following object-oriented principles and reducing the Configuration class's responsibilities. This improves modularity and maintainability.

Also applies to: 305-305

lib/src/config/options.dart (1)

404-413: Reliance on ArgResults.option() API

args.option(argOptName) is likewise not in the public API. Verify that an extension providing it exists; otherwise this will fail at compile time.

Copy link
Contributor

@SandPod SandPod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

@christerswahn christerswahn merged commit a98f595 into main Jun 13, 2025
17 checks passed
@christerswahn christerswahn deleted the config branch June 13, 2025 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants