Skip to content

Commit edbfde5

Browse files
Copilotjosecelano
andcommitted
docs: update README with install command and fix clippy warnings
Co-authored-by: josecelano <[email protected]>
1 parent 1706359 commit edbfde5

File tree

2 files changed

+82
-13
lines changed

2 files changed

+82
-13
lines changed

packages/dependency-installer/README.md

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ For manual usage, you can control log verbosity with the `--verbose` flag or `RU
1818
## Features
1919

2020
- **Dependency Detection**: Check if required development tools are installed
21-
- **Extensible**: Easy to add new dependency detectors
21+
- **Dependency Installation**: Install missing dependencies automatically
22+
- **Extensible**: Easy to add new dependency detectors and installers
2223
- **Structured Logging**: Built-in tracing support for observability and automation
2324
- **Type-Safe**: Uses strongly-typed enums for dependencies
2425
- **Error Handling**: Clear, actionable error messages
26+
- **Async Support**: Asynchronous installation operations for better performance
2527

2628
## Supported Dependencies
2729

28-
This package can detect the following development dependencies:
30+
This package can detect and install the following development dependencies:
2931

3032
- **cargo-machete** - Detects unused Rust dependencies
3133
- **OpenTofu** - Infrastructure provisioning tool
@@ -45,25 +47,34 @@ dependency-installer check
4547
# Check specific dependency
4648
dependency-installer check --dependency opentofu
4749

50+
# Install all dependencies
51+
dependency-installer install
52+
53+
# Install specific dependency
54+
dependency-installer install --dependency opentofu
55+
4856
# List all dependencies with status
4957
dependency-installer list
5058

5159
# Control log level (off, error, warn, info, debug, trace)
5260
dependency-installer check --log-level debug
61+
dependency-installer install --log-level debug
5362
dependency-installer check --log-level off # Disable all logging
5463

5564
# Enable verbose logging (equivalent to --log-level debug)
5665
dependency-installer check --verbose
66+
dependency-installer install --verbose
5767

5868
# Get help
5969
dependency-installer --help
6070
dependency-installer check --help
71+
dependency-installer install --help
6172
```
6273

6374
#### Exit Codes
6475

65-
- **0**: Success (all checks passed)
66-
- **1**: Missing dependencies
76+
- **0**: Success (all checks or installations passed)
77+
- **1**: Missing dependencies or installation failures
6778
- **2**: Invalid arguments
6879
- **3**: Internal error
6980

@@ -89,6 +100,26 @@ $ dependency-installer check --dependency opentofu
89100
2025-11-04T17:33:20.960482Z INFO torrust_dependency_installer::handlers::check: Dependency is not installed dependency="OpenTofu" status="not installed"
90101
Error: Check command failed: Failed to check specific dependency: opentofu: not installed
91102

103+
# Install all dependencies
104+
$ dependency-installer install
105+
2025-11-04T19:30:10.000000Z INFO torrust_dependency_installer::handlers::install: Installing all dependencies
106+
2025-11-04T19:30:10.100000Z INFO torrust_dependency_installer::installer::cargo_machete: Installing cargo-machete dependency="cargo-machete"
107+
2025-11-04T19:30:25.000000Z INFO torrust_dependency_installer::handlers::install: Dependency installation result dependency="cargo-machete" status="installed"
108+
2025-11-04T19:30:25.100000Z INFO torrust_dependency_installer::installer::opentofu: Installing OpenTofu dependency="opentofu"
109+
2025-11-04T19:30:40.000000Z INFO torrust_dependency_installer::handlers::install: Dependency installation result dependency="OpenTofu" status="installed"
110+
...
111+
2025-11-04T19:31:00.000000Z INFO torrust_dependency_installer::handlers::install: All dependencies installed successfully
112+
113+
# Install specific dependency with verbose logging
114+
$ dependency-installer install --dependency opentofu --verbose
115+
2025-11-04T19:30:10.000000Z INFO torrust_dependency_installer::handlers::install: Installing specific dependency dependency=opentofu
116+
2025-11-04T19:30:10.100000Z INFO torrust_dependency_installer::installer::opentofu: Installing OpenTofu dependency="opentofu"
117+
2025-11-04T19:30:10.200000Z DEBUG torrust_dependency_installer::installer::opentofu: Downloading OpenTofu installer script
118+
2025-11-04T19:30:12.000000Z DEBUG torrust_dependency_installer::installer::opentofu: Making installer script executable
119+
2025-11-04T19:30:12.100000Z DEBUG torrust_dependency_installer::installer::opentofu: Running OpenTofu installer with sudo
120+
2025-11-04T19:30:25.000000Z DEBUG torrust_dependency_installer::installer::opentofu: Cleaning up installer script
121+
2025-11-04T19:30:25.100000Z INFO torrust_dependency_installer::handlers::install: Dependency installation completed dependency="OpenTofu" status="installed"
122+
92123
# List all dependencies
93124
$ dependency-installer list
94125
2025-11-04T17:33:20.960482Z INFO torrust_dependency_installer::handlers::list: Available dependency dependency="cargo-machete" status="installed"
@@ -140,6 +171,44 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
140171
}
141172
```
142173
174+
#### Installing Dependencies
175+
176+
```rust
177+
use torrust_dependency_installer::{Dependency, DependencyManager};
178+
179+
#[tokio::main]
180+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
181+
// Initialize tracing for structured logging
182+
tracing_subscriber::fmt::init();
183+
184+
let manager = DependencyManager::new();
185+
186+
// Install specific dependency
187+
manager.install(Dependency::OpenTofu).await?;
188+
189+
// Or install all dependencies
190+
let results = manager.install_all().await;
191+
192+
for result in results {
193+
let installer = manager.get_installer(result.dependency);
194+
if result.success {
195+
tracing::info!(
196+
dependency = installer.name(),
197+
"Installation succeeded"
198+
);
199+
} else {
200+
tracing::error!(
201+
dependency = installer.name(),
202+
error = result.error.as_deref().unwrap_or("unknown"),
203+
"Installation failed"
204+
);
205+
}
206+
}
207+
208+
Ok(())
209+
}
210+
```
211+
143212
#### Using Individual Detectors
144213
145214
```rust

packages/dependency-installer/tests/docker_install_command.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use std::path::PathBuf;
99
mod containers;
1010
use containers::ubuntu_container_builder::UbuntuContainerBuilder;
1111

12-
/// Test that cargo-machete can be installed
12+
/// Test that `cargo-machete` can be installed
1313
#[tokio::test]
14-
#[ignore] // Requires recent Rust/Cargo version, run with --ignored flag
14+
#[ignore = "Requires recent Rust/Cargo version, run with --ignored flag"]
1515
async fn it_should_install_cargo_machete_successfully() {
1616
// Get the binary path (built by cargo before running tests)
1717
let binary_path = get_binary_path();
@@ -57,7 +57,7 @@ async fn it_should_install_cargo_machete_successfully() {
5757

5858
/// Test that installation is idempotent (can run multiple times)
5959
#[tokio::test]
60-
#[ignore] // Requires recent Rust/Cargo version, run with --ignored flag
60+
#[ignore = "Requires recent Rust/Cargo version, run with --ignored flag"]
6161
async fn it_should_handle_idempotent_installation_of_cargo_machete() {
6262
let binary_path = get_binary_path();
6363

@@ -93,9 +93,9 @@ async fn it_should_handle_idempotent_installation_of_cargo_machete() {
9393
);
9494
}
9595

96-
/// Test that OpenTofu can be installed
96+
/// Test that `OpenTofu` can be installed
9797
#[tokio::test]
98-
#[ignore] // This test is expensive, run with --ignored flag
98+
#[ignore = "This test is expensive, run with --ignored flag"]
9999
async fn it_should_install_opentofu_successfully() {
100100
let binary_path = get_binary_path();
101101

@@ -137,9 +137,9 @@ async fn it_should_install_opentofu_successfully() {
137137
);
138138
}
139139

140-
/// Test that Ansible can be installed
140+
/// Test that `Ansible` can be installed
141141
#[tokio::test]
142-
#[ignore] // This test is expensive, run with --ignored flag
142+
#[ignore = "This test is expensive, run with --ignored flag"]
143143
async fn it_should_install_ansible_successfully() {
144144
let binary_path = get_binary_path();
145145

@@ -172,9 +172,9 @@ async fn it_should_install_ansible_successfully() {
172172
);
173173
}
174174

175-
/// Test that LXD can be installed
175+
/// Test that `LXD` can be installed
176176
#[tokio::test]
177-
#[ignore] // This test is expensive and requires snap, run with --ignored flag
177+
#[ignore = "This test is expensive and requires snap, run with --ignored flag"]
178178
async fn it_should_install_lxd_successfully() {
179179
let binary_path = get_binary_path();
180180

0 commit comments

Comments
 (0)