-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PathBuf>, | ||
|
||
/// 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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String>, | ||
|
||
/// 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); | ||
} | ||
} |