completions: hint generator to expand to file paths
[ouch.git] / src / cli / args.rs
blob676f49dc0533b19e3425c5d80e53b262f5f767c4
1 use std::{ffi::OsString, path::PathBuf};
3 use clap::{Parser, ValueHint};
5 // Ouch command line options (docstrings below are part of --help)
6 /// A command-line utility for easily compressing and decompressing files and directories.
7 ///
8 /// Supported formats: tar, zip, gz, xz/lzma, bz/bz2, lz4, sz, zst.
9 ///
10 /// Repository: https://github.com/ouch-org/ouch
11 #[derive(Parser, Debug)]
12 #[command(about, version)]
13 // Disable rustdoc::bare_urls because rustdoc parses URLs differently than Clap
14 #[allow(rustdoc::bare_urls)]
15 pub struct CliArgs {
16     /// Skip [Y/n] questions positively
17     #[arg(short, long, conflicts_with = "no", global = true)]
18     pub yes: bool,
20     /// Skip [Y/n] questions negatively
21     #[arg(short, long, global = true)]
22     pub no: bool,
24     /// Activate accessibility mode, reducing visual noise
25     #[arg(short = 'A', long, env = "ACCESSIBLE", global = true)]
26     pub accessible: bool,
28     /// Ignores hidden files
29     #[arg(short = 'H', long, global = true)]
30     pub hidden: bool,
32     /// Silences output
33     #[arg(short = 'q', long, global = true)]
34     pub quiet: bool,
36     /// Ignores files matched by git's ignore files
37     #[arg(short = 'g', long, global = true)]
38     pub gitignore: bool,
40     /// Specify the format of the archive
41     #[arg(short, long, global = true)]
42     pub format: Option<OsString>,
44     /// Ouch and claps subcommands
45     #[command(subcommand)]
46     pub cmd: Subcommand,
49 #[derive(Parser, PartialEq, Eq, Debug)]
50 #[allow(rustdoc::bare_urls)]
51 pub enum Subcommand {
52     /// Compress one or more files into one output file
53     #[command(visible_alias = "c")]
54     Compress {
55         /// Files to be compressed
56         #[arg(required = true, value_hint = ValueHint::FilePath)]
57         files: Vec<PathBuf>,
59         /// The resulting file. Its extensions can be used to specify the compression formats
60         #[arg(required = true, value_hint = ValueHint::FilePath)]
61         output: PathBuf,
63         /// Compression level, applied to all formats
64         #[arg(short, long, group = "compression-level")]
65         level: Option<i16>,
67         /// Fastest compression level possible,
68         /// conflicts with --level and --slow
69         #[arg(long, group = "compression-level")]
70         fast: bool,
72         /// Slowest (and best) compression level possible,
73         /// conflicts with --level and --fast
74         #[arg(long, group = "compression-level")]
75         slow: bool,
76     },
77     /// Decompresses one or more files, optionally into another folder
78     #[command(visible_alias = "d")]
79     Decompress {
80         /// Files to be decompressed
81         #[arg(required = true, num_args = 1.., value_hint = ValueHint::FilePath)]
82         files: Vec<PathBuf>,
84         /// Place results in a directory other than the current one
85         #[arg(short = 'd', long = "dir", value_hint = ValueHint::FilePath)]
86         output_dir: Option<PathBuf>,
87     },
88     /// List contents of an archive
89     #[command(visible_aliases = ["l", "ls"])]
90     List {
91         /// Archives whose contents should be listed
92         #[arg(required = true, num_args = 1.., value_hint = ValueHint::FilePath)]
93         archives: Vec<PathBuf>,
95         /// Show archive contents as a tree
96         #[arg(short, long)]
97         tree: bool,
98     },