Skip to content

Commit

Permalink
Merge pull request #275 from ouch-org/show-aliases-in-help-message
Browse files Browse the repository at this point in the history
Show subcommand aliases on `--help`
  • Loading branch information
figsoda authored Oct 11, 2022
2 parents f8e6075 + 2269773 commit fe0af16
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@ use std::path::PathBuf;

use clap::{Parser, ValueHint};

// Command line options
// Ouch command line options (docstrings below are part of --help)
/// A command-line utility for easily compressing and decompressing files and directories.
///
/// Supported formats: tar, zip, bz/bz2, gz, lz4, xz/lz/lzma, zst.
///
/// Repository: https://github.com/ouch-org/ouch
#[derive(Parser, Debug)]
#[command(about, version)]
// Ignore bare urls in the documentation of this file because the doc comments
// are also being used by Clap's --help generation
// Disable rustdoc::bare_urls because rustdoc parses URLs differently than Clap
#[allow(rustdoc::bare_urls)]
pub struct Opts {
/// Skip [Y/n] questions positively.
/// Skip [Y/n] questions positively
#[arg(short, long, conflicts_with = "no", global = true)]
pub yes: bool,

/// Skip [Y/n] questions negatively.
/// Skip [Y/n] questions negatively
#[arg(short, long, global = true)]
pub no: bool,

Expand All @@ -39,44 +38,33 @@ pub struct Opts {
pub cmd: Subcommand,
}

// CAREFUL: this docs can accidentally become part of the --help message if they get too long
// this was tested in clap 3.0.0-beta5.
/// Repository: https://github.com/ouch-org/ouch
//
// Ouch commands:
// - `compress`
// - `decompress`
// - `list`
//
// Clap commands:
// - `help`
#[derive(Parser, PartialEq, Eq, Debug)]
#[allow(rustdoc::bare_urls)]
pub enum Subcommand {
/// Compress one or more files into one output file.
#[command(alias = "c")]
/// Compress one or more files into one output file
#[command(visible_alias = "c")]
Compress {
/// Files to be compressed.
/// Files to be compressed
#[arg(required = true, num_args = 1..)]
files: Vec<PathBuf>,

/// The resulting file. Its extensions can be used to specify the compression formats.
/// The resulting file. Its extensions can be used to specify the compression formats
#[arg(required = true, value_hint = ValueHint::FilePath)]
output: PathBuf,
},
/// Decompresses one or more files, optionally into another folder.
#[command(alias = "d")]
/// Decompresses one or more files, optionally into another folder
#[command(visible_alias = "d")]
Decompress {
/// Files to be decompressed.
/// Files to be decompressed
#[arg(required = true, num_args = 1..)]
files: Vec<PathBuf>,

/// Place results in a directory other than the current one.
/// Place results in a directory other than the current one
#[arg(short = 'd', long = "dir", value_hint = ValueHint::DirPath)]
output_dir: Option<PathBuf>,
},
/// List contents. Alias: l
#[command(alias = "l")]
/// List contents of an archive
#[command(visible_alias = "l")]
List {
/// Archives whose contents should be listed
#[arg(required = true, num_args = 1..)]
Expand Down

0 comments on commit fe0af16

Please sign in to comment.