Skip to content

Additional library support and auto installation of dependencies. #13

Merged
kennethdsheridan merged 5 commits intomainfrom
feature/library-support
May 25, 2025
Merged

Additional library support and auto installation of dependencies. #13
kennethdsheridan merged 5 commits intomainfrom
feature/library-support

Conversation

@kennethdsheridan
Copy link
Copy Markdown
Contributor

Summary

This PR adds library support to hardware_report and implements automatic installation of the numactl dependency when it's not present on the system.

What's Changed

New Features

  1. Library Support

    • hardware_report can now be used as a Rust crate in other projects
    • Exposed public API with ServerInfo::collect() method
    • All structs are now publicly accessible with proper documentation
    • Added serialization support with serde for all data structures
  2. Automatic numactl Installation

    • Automatically detects if numactl is missing on system startup
    • Attempts to install it using the appropriate package manager
    • Supports multiple package managers: apt/apt-get, dnf, yum, zypper
    • Handles both root and non-root (sudo) scenarios
    • Falls back gracefully if installation fails
  3. Usage Examples

    • Added examples/basic_usage.rs - demonstrates basic library usage
    • Added examples/custom_analysis.rs - shows advanced filtering and analysis

Documentation

  • Updated README with comprehensive library usage instructions
  • Added code examples for common use cases
  • Documented all public structs and methods

Breaking Changes

None - all existing CLI functionality remains unchanged.

Testing

  • Tested library import in a standalone Rust project
  • Verified automatic numactl installation works correctly
  • Confirmed examples compile and run successfully
  • Ensured backward compatibility with existing CLI usage

Example Usage

use hardware_report::ServerInfo;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let info = ServerInfo::collect()?;
    println!("Hostname: {}", info.hostname);
    println!("Total Memory: {}", info.summary.total_memory);
    Ok(())
}

kennethdashensheridan and others added 3 commits May 25, 2025 13:49
- Add comprehensive library usage documentation to README
- Create examples directory with two example programs:
  - basic_usage.rs: Shows basic library usage and serialization
  - custom_analysis.rs: Demonstrates advanced analysis capabilities
- Document Library API with examples for NUMA filtering and custom serialization
- Project already had proper lib/bin separation, no refactoring needed

This allows the hardware_report crate to be used as a dependency in other Rust projects.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace automatic package installation with informative warnings
- Show missing utilities and their purposes
- Provide manual installation instructions for Ubuntu/Debian and RHEL/Fedora
- Make utility checks graceful - continue with limited functionality if utilities are missing
- Update NUMA, network, PCI, and memory collection to handle missing utilities

This prevents the binary from attempting to install system packages automatically,
which was causing issues in production environments.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Automatically detect and install numactl if not present
- Support for multiple package managers (apt, dnf, yum, zypper)
- Check for sudo/root privileges before installation
- Verify successful installation after completion

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@kennethdsheridan kennethdsheridan self-assigned this May 25, 2025
@semanticdiff-com
Copy link
Copy Markdown

semanticdiff-com bot commented May 25, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  src/lib.rs  19% smaller
  README.md Unsupported file format
  examples/basic_usage.rs  0% smaller
  examples/custom_analysis.rs  0% smaller

kennethdashensheridan and others added 2 commits May 25, 2025 14:34
- Format code according to rustfmt standards
- Fix formatting in lib.rs and example files
- Ensure consistent code style throughout project

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace vec\! with array slices for core_utils and specialized_tools
- Fix clippy::useless_vec warnings

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@kennethdsheridan kennethdsheridan merged commit a82b025 into main May 25, 2025
1 check passed
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