Add package manager detection feature to show binary source information#32
Add package manager detection feature to show binary source information#32
Conversation
Co-authored-by: NQMVD <99403507+NQMVD@users.noreply.github.com>
| if self.version.is_none() { | ||
| write!(f, "{} ?", self.name) | ||
| if let Some(ref pm) = self.package_manager { | ||
| write!(f, "{} ? ({})", self.name, pm) |
There was a problem hiding this comment.
dont use () but just prefix the name with "via"
| ) | ||
| let version_str = format_version(self.version.as_ref().unwrap(), false); | ||
| if let Some(ref pm) = self.package_manager { | ||
| write!(f, "{} {} ({})", self.name, version_str, pm) |
There was a problem hiding this comment.
dont use () but just prefix the name with "via"
src/discovery.rs
Outdated
| let path_str_lower = path_str.to_lowercase(); | ||
|
|
||
| // Check for rustup/cargo | ||
| if path_str_lower.contains("/.cargo/bin/") || path_str_lower.contains("/.rustup/") { |
There was a problem hiding this comment.
these are NOT the same manager! separate cargo and rustup
| path_str_lower.starts_with("/usr/sbin/") { | ||
| return Some("system".to_string()); | ||
| } | ||
|
|
There was a problem hiding this comment.
add more managers, like uv, bun, yarn and pnpm
| fn test_detect_package_manager() { | ||
| // Test rustup/cargo detection | ||
| assert_eq!( | ||
| detect_package_manager(Path::new("/home/user/.cargo/bin/cargo")), |
src/output.rs
Outdated
| let version_display = if always_found { | ||
| "found".to_string() | ||
| if let Some(ref pm) = bin.package_manager { | ||
| format!("found ({})", pm) |
src/output.rs
Outdated
| Some(ref version) => { | ||
| let version_str = format!("{}", format_version(version, full_versions)); | ||
| if let Some(ref pm) = bin.package_manager { | ||
| format!("{} ({})", version_str, pm) |
src/output.rs
Outdated
| } | ||
| None => { | ||
| if let Some(ref pm) = bin.package_manager { | ||
| format!("? ({})", pm) |
src/output.rs
Outdated
| let padding = " ".repeat(padding_needed); | ||
| println!("{}{} found", padding, bin.name.green()); | ||
| let display_text = if let Some(ref pm) = bin.package_manager { | ||
| format!("found ({})", pm) |
nmb4
left a comment
There was a problem hiding this comment.
refactor to implement what ive commented
There was a problem hiding this comment.
Pull Request Overview
This PR implements a new feature that detects and displays package manager information for system binaries. It analyzes binary paths to identify the package manager responsible for managing each binary and shows this information in parentheses after the version number.
Key changes:
- Added package manager detection logic based on binary path analysis
- Enhanced display output to show package manager information when available
- Updated Binary struct to include package manager field
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/binary.rs | Added package_manager field to Binary struct and updated display formatting |
| src/discovery.rs | Implemented package manager detection logic and updated binary partitioning |
| src/versions.rs | Preserved package_manager field through version retrieval process |
| src/output.rs | Updated output formatting to display package manager information |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/discovery.rs
Outdated
| if path_str_lower.contains("/.local/bin/") || | ||
| path_str_lower.contains("/python") || | ||
| path_str_lower.contains("/pip/") || | ||
| path_str_lower.contains("/pipx/") { | ||
| return Some("pip".to_string()); | ||
| } |
There was a problem hiding this comment.
The detection logic for pip is too broad. Checking for '/python' in the path will incorrectly classify many system binaries as pip-managed. For example, '/usr/bin/python3' would be detected as pip when it's actually a system package. Consider making this check more specific.
src/discovery.rs
Outdated
| if path_str_lower.starts_with("/opt/homebrew/") || | ||
| path_str_lower.starts_with("/usr/local/cellar/") || | ||
| (path_str_lower.contains("/usr/local/") && path_str_lower.contains("homebrew")) { |
There was a problem hiding this comment.
The homebrew detection is too broad. The condition path_str_lower.contains("/usr/local/") && path_str_lower.contains("homebrew") could match paths like '/usr/local/bin/somebinary' if the binary name happens to contain 'homebrew'. Consider making this check more specific to actual homebrew installation paths.
| if path_str_lower.starts_with("/opt/homebrew/") || | |
| path_str_lower.starts_with("/usr/local/cellar/") || | |
| (path_str_lower.contains("/usr/local/") && path_str_lower.contains("homebrew")) { | |
| path_str_lower.starts_with("/usr/local/homebrew/") { |
This PR implements a new feature that detects and displays which package manager is responsible for managing each binary found by the
needstool. The package manager information is shown in parentheses after the version number.What's Changed
Core Functionality
which()to determine the managing package managercargo 1.89.0 (rustup)Supported Package Managers
The detection logic supports common package managers and installation methods:
~/.cargo/bin/,~/.rustup/toolchains/*/bin//usr/bin/,/bin/,/usr/local/bin/(apt, yum, pacman, etc.)/opt/homebrew/,/usr/local/cellar/node_modules/.bin/~/go/bin/,$GOPATH/bin/~/.local/bin/Example Output
Before:
After:
Compatibility
--no-versionsflagImplementation Details
package_manager: Option<String>field toBinarystructpartition_binaries()to capture binary paths fromwhich()binary.rsandoutput.rsto show package manager infoTesting
This feature addresses the common need to understand where system binaries come from, making it easier to manage dependencies and troubleshoot installation issues.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.