1 //! CLI related functions, uses the clap argparsing definitions from `opts.rs`.
11 use once_cell::sync::OnceCell;
13 use crate::{Opts, QuestionPolicy, Subcommand};
15 /// Whether to enable accessible output (removes info output and reduces other
16 /// output, removes visual markers like '[' and ']').
17 /// Removes th progress bar as well
18 pub static ACCESSIBLE: OnceCell<bool> = OnceCell::new();
21 /// A helper method that calls `clap::Parser::parse`.
24 /// 1. Make paths absolute.
25 /// 2. Checks the QuestionPolicy.
26 pub fn parse_args() -> crate::Result<(Self, QuestionPolicy)> {
27 let mut opts = Self::parse();
29 ACCESSIBLE.set(opts.accessible).unwrap();
31 let (Subcommand::Compress { files, .. }
32 | Subcommand::Decompress { files, .. }
33 | Subcommand::List { archives: files, .. }) = &mut opts.cmd;
34 *files = canonicalize_files(files)?;
36 let skip_questions_positively = if opts.yes {
37 QuestionPolicy::AlwaysYes
39 QuestionPolicy::AlwaysNo
44 Ok((opts, skip_questions_positively))
48 fn canonicalize_files(files: &[impl AsRef<Path>]) -> io::Result<Vec<PathBuf>> {
49 files.iter().map(fs::canonicalize).collect()