Skip to main content

aprender_zram_cli/commands/
remove.rs

1//! Remove zram device command.
2//!
3//! This is a pure shim that delegates to `trueno_zram_core::zram`.
4
5use clap::Args;
6use trueno_zram_core::zram::{SysfsOps, ZramOps};
7
8/// Arguments for removing a zram device.
9#[derive(Debug, Args)]
10pub struct RemoveArgs {
11    /// Device number to remove.
12    #[arg(short, long, default_value = "0")]
13    pub device: u32,
14
15    /// Force removal even if in use.
16    #[arg(short, long)]
17    pub force: bool,
18}
19
20/// Remove a zram device.
21///
22/// # Errors
23/// Returns an error if the zram device cannot be removed.
24pub fn remove(args: &RemoveArgs) -> Result<(), Box<dyn std::error::Error>> {
25    let ops = SysfsOps::new();
26    ops.remove(args.device, args.force)?;
27
28    println!("Removed zram{}", args.device);
29    Ok(())
30}