Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update remove_command.dart #834

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

shinriyo
Copy link

@shinriyo shinriyo commented Mar 22, 2025

remove with wildcard
like this
dart run bin/main.dart remove '3.27.*'

Ref:
#833

Summary by CodeRabbit

  • New Features
    • Introduced support for removing multiple versions using wildcard patterns.
    • Added a confirmation prompt and progress feedback for bulk removals.
    • Maintained existing behavior for specific version removals.

remove with wildcard
like this
`dart run bin/main.dart remove '3.27.*'`

Ref:
leoafarias#833
Copy link

vercel bot commented Mar 22, 2025

@shinriyo is attempting to deploy a commit to the FlutterTools Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Mar 22, 2025

Walkthrough

This change updates the version removal command to support wildcard patterns. When a user specifies a version string containing a wildcard (*), the command converts it into a regex pattern to match cached versions. If no matches are found, it logs an informational message and returns a success exit code. When matching versions are found, the command prompts the user for confirmation before removing each version. Exception handling ensures that any failure during removal is logged and rethrown. For non-wildcard version strings, the existing removal logic remains unchanged.

Changes

File Change Summary
lib/…/remove_command.dart Added logic to detect wildcard characters in version strings, convert them into regex, filter cached versions, prompt for confirmation, and handle removals with exception logging and rethrowing.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant RC as RemoveCommand
    participant C as Cache
    participant L as Logger

    U->>RC: Provide version string (possibly with wildcard)
    RC->>RC: Check if version string contains "*"
    alt Wildcard detected
        RC->>C: Retrieve all available versions
        C-->>RC: Return list of versions
        RC->>RC: Filter versions using regex conversion
        alt No matches found
            RC->>L: Log informational message
            RC-->>U: Return success code
        else Matches found
            RC->>U: Prompt for confirmation to remove matches
            alt User declines
                RC-->>U: Return success code (no removal)
            else User confirms
                loop For each matching version
                    RC->>C: Remove version from cache
                    alt Exception occurs
                        RC->>L: Log failure message
                        RC->>RC: Rethrow exception
                    end
                end
                RC-->>U: Return success code
            end
        end
    else
        RC->>RC: Execute existing specific version removal logic
    end
Loading

Poem

I'm just a rabbit, hopping with glee,
Code wildcards abound—oh, what a spree!
I nibble on regex with each little bite,
Confirming removals deep in the night.
Through logs and prompts, I hop away,
Celebrating clean code in my own bunny way!
🐇🌟


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

@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 (3)
lib/src/commands/remove_command.dart (3)

64-71: Great implementation of wildcard pattern matching, but consider escaping regex special characters

The regex pattern construction doesn't account for potential special characters in the version string that have special meaning in regex (like ., +, (, ), etc.). This could lead to unexpected behavior if the version string contains such characters.

Consider escaping all regex special characters before replacing the wildcard:

- final pattern = version.replaceAll('*', '.*');
+ final pattern = RegExp.escape(version).replaceAll('\\*', '.*');

87-96: Exception handling could be more specific

The current implementation catches all exceptions generically. Consider catching more specific exceptions to provide more tailored error messages.

try {
  CacheService.fromContext.remove(matchingVersion);
  progress.complete('${matchingVersion.name} removed.');
- } on Exception {
+ } on FileSystemException catch (e) {
-  progress.fail('Could not remove ${matchingVersion.name}');
+  progress.fail('Could not remove ${matchingVersion.name}: ${e.message}');
  rethrow;
+ } on Exception catch (e) {
+  progress.fail('Error removing ${matchingVersion.name}: ${e.toString()}');
+  rethrow;
}

63-99: Consider adding a helper method for reused removal logic

I notice there's duplicated code between the wildcard pattern removal logic and the specific version removal logic (lines 111-121). Consider extracting the common functionality into a helper method to improve maintainability.

You could create a helper method like:

Future<void> _removeVersion(FlutterVersion version) async {
  final progress = logger.progress('Removing ${version.name}...');
  try {
    CacheService.fromContext.remove(version);
    progress.complete('${version.name} removed.');
  } on Exception {
    progress.fail('Could not remove ${version.name}');
    rethrow;
  }
}

Then use this method in both the wildcard and specific version removal sections.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ddad14e and 803e12c.

📒 Files selected for processing (1)
  • lib/src/commands/remove_command.dart (1 hunks)
🔇 Additional comments (3)
lib/src/commands/remove_command.dart (3)

78-85: Good user confirmation prompt for bulk removal

The confirmation prompt is clear and includes the count of matching versions, which is helpful for users to understand the impact of their action. Setting defaultValue: false is a good safety measure to prevent accidental deletions.


73-76: Clear user feedback when no matching versions found

Good implementation of informative feedback when no matching versions are found.


64-99: Overall well-implemented feature with good user experience

The implementation of wildcard pattern matching for version removal is well thought out. It properly:

  1. Detects wildcard patterns
  2. Matches versions using regex
  3. Provides clear user feedback
  4. Requests confirmation before bulk actions
  5. Handles errors appropriately

This enhancement significantly improves the usability of the remove command.

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.

1 participant