Skip to content

Conversation

@christerswahn
Copy link
Collaborator

@christerswahn christerswahn commented Mar 3, 2025

In order to make it more clear what output behavior is being configured, BetterCommandRunner's constructor parameters were changed from:

    PassMessage? logError,
    PassMessage? logInfo,

to:

    MessageOutput? messageOutput,

MessageOutput is a new type containing specific output members:

final class MessageOutput {
  void logUsageException(UsageException exception);

  void logUsage(String usage);
}

Summary by CodeRabbit

  • New Features

    • Introduced a unified logging setup for command execution that consolidates usage and error messages, ensuring clearer and more consistent output for users.
  • Refactor

    • Streamlined the logging configuration by replacing multiple logging points with a single, flexible interface for improved consistency and maintainability.

@christerswahn christerswahn requested a review from SandPod March 3, 2025 15:21
@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2025

📝 Walkthrough

Walkthrough

This pull request refactors the logging mechanism used by the BetterCommand and BetterCommandRunner classes. The changes replace the existing message-passing functions (logInfo/logError) with a unified logging interface named MessageOutput. This new interface consolidates logging functions for usage messages and exceptions. Both production code and tests have been updated accordingly to support this new approach.

Changes

File(s) Change Summary
lib/src/better_command_runner/{better_command.dart, better_command_runner.dart} Replaced separate logging members (_logInfo and _logError of type PassMessage?) with a single _messageOutput of type MessageOutput?. Updated constructor parameters from logInfo/logError to passOutput/messageOutput, modified logging calls (e.g., printUsage now calls methods on _messageOutput), and introduced a new MessageOutput class.
test/{better_command_runner/logging_test.dart, better_command_test.dart} Updated tests to align with the new logging approach by replacing logError and logInfo parameters with messageOutput (using an instance of MessageOutput), ensuring that usage and exception logging are correctly handled in the test setups.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant Command as BetterCommand
    participant Logger as MessageOutput
    User->>Command: Invoke printUsage
    Command->>Logger: logUsage(usageInfo)
Loading
sequenceDiagram
    participant Runner as BetterCommandRunner
    participant Logger as MessageOutput
    participant Error as UsageException
    Runner->>Runner: Detect error condition
    Runner->>Logger: logUsageException(Error)
Loading

Suggested reviewers

  • SandPod

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

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.

Suggestion to simplify the interface.

I'm not sure we need the abstraction in this case since it is simply configuration passed in.

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: 0

🧹 Nitpick comments (1)
lib/src/better_command_runner/better_command_runner.dart (1)

9-34: Consider adding more specific documentation about migration

For users who are updating from the previous API, it would be helpful to include explicit documentation about how this new class replaces the previous logging approach.

 /// A proxy for user-provided functions for passing specific log messages.
 ///
 /// It is valid to not provide a function in order to not pass that output.
+/// 
+/// This class replaces the previous approach of passing separate `logError` and 
+/// `logInfo` callback functions, consolidating them into a single interface.
 final class MessageOutput {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5ee5c61 and 16a5237.

📒 Files selected for processing (4)
  • lib/src/better_command_runner/better_command.dart (1 hunks)
  • lib/src/better_command_runner/better_command_runner.dart (5 hunks)
  • test/better_command_runner/logging_test.dart (1 hunks)
  • test/better_command_test.dart (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/better_command_runner/logging_test.dart
  • lib/src/better_command_runner/better_command.dart
🔇 Additional comments (10)
test/better_command_test.dart (2)

7-7: Constructor parameter updated to match the refactored API

The constructor parameter has been correctly updated from logInfo to passOutput to align with the changes in the BetterCommand class hierarchy.


28-32: Successfully adapted the test to use the new MessageOutput class

The test now correctly instantiates a MessageOutput object with a logUsage function instead of directly passing a logging function. This change properly aligns with the refactored API while maintaining the same test logic.

lib/src/better_command_runner/better_command_runner.dart (8)

9-34: Consider renaming to MessageOutputs (plural) for clarity

The class represents multiple output mechanisms (currently usage exceptions and usage messages), so a plural name might better reflect its purpose.

-final class MessageOutput {
+final class MessageOutputs {

The class looks well-designed with:

  • Immutability (marked as final)
  • Clear documentation for each method
  • Proper null-safety with optional function callbacks
  • Encapsulation of the logging functionality

61-61: Field renamed to reflect new consolidated approach

The change from separate _logError and _logInfo fields to a single _messageOutput field successfully consolidates the logging concerns.


72-73: Documentation updated to reflect API changes

The constructor documentation has been correctly updated to describe the new messageOutput parameter.


80-81: Constructor parameter updated for clarity

The constructor now accepts a single MessageOutput parameter instead of separate logging functions, which simplifies the API and makes the intention clearer.


85-85: Constructor field assignment updated correctly

The field assignment has been properly updated to match the new parameter.


137-137: Exception handling updated to use new logging approach

The exception logging has been correctly updated to use the new _messageOutput?.logUsageException(e) method.


145-145: Usage printing updated to use new logging approach

The usage printing has been correctly updated to use the new _messageOutput?.logUsage(usage) method.


193-193: Exception handling consistently updated throughout the class

The usage exception handling is consistently updated in all relevant locations.

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 a604a14 into main Mar 3, 2025
6 checks passed
@christerswahn christerswahn deleted the 646-errors branch March 3, 2025 16:42
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