Major improvements: rollbacks, testing, docs, and code quality
- Fixed rollback implementation with two-phase approach (remove new, downgrade upgraded) - Added explicit package tracking (newly_installed vs upgraded) - Implemented graceful error handling with fail-fast approach - Added comprehensive test suite (20 tests across 3 test files) - Created centralized APT command execution module (apt_commands.rs) - Added configuration system with dry-run, quiet, and APT options - Reduced code duplication and improved maintainability - Added extensive documentation (rollbacks.md, rollbacks-not-featured.md, ffi-bridge.md) - Created configuration usage example - Updated README with crate usage instructions - All tests passing, clean compilation, production-ready
This commit is contained in:
parent
534c0e87a8
commit
2daad2837d
15 changed files with 1412 additions and 139 deletions
77
examples/configuration_usage.rs
Normal file
77
examples/configuration_usage.rs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
//! Example demonstrating APT wrapper configuration options
|
||||
//!
|
||||
//! This example shows how to use the various configuration options
|
||||
//! available in the APT wrapper.
|
||||
|
||||
use apt_wrapper::{AptTransaction, AptConfig, init};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("=== APT Wrapper Configuration Example ===");
|
||||
|
||||
// Initialize
|
||||
init()?;
|
||||
println!("✓ APT wrapper initialized");
|
||||
|
||||
// Example 1: Default configuration
|
||||
println!("\n--- Example 1: Default Configuration ---");
|
||||
let mut tx1 = AptTransaction::new()?;
|
||||
tx1.add_package("apt")?;
|
||||
println!("✓ Created transaction with default config");
|
||||
println!(" Config: {:?}", tx1.config());
|
||||
|
||||
// Example 2: Custom configuration
|
||||
println!("\n--- Example 2: Custom Configuration ---");
|
||||
let config = AptConfig {
|
||||
no_install_recommends: true,
|
||||
no_install_suggests: true,
|
||||
assume_yes: true,
|
||||
quiet: false,
|
||||
dry_run: true,
|
||||
};
|
||||
|
||||
let mut tx2 = AptTransaction::with_config(config)?;
|
||||
tx2.add_package("curl")?;
|
||||
println!("✓ Created transaction with custom config");
|
||||
println!(" Config: {:?}", tx2.config());
|
||||
|
||||
// Example 3: Testing configuration
|
||||
println!("\n--- Example 3: Testing Configuration ---");
|
||||
let mut tx3 = AptTransaction::for_testing()?;
|
||||
tx3.add_package("vim")?;
|
||||
println!("✓ Created transaction for testing");
|
||||
println!(" Config: {:?}", tx3.config());
|
||||
|
||||
// Example 4: Runtime configuration changes
|
||||
println!("\n--- Example 4: Runtime Configuration Changes ---");
|
||||
let mut tx4 = AptTransaction::new()?;
|
||||
tx4.add_package("git")?;
|
||||
|
||||
// Enable dry run mode
|
||||
tx4.enable_dry_run();
|
||||
println!("✓ Enabled dry run mode");
|
||||
|
||||
// Enable quiet mode
|
||||
tx4.enable_quiet();
|
||||
println!("✓ Enabled quiet mode");
|
||||
|
||||
// Disable dry run mode
|
||||
tx4.disable_dry_run();
|
||||
println!("✓ Disabled dry run mode");
|
||||
|
||||
println!(" Final config: {:?}", tx4.config());
|
||||
|
||||
// Example 5: Configuration validation
|
||||
println!("\n--- Example 5: Configuration Validation ---");
|
||||
let mut tx5 = AptTransaction::new()?;
|
||||
tx5.add_package("apt")?;
|
||||
|
||||
// Resolve dependencies (this will validate packages exist)
|
||||
tx5.resolve()?;
|
||||
println!("✓ Dependencies resolved successfully");
|
||||
|
||||
// Note: We don't actually commit in examples to avoid installing packages
|
||||
println!("\n=== Example completed ===");
|
||||
println!("Note: Transactions were not committed to avoid installing packages");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue