ouch-org / ouch

Painless compression and decompression in the terminal
https://crates.io/crates/ouch
Other
2.18k stars 75 forks source link

Change to print possible values ​​for `--format` #693

Open sorairolake opened 1 month ago

sorairolake commented 1 month ago

Currently, --format takes a OsString value.

https://github.com/ouch-org/ouch/blob/4a323aeba83ad0f937bf5d2ed18eaa7a5afdb79d/src/cli/args.rs#L40-L42

Change this to the following:

/// Specify the format of the archive
#[arg(short, long, global = true)]
pub format: Option<Format>,

...

#[derive(Clone, Debug, ValueEnum)]
pub enum Format {
    /// .tar
    #[value(alias(".tar"))]
    Tar,

    /// .xz
    #[value(alias(".xz"))]
    Xz,

    /// .tar.zst or .tzst
    #[value(name("tar.zst"), alias(".tar.zst"), alias("tzst"), alias(".tzst"))]
    TarZst,

    ...
}

I think this will allow --format to print possible values.

The downside to this is that it makes complex chains of file formats such as .tar.gz.xz.zst.gz.lz4.sz impossible.

marcospb19 commented 1 month ago

I think this will allow --format to print possible values.

Hey! By print, do you mean --help or shell autocompletion?

sorairolake commented 1 month ago

I think this will allow --format to print possible values.

Hey! By print, do you mean --help or shell autocompletion?

Yes, that's right.

marcospb19 commented 1 month ago

I'm sorry, which one of these two? hahaha

sorairolake commented 1 month ago

@marcospb19 Both. -h prints possible values, and --help prints the help description (doc comments) in addition to this. For shell completion, possible values ​​will be completed if supported. If the help description is supported it will also be printed.

sorairolake commented 1 month ago

To avoid breaking changes to --format, it may be better to add new options rather than modifying --format. I think it would be better to have the new options separate for compression formats and archive formats to limit the number of possible values.

e.g., --compression-format=gzip and --archive-format=tar.

marcospb19 commented 1 month ago

I can't think of a scenario where this would break --format :thinking:.

sorairolake commented 1 month ago

I can't think of a scenario where this would break --format 🤔.

I think this will not be able to handle complex chains .tar.gz.xz.zst.gz.lz4.sz.