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

Refactor search command #912

Merged
merged 7 commits into from
Dec 11, 2024
Merged

Refactor search command #912

merged 7 commits into from
Dec 11, 2024

Conversation

jewlexx
Copy link
Member

@jewlexx jewlexx commented Dec 11, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a command-line flag app download --outdated for downloading outdated applications.
    • Added support for a json flag in the search command.
    • Implemented warnings for deprecated usage in the search command.
    • Enhanced logging by directing logs to a specific directory when running with debug assertions.
  • Bug Fixes

    • Updated download progress bars to display app names instead of URL leaves.
    • Modified the search command to show the [installed] label correctly.
  • Documentation

    • Updated CHANGELOG.md to reflect notable changes in the project.
  • Chores

    • Version updated from 1.15.0 to 1.16.0.
    • Removed the sfsu_macros crate from the project.
    • Added a new warning! macro for colored warning messages.

@jewlexx jewlexx added the enhancement New feature or request label Dec 11, 2024
@jewlexx jewlexx self-assigned this Dec 11, 2024
@jewlexx jewlexx marked this pull request as ready for review December 11, 2024 03:07
Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

The changes in this pull request involve updates to several files, primarily focusing on the CHANGELOG.md, Cargo.toml, and various command files. Notable additions include the introduction of a new command-line flag app download --outdated, enhancements in the search command for deprecated usage, and modifications to the Args structs to utilize global architecture settings. The sfsu_macros crate has been removed, and a new warning! macro has been added for logging purposes. The version of the package has also been incremented.

Changes

File Path Change Summary
CHANGELOG.md Updated to reflect new command app download --outdated, warnings for deprecated usage, and json flag support in search. Removed json flag from app download.
Cargo.toml Version updated from 1.15.0 to 1.16.0.
src/commands/app/download.rs Modified arch field to use #[clap(from_global)].
src/commands/search.rs Refactored MatchCriteria struct, introduced MatchedManifest and MatchedOutput structs, and improved matching logic. Removed parse_output function.
src/commands/virustotal.rs Modified arch field to use #[clap(from_global)].
src/main.rs Added arch field to Args struct with a default value of Architecture::ARCH.
src/output.rs Introduced a new warning! macro for logging warnings.

Possibly related PRs

  • Added outdated flag to download command #901: The changes in this PR include the addition of the app download --outdated command and the removal of the json flag from the app download command, which directly relates to the updates made in the main PR's CHANGELOG.md.
  • added config validations #905: This PR introduces configuration validations that cause the application to crash with an error message when no_junction is enabled, which is also mentioned in the main PR's CHANGELOG.md.

🐰 In the code we hop and play,
New flags and warnings pave the way.
From CHANGELOG to Cargo bright,
Each change brings joy, a coder's delight!
With warning! calls, we’ll never stray,
Together we code, come what may! 🌟


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. (Experiment)
  • @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

@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

🧹 Outside diff range and nitpick comments (4)
src/commands/search.rs (3)

70-79: Simplify redundant checks in match_binaries method.

The filter_map in the match_binaries method redundantly checks pattern.is_match(&b) after already filtering for matches. This can be simplified to improve readability and efficiency.

Apply this diff to simplify the method:

 fn match_binaries(&mut self, pattern: &Regex, binaries: Vec<String>) -> &mut Self {
     let binary_matches = binaries
         .into_iter()
-        .filter(|binary| pattern.is_match(binary))
-        .filter_map(|b| {
-            if pattern.is_match(&b) {
-                Some(b.clone())
-            } else {
-                None
-            }
-        });
+        .filter(|binary| pattern.is_match(binary))
+        .collect();

     self.bins.extend(binary_matches);

     self
 }

129-129: Use pattern.as_str() instead of pattern.to_string() for exact match comparison.

Comparing manifest.name() to pattern.to_string() may not yield the expected result because pattern.to_string() includes the regex syntax, which may not match the manifest name as intended. Use pattern.as_str() to compare the raw pattern string.

Apply this diff:

 let exact_match = unsafe { manifest.name() } == pattern.to_string();
+let exact_match = unsafe { manifest.name() } == pattern.as_str();

251-256: Avoid variable shadowing for improved clarity.

The variable bucket is shadowed within the if let Some(bucket) = self.bucket block, which can cause confusion and potential errors. Consider renaming the inner variable to avoid shadowing the outer bucket.

Apply this diff to rename the inner variable:

 if let Some(bucket_flag) = self.bucket {
     warning!("Using bucket flag instead of bucket/package syntax");
     bucket_flag
 } else {
     bucket.to_string()
 }
CHANGELOG.md (1)

22-22: Specify the noun after "each" for clarity.

The sentence "Download hash checks now report to a progress bar rather than a print message for each" is missing the noun after "each". Consider adding the noun to clarify the message.

Apply this diff:

- Download hash checks now report to a progress bar rather than a print message for each
+ Download hash checks now report to a progress bar rather than a print message for each file
🧰 Tools
🪛 LanguageTool

[grammar] ~22-~22: Use a singular noun after the quantifier ‘each’, or change it to “all”.
Context: ...ess bar rather than a print message for each - Logs will now go into <PWD>/logs if runnin...

(EACH_EVERY_NNS)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 76687f0 and 63def21.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • CHANGELOG.md (1 hunks)
  • Cargo.toml (1 hunks)
  • src/commands/app/download.rs (1 hunks)
  • src/commands/search.rs (6 hunks)
  • src/commands/virustotal.rs (1 hunks)
  • src/main.rs (2 hunks)
  • src/output.rs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Cargo.toml
🧰 Additional context used
🪛 LanguageTool
CHANGELOG.md

[grammar] ~22-~22: Use a singular noun after the quantifier ‘each’, or change it to “all”.
Context: ...ess bar rather than a print message for each - Logs will now go into <PWD>/logs if runnin...

(EACH_EVERY_NNS)

🔇 Additional comments (7)
src/commands/search.rs (1)

45-49: ⚠️ Potential issue

Missing pattern parameter in MatchCriteria::matches function.

The pattern variable is used within the matches method but is not included in the function signature. This will result in a compilation error due to the undefined pattern.

Apply this diff to add the missing pattern parameter:

 pub fn matches(
     file_name: &str,
+    pattern: &Regex,
     list_binaries: impl FnOnce() -> Vec<String>,
     mode: SearchMode,
 ) -> Self {

Likely invalid or redundant comment.

src/output.rs (1)

16-24: LGTM!

The warning! macro is correctly defined, enabling consistent and formatted warning messages throughout the codebase.

src/commands/app/download.rs (1)

42-43: LGTM!

Using #[clap(from_global)] for the arch field allows for consistent architecture settings across commands and enhances configurability.

src/main.rs (2)

30-33: LGTM: Clean import organization

The imports are well-organized and the new Architecture import is properly placed within the sprinkles module group.


124-131: LGTM: Well-structured architecture configuration

The new arch field is:

  • Properly marked as global for consistent usage across commands
  • Has clear documentation explaining its purpose
  • Uses a sensible default value
src/commands/virustotal.rs (2)

115-115: LGTM: Proper global architecture configuration

The arch field correctly uses from_global to inherit the architecture setting from the main Args struct, maintaining consistency across commands.


Line range hint 177-184: Verify architecture handling in install_config

The architecture is used consistently in install_config calls. However, let's verify the error handling for unsupported architectures.

✅ Verification successful

Let me gather more information about the architecture handling by checking the implementation of install_config and related error handling.


Let me try a different approach to find architecture-related code and error handling.


Let me check one more aspect to understand how architecture validation is handled in the manifest and configuration code.


Based on the code analysis, I can now generate the final response:

Architecture handling in install_config appears to be properly implemented

The code shows that architecture handling in install_config is implemented through a consistent pattern across multiple commands (search, virustotal, info). The architecture parameter is properly passed through to configuration merging (merge_default) and there's no evidence of unhandled architecture cases. The code gracefully handles both hash and URL configurations for different architectures.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if install_config handles unsupported architectures gracefully

# Search for error handling around install_config calls
rg -A 5 "install_config.*arch" 

# Look for architecture validation or error handling patterns
ast-grep --pattern 'install_config($_) {
  $$$
  if $_ {
    $$$
  }
  $$$
}'

Length of output: 1677


Script:

#!/bin/bash
# Search for install_config implementation and architecture-related error handling
ast-grep --pattern 'fn install_config($_) {
  $$$
}'

# Look for architecture-related structs and implementations
rg -A 5 "pub struct.*arch|impl.*arch"

# Search for architecture validation or error patterns
rg -A 3 "unsupported.*arch|invalid.*arch|unknown.*arch"

Length of output: 152


Script:

#!/bin/bash
# Search for architecture-related code in manifest handling
rg -A 5 "manifest.*arch|Arch|Architecture"

# Look for error handling in manifest-related code
ast-grep --pattern 'match $_ {
  $$$
}'

# Find where architecture is used in configuration
rg -A 3 "config.*arch|arch.*config"

Length of output: 40676


Script:

#!/bin/bash
# Look for architecture-related code in manifest and configuration
ast-grep --pattern 'struct $_Config {
  $$$
}'

# Search for architecture validation or error handling in manifest code
rg -A 5 "fn.*manifest.*arch|manifest.*arch.*fn"

# Look for any architecture-related error types or handling
rg -A 3 "Error.*arch|arch.*error"

Length of output: 533

@jewlexx jewlexx merged commit 6d5efed into trunk Dec 11, 2024
10 checks passed
@jewlexx jewlexx deleted the search-refactor branch December 11, 2024 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant