diff --git a/Cargo.toml b/Cargo.toml index dd05ee3c3..b1617547a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/commands.rs b/src/commands.rs index 8e006347e..254722627 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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 output-file"); - println!("DECOMPRESSION USAGE:"); - println!(" ouch [-o/--output output-folder]"); -} - -#[inline] -fn version_command() { - println!("ouch {}", crate::VERSION); -} - type BoxedCompressor = Box; type BoxedDecompressor = Box; diff --git a/src/lib.rs b/src/lib.rs index 77090c3e6..fa9bad72a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 Decompresses files. + + ouch compress 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}{reset} Decompresses files. + + {green}ouch compress {magenta} 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(), + ); +} diff --git a/src/utils.rs b/src/utils.rs index 64df0e037..736628bd3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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"];