Skip to content

Commit

Permalink
New --help message
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19 committed Apr 7, 2021
1 parent 973af5f commit df1bc87
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ description = "A command-line utility for easily compressing and decompressing f

[dependencies]
colored = "2.0.0"
termion = "1.5.6"
walkdir = "2.3.2"
tar = "0.4.33"
xz2 = "0.1.6"
Expand Down
20 changes: 2 additions & 18 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,12 @@ pub fn run(command: Command, flags: &oof::Flags) -> crate::Result<()> {
decompress_file(file, output_folder, flags)?;
}
}
Command::ShowHelp => help_command(),
Command::ShowVersion => version_command(),
Command::ShowHelp => crate::help_command(),
Command::ShowVersion => crate::version_command(),
}
Ok(())
}

fn help_command() {
version_command();
println!("Vinícius R. M. & João M. Bezerra");
println!("ouch is a unified compression & decompression utility");
println!();
println!(" COMPRESSION USAGE:");
println!(" ouch compress <input...> output-file");
println!("DECOMPRESSION USAGE:");
println!(" ouch <input> [-o/--output output-folder]");
}

#[inline]
fn version_command() {
println!("ouch {}", crate::VERSION);
}

type BoxedCompressor = Box<dyn Compressor>;
type BoxedDecompressor = Box<dyn Decompressor>;

Expand Down
67 changes: 66 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,71 @@ mod extension;
mod file;
mod utils;

pub use error::{Error, Result};

const VERSION: &str = "0.1.5";

pub use error::{Error, Result};
fn help_command() {
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!(
"\
{cyan}ouch{reset} - Obvious Unified Compression files Helper
{cyan}USAGE:{reset}
{green}ouch {magenta}<files...>{reset} Decompresses files.
{green}ouch compress {magenta}<files...> OUTPUT.EXT{reset} Compresses files into {magenta}OUTPUT.EXT{reset},
where {magenta}EXT{reset} must be a supported format.
{cyan}FLAGS:{reset}
{yellow}-h{white}, {yellow}--help{reset} Display this help information.
{yellow}-y{white}, {yellow}--yes{reset} Skip overwrite questions.
{yellow}-n{white}, {yellow}--no{reset} Skip overwrite questions.
{yellow}--version{reset} Display version information.
{cyan}SPECIFIC FLAGS:{reset}
{yellow}-o{reset}, {yellow}--output{reset} FOLDER_PATH When decompressing, to decompress files to
another folder.
Visit https://github.com/vrmiguel/ouch for more usage examples.",
magenta = magenta(),
white = white(),
green = green(),
yellow = yellow(),
reset = reset(),
cyan = cyan()
);
}

#[inline]
fn version_command() {
use utils::colors::*;
println!(
"{green}ouch{reset} {}",
crate::VERSION,
green = green(),
reset = reset(),
);
}
33 changes: 33 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,39 @@ pub struct Bytes {
bytes: f64,
}

#[allow(dead_code)]
pub mod colors {
use termion::color::*;

pub fn reset() -> &'static str {
Reset.fg_str()
}
pub fn black() -> &'static str {
LightBlack.fg_str()
}
pub fn blue() -> &'static str {
LightBlue.fg_str()
}
pub fn cyan() -> &'static str {
LightCyan.fg_str()
}
pub fn green() -> &'static str {
LightGreen.fg_str()
}
pub fn magenta() -> &'static str {
LightMagenta.fg_str()
}
pub fn red() -> &'static str {
LightRed.fg_str()
}
pub fn white() -> &'static str {
LightWhite.fg_str()
}
pub fn yellow() -> &'static str {
LightYellow.fg_str()
}
}

impl Bytes {
const UNIT_PREFIXES: [&'static str; 6] = ["", "k", "M", "G", "T", "P"];

Expand Down

0 comments on commit df1bc87

Please sign in to comment.