Skip to content

question: clap parser? #513

@xfbs

Description

@xfbs

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions