mirror of
https://github.com/ouch-org/ouch.git
synced 2025-07-22 17:40:17 +00:00
Merge pull request #22 from vrmiguel/dev
Fix the -n, --no flag usage and add an alias for the compress subcommand
This commit is contained in:
commit
b50f82a65b
17
src/cli.rs
17
src/cli.rs
@ -94,12 +94,14 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let subcommands = &["compress"];
|
let subcommands = &[
|
||||||
|
"c", "compress"
|
||||||
|
];
|
||||||
|
|
||||||
let mut flags_info = vec![flag!('y', "yes"), flag!('n', "no")];
|
let mut flags_info = vec![flag!('y', "yes"), flag!('n', "no")];
|
||||||
|
|
||||||
let parsed_args = match oof::pop_subcommand(&mut args, subcommands) {
|
let parsed_args = match oof::pop_subcommand(&mut args, subcommands) {
|
||||||
Some(&"compress") => {
|
Some(&"c") | Some(&"compress") => {
|
||||||
// `ouch compress` subcommand
|
// `ouch compress` subcommand
|
||||||
let (args, flags) = oof::filter_flags(args, &flags_info)?;
|
let (args, flags) = oof::filter_flags(args, &flags_info)?;
|
||||||
let mut files: Vec<PathBuf> = args.into_iter().map(PathBuf::from).collect();
|
let mut files: Vec<PathBuf> = args.into_iter().map(PathBuf::from).collect();
|
||||||
@ -133,13 +135,10 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {
|
|||||||
// Parse flags
|
// Parse flags
|
||||||
let (args, mut flags) = oof::filter_flags(args, &flags_info)?;
|
let (args, mut flags) = oof::filter_flags(args, &flags_info)?;
|
||||||
|
|
||||||
let files = args.into_iter().map(canonicalize);
|
let files = args
|
||||||
for file in files.clone() {
|
.into_iter()
|
||||||
if let Err(err) = file {
|
.map(canonicalize)
|
||||||
return Err(err);
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
}
|
|
||||||
}
|
|
||||||
let files = files.map(Result::unwrap).collect();
|
|
||||||
|
|
||||||
let output_folder = flags.take_arg("output").map(PathBuf::from);
|
let output_folder = flags.take_arg("output").map(PathBuf::from);
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ type BoxedDecompressor = Box<dyn Decompressor>;
|
|||||||
|
|
||||||
fn get_compressor(file: &File) -> crate::Result<(Option<BoxedCompressor>, BoxedCompressor)> {
|
fn get_compressor(file: &File) -> crate::Result<(Option<BoxedCompressor>, BoxedCompressor)> {
|
||||||
let extension = match &file.extension {
|
let extension = match &file.extension {
|
||||||
Some(extension) => extension.clone(),
|
Some(extension) => extension,
|
||||||
None => {
|
None => {
|
||||||
// This is reached when the output file given does not have an extension or has an unsupported one
|
// This is reached when the output file given does not have an extension or has an unsupported one
|
||||||
return Err(crate::Error::MissingExtensionError(file.path.to_path_buf()));
|
return Err(crate::Error::MissingExtensionError(file.path.to_path_buf()));
|
||||||
@ -58,7 +58,7 @@ fn get_compressor(file: &File) -> crate::Result<(Option<BoxedCompressor>, BoxedC
|
|||||||
|
|
||||||
// Supported first compressors:
|
// Supported first compressors:
|
||||||
// .tar and .zip
|
// .tar and .zip
|
||||||
let first_compressor: Option<Box<dyn Compressor>> = match extension.first_ext {
|
let first_compressor: Option<Box<dyn Compressor>> = match &extension.first_ext {
|
||||||
Some(ext) => match ext {
|
Some(ext) => match ext {
|
||||||
CompressionFormat::Tar => Some(Box::new(TarCompressor)),
|
CompressionFormat::Tar => Some(Box::new(TarCompressor)),
|
||||||
CompressionFormat::Zip => Some(Box::new(ZipCompressor)),
|
CompressionFormat::Zip => Some(Box::new(ZipCompressor)),
|
||||||
@ -84,7 +84,7 @@ fn get_compressor(file: &File) -> crate::Result<(Option<BoxedCompressor>, BoxedC
|
|||||||
|
|
||||||
fn get_decompressor(file: &File) -> crate::Result<(Option<BoxedDecompressor>, BoxedDecompressor)> {
|
fn get_decompressor(file: &File) -> crate::Result<(Option<BoxedDecompressor>, BoxedDecompressor)> {
|
||||||
let extension = match &file.extension {
|
let extension = match &file.extension {
|
||||||
Some(extension) => extension.clone(),
|
Some(extension) => extension,
|
||||||
None => {
|
None => {
|
||||||
// This block *should* be unreachable
|
// This block *should* be unreachable
|
||||||
eprintln!(
|
eprintln!(
|
||||||
@ -104,7 +104,7 @@ fn get_decompressor(file: &File) -> crate::Result<(Option<BoxedDecompressor>, Bo
|
|||||||
CompressionFormat::Bzip => Box::new(BzipDecompressor),
|
CompressionFormat::Bzip => Box::new(BzipDecompressor),
|
||||||
};
|
};
|
||||||
|
|
||||||
let first_decompressor: Option<Box<dyn Decompressor>> = match extension.first_ext {
|
let first_decompressor: Option<Box<dyn Decompressor>> = match &extension.first_ext {
|
||||||
Some(ext) => match ext {
|
Some(ext) => match ext {
|
||||||
CompressionFormat::Tar => Some(Box::new(TarDecompressor)),
|
CompressionFormat::Tar => Some(Box::new(TarDecompressor)),
|
||||||
CompressionFormat::Zip => Some(Box::new(ZipDecompressor)),
|
CompressionFormat::Zip => Some(Box::new(ZipDecompressor)),
|
||||||
|
@ -105,7 +105,7 @@ pub fn permission_for_overwriting(
|
|||||||
flags: &oof::Flags,
|
flags: &oof::Flags,
|
||||||
confirm: &Confirmation,
|
confirm: &Confirmation,
|
||||||
) -> crate::Result<bool> {
|
) -> crate::Result<bool> {
|
||||||
match (flags.is_present("yes"), flags.is_present("false")) {
|
match (flags.is_present("yes"), flags.is_present("no")) {
|
||||||
(true, true) => {
|
(true, true) => {
|
||||||
unreachable!("This should've been cutted out in the ~/src/cli.rs filter flags function.")
|
unreachable!("This should've been cutted out in the ~/src/cli.rs filter flags function.")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user