1 //! CLI related functions, uses the clap argparsing definitions from `opts.rs`.
12 use crate::{Opts, QuestionPolicy, Subcommand};
15 /// A helper method that calls `clap::Parser::parse`.
18 /// 1. Make paths absolute.
19 /// 2. Checks the QuestionPolicy.
20 pub fn parse_args() -> crate::Result<(Self, QuestionPolicy)> {
21 let mut opts = Self::parse();
23 let (Subcommand::Compress { files, .. }
24 | Subcommand::Decompress { files, .. }
25 | Subcommand::List { archives: files, .. }) = &mut opts.cmd;
26 *files = canonicalize_files(files)?;
28 let skip_questions_positively = if opts.yes {
29 QuestionPolicy::AlwaysYes
31 QuestionPolicy::AlwaysNo
36 Ok((opts, skip_questions_positively))
40 fn canonicalize_files(files: &[impl AsRef<Path>]) -> io::Result<Vec<PathBuf>> {
41 files.iter().map(fs::canonicalize).collect()