1 //! CLI related functions, uses the clap argparsing definitions from `args.rs`.
13 pub use self::args::{CliArgs, Subcommand};
15 accessible::set_accessible,
16 utils::{is_path_stdin, FileVisibilityPolicy},
21 /// A helper method that calls `clap::Parser::parse`.
24 /// 1. Make paths absolute.
25 /// 2. Checks the QuestionPolicy.
26 pub fn parse_and_validate_args() -> crate::Result<(Self, QuestionPolicy, FileVisibilityPolicy)> {
27 let mut args = Self::parse();
29 set_accessible(args.accessible);
31 let (Subcommand::Compress { files, .. }
32 | Subcommand::Decompress { files, .. }
33 | Subcommand::List { archives: files, .. }) = &mut args.cmd;
34 *files = canonicalize_files(files)?;
36 let skip_questions_positively = match (args.yes, args.no) {
37 (false, false) => QuestionPolicy::Ask,
38 (true, false) => QuestionPolicy::AlwaysYes,
39 (false, true) => QuestionPolicy::AlwaysNo,
40 (true, true) => unreachable!(),
43 let file_visibility_policy = FileVisibilityPolicy::new()
44 .read_git_exclude(args.gitignore)
45 .read_ignore(args.gitignore)
46 .read_git_ignore(args.gitignore)
47 .read_hidden(args.hidden);
49 Ok((args, skip_questions_positively, file_visibility_policy))
53 fn canonicalize_files(files: &[impl AsRef<Path>]) -> io::Result<Vec<PathBuf>> {
57 if is_path_stdin(f.as_ref()) {
58 Ok(f.as_ref().to_path_buf())