-
Notifications
You must be signed in to change notification settings - Fork 47
question: clap parser? #513
Copy link
Copy link
Open
Description
Is it allowed to use clap's derive feature in this project? I always use that in my projects because I feel like it is more readable and less code. But the crates in here don't seem to use it. So when I implemented fallocate, I also didn't use it.
If it is allowed, I would be happy to migrate some things over.
For reference, this is what it would look like for fallocate:
use clap::Parser;
#[derive(Parser)]
#[command(version, about = "Preallocate or deallocate space to a file.")]
#[command(override_usage = "fallocate [options] <filename>")]
#[group(id = "mode", args = ["collapse_range", "dig_holes", "insert_range", "punch_hole", "zero_range", "posix"])]
struct Options {
/// remove a range from the file
#[arg(short = 'c', long = "collapse-range")]
collapse_range: bool,
/// detect zeroes and replace with holes
#[arg(short = 'd', long = "dig-holes")]
dig_holes: bool,
/// insert a hole at range, shifting existing data
#[arg(short = 'i', long = "insert-range")]
insert_range: bool,
/// length for range operations, in bytes
#[arg(short = 'l', long, value_name = "num")]
length: Option<String>,
/// maintain the apparent size of the file
#[arg(short = 'n', long = "keep-size")]
keep_size: bool,
/// offset for range operations, in bytes
#[arg(short = 'o', long, value_name = "num")]
offset: Option<String>,
/// replace a range with a hole (implies -n)
#[arg(short = 'p', long = "punch-hole")]
punch_hole: bool,
/// zero and ensure allocation of a range
#[arg(short = 'z', long = "zero-range")]
zero_range: bool,
/// use posix_fallocate(3) instead of fallocate(2)
#[arg(short = 'x', long)]
posix: bool,
/// verbose mode
#[arg(short = 'v', long)]
verbose: bool,
/// target file
filename: String,
}Using this would save about 70 lines of code.
Cheers!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels