aprender_zram_cli/commands/
create.rs1use clap::Args;
6use trueno_zram_core::zram::{format_size, parse_size, SysfsOps, ZramConfig, ZramOps};
7
8#[derive(Debug, Args)]
10pub struct CreateArgs {
11 #[arg(short, long, default_value = "0", value_parser = clap::value_parser!(u32).range(0..=16))]
13 pub device: u32,
14
15 #[arg(short, long)]
17 pub size: String,
18
19 #[arg(short, long, default_value = "lz4")]
21 pub algorithm: String,
22
23 #[arg(long, default_value = "0")]
25 pub streams: u32,
26}
27
28pub fn create(args: &CreateArgs) -> Result<(), Box<dyn std::error::Error>> {
33 let size_bytes = parse_size(&args.size)?;
34
35 let config = ZramConfig {
36 device: args.device,
37 size: size_bytes,
38 algorithm: args.algorithm.clone(),
39 streams: args.streams,
40 };
41
42 let ops = SysfsOps::new();
43 ops.create(&config)?;
44
45 println!(
46 "Created zram{} with size {} using {}",
47 args.device,
48 format_size(size_bytes),
49 args.algorithm
50 );
51
52 Ok(())
53}