mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 11:35:45 +00:00
Make decompress command explicit
- No subcommand given now calls the help menu - Also added docs for the short version of compress and decompress
This commit is contained in:
parent
f7139548f6
commit
788809b8f3
12
README.md
12
README.md
@ -28,17 +28,20 @@ Run `ouch` and pass compressed files as arguments.
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Decompress 'a.zip'
|
# Decompress 'a.zip'
|
||||||
ouch a.zip
|
ouch decompress a.zip
|
||||||
|
|
||||||
|
# Also works with the short version
|
||||||
|
ouch d a.zip
|
||||||
|
|
||||||
# Decompress multiple files
|
# Decompress multiple files
|
||||||
ouch a.zip b.tar.gz
|
ouch decompress a.zip b.tar.gz
|
||||||
```
|
```
|
||||||
|
|
||||||
You can redirect the decompression results to a folder with the `-o/--output` flag.
|
You can redirect the decompression results to a folder with the `-o/--output` flag.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Create 'pictures' folder and decompress inside of it
|
# Create 'pictures' folder and decompress inside of it
|
||||||
ouch a.zip -o pictures
|
ouch decompress a.zip -o pictures
|
||||||
```
|
```
|
||||||
|
|
||||||
### Compressing
|
### Compressing
|
||||||
@ -51,6 +54,9 @@ Accepts multiple files and folders, the **last** argument shall be the **output
|
|||||||
# Compress four files into 'archive.zip'
|
# Compress four files into 'archive.zip'
|
||||||
ouch compress 1 2 3 4 archive.zip
|
ouch compress 1 2 3 4 archive.zip
|
||||||
|
|
||||||
|
# Also works with the short version
|
||||||
|
ouch c 1 2 3 4 archive.zip
|
||||||
|
|
||||||
# Compress folder and video into 'videos.tar.gz'
|
# Compress folder and video into 'videos.tar.gz'
|
||||||
ouch compress videos/ meme.mp4 videos.tar.gz
|
ouch compress videos/ meme.mp4 videos.tar.gz
|
||||||
|
|
||||||
|
23
src/cli.rs
23
src/cli.rs
@ -98,7 +98,7 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {
|
|||||||
return Ok(ParsedArgs { command: Command::ShowVersion, flags: oof::Flags::default() });
|
return Ok(ParsedArgs { command: Command::ShowVersion, flags: oof::Flags::default() });
|
||||||
}
|
}
|
||||||
|
|
||||||
let subcommands = &["c", "compress"];
|
let subcommands = &["c", "compress", "d", "decompress"];
|
||||||
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) {
|
||||||
@ -117,8 +117,7 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {
|
|||||||
let command = Command::Compress { files, output_path };
|
let command = Command::Compress { files, output_path };
|
||||||
ParsedArgs { command, flags }
|
ParsedArgs { command, flags }
|
||||||
}
|
}
|
||||||
// Defaults to decompression when there is no subcommand
|
Some(&"d") | Some(&"decompress") => {
|
||||||
None => {
|
|
||||||
flags_info.push(arg_flag!('o', "output"));
|
flags_info.push(arg_flag!('o', "output"));
|
||||||
|
|
||||||
if let Some(first_arg) = args.first() {
|
if let Some(first_arg) = args.first() {
|
||||||
@ -140,6 +139,10 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {
|
|||||||
let command = Command::Decompress { files, output_folder };
|
let command = Command::Decompress { files, output_folder };
|
||||||
ParsedArgs { command, flags }
|
ParsedArgs { command, flags }
|
||||||
}
|
}
|
||||||
|
// Defaults to help when there is no subcommand
|
||||||
|
None => {
|
||||||
|
return Ok(ParsedArgs { command: Command::ShowHelp, flags: oof::Flags::default() });
|
||||||
|
}
|
||||||
_ => unreachable!("You should match each subcommand passed."),
|
_ => unreachable!("You should match each subcommand passed."),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -163,18 +166,28 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cli_commands() {
|
fn test_cli_commands() {
|
||||||
|
assert_eq!(test_cli("").unwrap().command, Command::ShowHelp);
|
||||||
assert_eq!(test_cli("--help").unwrap().command, Command::ShowHelp);
|
assert_eq!(test_cli("--help").unwrap().command, Command::ShowHelp);
|
||||||
assert_eq!(test_cli("--version").unwrap().command, Command::ShowVersion);
|
assert_eq!(test_cli("--version").unwrap().command, Command::ShowVersion);
|
||||||
assert_eq!(test_cli("--version").unwrap().flags, oof::Flags::default());
|
assert_eq!(test_cli("--version").unwrap().flags, oof::Flags::default());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
test_cli("foo.zip bar.zip").unwrap().command,
|
test_cli("decompress foo.zip bar.zip").unwrap().command,
|
||||||
|
Command::Decompress { files: vec!["foo.zip".into(), "bar.zip".into()], output_folder: None }
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
test_cli("d foo.zip bar.zip").unwrap().command,
|
||||||
Command::Decompress { files: vec!["foo.zip".into(), "bar.zip".into()], output_folder: None }
|
Command::Decompress { files: vec!["foo.zip".into(), "bar.zip".into()], output_folder: None }
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
test_cli("compress foo bar baz.zip").unwrap().command,
|
test_cli("compress foo bar baz.zip").unwrap().command,
|
||||||
Command::Compress { files: vec!["foo".into(), "bar".into()], output_path: "baz.zip".into() }
|
Command::Compress { files: vec!["foo".into(), "bar".into()], output_path: "baz.zip".into() }
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
test_cli("c foo bar baz.zip").unwrap().command,
|
||||||
|
Command::Compress { files: vec!["foo".into(), "bar".into()], output_path: "baz.zip".into() }
|
||||||
|
);
|
||||||
assert_eq!(test_cli("compress").unwrap_err(), Error::MissingArgumentsForCompression);
|
assert_eq!(test_cli("compress").unwrap_err(), Error::MissingArgumentsForCompression);
|
||||||
|
// assert_eq!(test_cli("decompress").unwrap_err(), Error::MissingArgumentsForCompression); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -184,7 +197,7 @@ mod tests {
|
|||||||
assert_eq!(test_cli("--version").unwrap().flags, oof::Flags::default());
|
assert_eq!(test_cli("--version").unwrap().flags, oof::Flags::default());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
test_cli("foo --yes bar --output folder").unwrap().flags,
|
test_cli("decompress foo --yes bar --output folder").unwrap().flags,
|
||||||
oof::Flags {
|
oof::Flags {
|
||||||
boolean_flags: vec!["yes"].into_iter().collect(),
|
boolean_flags: vec!["yes"].into_iter().collect(),
|
||||||
argument_flags: vec![("output", OsString::from("folder"))].into_iter().collect(),
|
argument_flags: vec![("output", OsString::from("folder"))].into_iter().collect(),
|
||||||
|
29
src/lib.rs
29
src/lib.rs
@ -35,38 +35,21 @@ lazy_static! {
|
|||||||
|
|
||||||
fn help_command() {
|
fn help_command() {
|
||||||
use utils::colors::*;
|
use utils::colors::*;
|
||||||
/*
|
|
||||||
ouch - Obvious Unified Compressed files Helper
|
|
||||||
|
|
||||||
USAGE:
|
|
||||||
ouch <files...> Decompresses files.
|
|
||||||
|
|
||||||
ouch compress <files...> OUTPUT.EXT Compresses files into OUTPUT.EXT,
|
|
||||||
where EXT must be a supported format.
|
|
||||||
|
|
||||||
FLAGS:
|
|
||||||
-h, --help Display this help information.
|
|
||||||
-y, --yes Skip overwrite questions.
|
|
||||||
-n, --no Skip overwrite questions.
|
|
||||||
--version Display version information.
|
|
||||||
|
|
||||||
SPECIFIC FLAGS:
|
|
||||||
-o, --output FOLDER_PATH When decompressing, to decompress files to
|
|
||||||
another folder.
|
|
||||||
|
|
||||||
Visit https://github.com/vrmiguel/ouch for more usage examples.
|
|
||||||
*/
|
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"\
|
"\
|
||||||
{cyan}ouch{reset} - Obvious Unified Compression files Helper
|
{cyan}ouch{reset} - Obvious Unified Compression files Helper
|
||||||
|
|
||||||
{cyan}USAGE:{reset}
|
{cyan}USAGE:{reset}
|
||||||
{green}ouch {magenta}<files...>{reset} Decompresses files.
|
{green}ouch decompress {magenta}<files...>{reset} Decompresses files.
|
||||||
|
|
||||||
{green}ouch compress {magenta}<files...> OUTPUT.EXT{reset} Compresses files into {magenta}OUTPUT.EXT{reset},
|
{green}ouch compress {magenta}<files...> OUTPUT.EXT{reset} Compresses files into {magenta}OUTPUT.EXT{reset},
|
||||||
where {magenta}EXT{reset} must be a supported format.
|
where {magenta}EXT{reset} must be a supported format.
|
||||||
|
|
||||||
|
{cyan}ALIASES:{reset}
|
||||||
|
{green}d decompress {reset}
|
||||||
|
{green}c compress {reset}
|
||||||
|
|
||||||
{cyan}FLAGS:{reset}
|
{cyan}FLAGS:{reset}
|
||||||
{yellow}-h{white}, {yellow}--help{reset} Display this help information.
|
{yellow}-h{white}, {yellow}--help{reset} Display this help information.
|
||||||
{yellow}-y{white}, {yellow}--yes{reset} Skip overwrite questions.
|
{yellow}-y{white}, {yellow}--yes{reset} Skip overwrite questions.
|
||||||
@ -77,7 +60,7 @@ fn help_command() {
|
|||||||
{yellow}-o{reset}, {yellow}--output{reset} FOLDER_PATH When decompressing, to decompress files to
|
{yellow}-o{reset}, {yellow}--output{reset} FOLDER_PATH When decompressing, to decompress files to
|
||||||
another folder.
|
another folder.
|
||||||
|
|
||||||
Visit https://github.com/vrmiguel/ouch for more usage examples.",
|
Visit https://github.com/ouch-org/ouch for more usage examples.",
|
||||||
magenta = magenta(),
|
magenta = magenta(),
|
||||||
white = white(),
|
white = white(),
|
||||||
green = green(),
|
green = green(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user