diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..8febf4e --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,42 @@ +use std::path::PathBuf; + +use clap::{Parser, ValueEnum}; + +/// Simple program to greet a person +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +pub struct Args { + /// Compress or Decompress files name + #[arg(required = true)] + pub files: Vec, + + /// Whether to decompress the input + #[arg(short, long)] + decompress: bool, + + /// Put passwords on compressed files + #[arg(short, long)] + encrypt: bool, + + #[arg(short, long)] + #[clap(value_enum, default_value_t=Format::Zip)] + pub format: Format, + + /// Whether to recursively greet + #[arg(short, long)] + recursive: bool, + + /// Verbose mode + #[arg(short, long)] + verbose: bool, + + /// Number of compressions to perform + #[arg(short, long, default_value = "6")] + pub count: u32, +} + +#[derive(ValueEnum, Clone, Debug)] +pub enum Format { + Gzip, + Zip, +} diff --git a/src/main.rs b/src/main.rs index 7250b4d..393921a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,65 +1,27 @@ -use clap::{Parser, ValueEnum}; +use clap::Parser; -/// Simple program to greet a person -#[derive(Parser, Debug)] -#[command(version, about, long_about = None)] -struct Args { - /// Compress or Decompress file name - #[arg(value_name = "FILE")] - file: String, - - /// Multiple File Designation - #[arg(last=true)] - multiple_files: Vec, - - /// Whether to decompress the input - #[arg(short, long)] - decompress: bool, - - /// Put passwords on compressed files - #[arg(short, long)] - encrypt: bool, - - #[arg(short, long)] - #[clap(value_enum, default_value_t=Format::Zip)] - format: Format, - - /// Whether to recursively greet - #[arg(short, long)] - recursive: bool, - - /// Verbose mode - #[arg(short, long)] - verbose: bool, - - /// Number of compressions to perform - #[arg(short, long, default_value = "6")] - count: u32, -} - -#[derive(ValueEnum, Clone, Debug)] -enum Format { - Gzip, - Zip, -} - -fn hello() -> String { - "Hello, world!".to_string() -} +mod cli; fn main() { - let _args = Args::parse(); + let args = cli::Args::parse(); - println!("Hello, world!"); - println!("{}", hello()); + print!("{:?}", args); } #[cfg(test)] mod tests { + use std::path::PathBuf; + use super::*; #[test] - fn test_hello() { - assert_eq!(hello(), "Hello, world!"); + fn test_run() { + let opts = + cli::Args::parse_from(&["unicom", "-f", "zip", "-r", "-c", "8", "file1", "file2"]); + assert_eq!( + opts.files, + vec![PathBuf::from("file1"), PathBuf::from("file2")] + ); + assert_eq!(opts.count, 8); } }