mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 11:35:45 +00:00
Add -y, --yes and -n, --no flags (currently unused)
This commit is contained in:
parent
7e85798381
commit
c7cf1112b6
41
src/cli.rs
41
src/cli.rs
@ -22,6 +22,16 @@ pub enum CommandKind {
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub enum Flags {
|
||||
// No flags supplied
|
||||
None,
|
||||
// Flag -y, --yes supplied
|
||||
AlwaysYes,
|
||||
// Flag -n, --no supplied
|
||||
AlwaysNo
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub struct Command {
|
||||
pub kind: CommandKind,
|
||||
@ -63,12 +73,43 @@ Please relate any issues or contribute at https://github.com/vrmiguel/ouch")
|
||||
.help("The output directory or compressed file.")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("yes")
|
||||
.required(false)
|
||||
.multiple(false)
|
||||
.long("yes")
|
||||
.short("y")
|
||||
.help("Says yes to all confirmation dialogs.")
|
||||
.conflicts_with("no")
|
||||
.takes_value(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("no")
|
||||
.required(false)
|
||||
.multiple(false)
|
||||
.long("no")
|
||||
.short("n")
|
||||
.help("Says no to all confirmation dialogs.")
|
||||
.conflicts_with("yes")
|
||||
.takes_value(false),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_matches() -> clap::ArgMatches<'static> {
|
||||
clap_app().get_matches()
|
||||
}
|
||||
|
||||
pub fn parse_matches(matches: clap::ArgMatches<'static>) -> crate::Result<(Command, Flags)> {
|
||||
let flag = match (matches.is_present("yes"), matches.is_present("no")) {
|
||||
(true, true) => unreachable!(),
|
||||
(true, _) => Flags::AlwaysYes,
|
||||
(_, true) => Flags::AlwaysNo,
|
||||
(_, _) => Flags::None
|
||||
};
|
||||
|
||||
Ok((Command::try_from(matches)?, flag))
|
||||
}
|
||||
|
||||
impl TryFrom<clap::ArgMatches<'static>> for Command {
|
||||
type Error = crate::Error;
|
||||
|
||||
|
16
src/main.rs
16
src/main.rs
@ -9,24 +9,12 @@ mod file;
|
||||
mod test;
|
||||
mod utils;
|
||||
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use error::{Error, Result};
|
||||
use evaluator::Evaluator;
|
||||
|
||||
fn main() -> crate::Result<()> {
|
||||
let matches = cli::get_matches();
|
||||
let command = cli::Command::try_from(matches)?;
|
||||
// let command = cli::Command::try_from(matches)?;
|
||||
let (command, _flags) = cli::parse_matches(matches)?;
|
||||
Evaluator::evaluate(command)
|
||||
}
|
||||
|
||||
// fn main() -> crate::Result<()> {
|
||||
// let dialog = dialogs::Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE"));
|
||||
|
||||
// match dialog.ask(Some("file.tar.gz"))? {
|
||||
// true => println!("deleting"),
|
||||
// false => println!("keeping")
|
||||
// };
|
||||
|
||||
// Ok(())
|
||||
// }
|
||||
|
Loading…
x
Reference in New Issue
Block a user