mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-05 02:55:31 +00:00
rename Opts
to CliArgs
This commit is contained in:
parent
ab675e8dbb
commit
5b99f434c3
4
build.rs
4
build.rs
@ -27,7 +27,7 @@ use clap::{CommandFactory, ValueEnum};
|
||||
use clap_complete::{generate_to, Shell};
|
||||
use clap_mangen::Man;
|
||||
|
||||
include!("src/opts.rs");
|
||||
include!("src/cli/args.rs");
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-env-changed=OUCH_ARTIFACTS_FOLDER");
|
||||
@ -35,7 +35,7 @@ fn main() {
|
||||
if let Some(dir) = env::var_os("OUCH_ARTIFACTS_FOLDER") {
|
||||
let out = &Path::new(&dir);
|
||||
create_dir_all(out).unwrap();
|
||||
let cmd = &mut Opts::command();
|
||||
let cmd = &mut CliArgs::command();
|
||||
|
||||
Man::new(cmd.clone())
|
||||
.render(&mut File::create(out.join("ouch.1")).unwrap())
|
||||
|
@ -12,7 +12,7 @@ use clap::{Parser, ValueHint};
|
||||
#[command(about, version)]
|
||||
// Disable rustdoc::bare_urls because rustdoc parses URLs differently than Clap
|
||||
#[allow(rustdoc::bare_urls)]
|
||||
pub struct Opts {
|
||||
pub struct CliArgs {
|
||||
/// Skip [Y/n] questions positively
|
||||
#[arg(short, long, conflicts_with = "no", global = true)]
|
||||
pub yes: bool,
|
@ -1,4 +1,6 @@
|
||||
//! CLI related functions, uses the clap argparsing definitions from `opts.rs`.
|
||||
//! CLI related functions, uses the clap argparsing definitions from `args.rs`.
|
||||
|
||||
mod args;
|
||||
|
||||
use std::{
|
||||
io,
|
||||
@ -9,25 +11,26 @@ use std::{
|
||||
use clap::Parser;
|
||||
use fs_err as fs;
|
||||
|
||||
use crate::{accessible::set_accessible, utils::FileVisibilityPolicy, Opts, QuestionPolicy, Subcommand};
|
||||
pub use self::args::{CliArgs, Subcommand};
|
||||
use crate::{accessible::set_accessible, utils::FileVisibilityPolicy, QuestionPolicy};
|
||||
|
||||
impl Opts {
|
||||
impl CliArgs {
|
||||
/// A helper method that calls `clap::Parser::parse`.
|
||||
///
|
||||
/// And:
|
||||
/// 1. Make paths absolute.
|
||||
/// 2. Checks the QuestionPolicy.
|
||||
pub fn parse_args() -> crate::Result<(Self, QuestionPolicy, FileVisibilityPolicy)> {
|
||||
let mut opts = Self::parse();
|
||||
let mut args = Self::parse();
|
||||
|
||||
set_accessible(opts.accessible);
|
||||
set_accessible(args.accessible);
|
||||
|
||||
let (Subcommand::Compress { files, .. }
|
||||
| Subcommand::Decompress { files, .. }
|
||||
| Subcommand::List { archives: files, .. }) = &mut opts.cmd;
|
||||
| Subcommand::List { archives: files, .. }) = &mut args.cmd;
|
||||
*files = canonicalize_files(files)?;
|
||||
|
||||
let skip_questions_positively = match (opts.yes, opts.no) {
|
||||
let skip_questions_positively = match (args.yes, args.no) {
|
||||
(false, false) => QuestionPolicy::Ask,
|
||||
(true, false) => QuestionPolicy::AlwaysYes,
|
||||
(false, true) => QuestionPolicy::AlwaysNo,
|
||||
@ -35,12 +38,12 @@ impl Opts {
|
||||
};
|
||||
|
||||
let file_visibility_policy = FileVisibilityPolicy::new()
|
||||
.read_git_exclude(opts.gitignore)
|
||||
.read_ignore(opts.gitignore)
|
||||
.read_git_ignore(opts.gitignore)
|
||||
.read_hidden(opts.hidden);
|
||||
.read_git_exclude(args.gitignore)
|
||||
.read_ignore(args.gitignore)
|
||||
.read_git_ignore(args.gitignore)
|
||||
.read_hidden(args.hidden);
|
||||
|
||||
Ok((opts, skip_questions_positively, file_visibility_policy))
|
||||
Ok((args, skip_questions_positively, file_visibility_policy))
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ use rayon::prelude::{IndexedParallelIterator, IntoParallelRefIterator, ParallelI
|
||||
use utils::colors;
|
||||
|
||||
use crate::{
|
||||
cli::{CliArgs, Subcommand},
|
||||
commands::{compress::compress_files, decompress::decompress_file, list::list_archive_contents},
|
||||
error::{Error, FinalError},
|
||||
extension::{self, flatten_compression_formats, parse_format, Extension, SUPPORTED_EXTENSIONS},
|
||||
@ -22,7 +23,7 @@ use crate::{
|
||||
self, pretty_format_list_of_paths, to_utf, try_infer_extension, user_wants_to_continue, EscapedPathDisplay,
|
||||
FileVisibilityPolicy,
|
||||
},
|
||||
warning, Opts, QuestionAction, QuestionPolicy, Subcommand,
|
||||
warning, QuestionAction, QuestionPolicy,
|
||||
};
|
||||
|
||||
/// Warn the user that (de)compressing this .zip archive might freeze their system.
|
||||
@ -99,7 +100,7 @@ fn check_for_non_archive_formats(files: &[PathBuf], formats: &[Vec<Extension>])
|
||||
///
|
||||
/// There are a lot of custom errors to give enough error description and explanation.
|
||||
pub fn run(
|
||||
args: Opts,
|
||||
args: CliArgs,
|
||||
question_policy: QuestionPolicy,
|
||||
file_visibility_policy: FileVisibilityPolicy,
|
||||
) -> crate::Result<()> {
|
||||
|
@ -10,14 +10,11 @@ pub mod extension;
|
||||
pub mod list;
|
||||
pub mod utils;
|
||||
|
||||
/// CLI argparsing definitions, using `clap`.
|
||||
pub mod opts;
|
||||
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
use cli::CliArgs;
|
||||
use error::{Error, Result};
|
||||
use once_cell::sync::Lazy;
|
||||
use opts::{Opts, Subcommand};
|
||||
use utils::{QuestionAction, QuestionPolicy};
|
||||
|
||||
// Used in BufReader and BufWriter to perform less syscalls
|
||||
@ -37,6 +34,6 @@ fn main() {
|
||||
}
|
||||
|
||||
fn run() -> Result<()> {
|
||||
let (args, skip_questions_positively, file_visibility_policy) = Opts::parse_args()?;
|
||||
let (args, skip_questions_positively, file_visibility_policy) = CliArgs::parse_args()?;
|
||||
commands::run(args, skip_questions_positively, file_visibility_policy)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user