Skip to content

Commit

Permalink
src/main.rs : make -d directory optional as intended
Browse files Browse the repository at this point in the history
Signed-off-by: Graeme Gregory <[email protected]>
  • Loading branch information
xXorAa committed Feb 9, 2023
1 parent e7a4101 commit daedad3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use clap::Parser;
struct Args {
/// directory to extract to
#[arg(short = 'd')]
directory: String,
directory: Option<String>,

/// escpae the filenames sQLux/Q-Emulator style
#[arg(short = 'e')]
Expand Down Expand Up @@ -159,8 +159,13 @@ fn real_main() -> i32 {
let file = fs::File::open(args.file).unwrap();
let mut archive = zip::ZipArchive::new(file).unwrap();

if !args.directory.is_empty() {
let path = Path::new(&args.directory);
let dirname = match args.directory {
Some(ref x) => x,
None => ""
};

if !dirname.is_empty() {
let path = Path::new(dirname);
fs::create_dir_all(&path).unwrap();
}

Expand Down Expand Up @@ -194,9 +199,9 @@ fn real_main() -> i32 {
escape_filename(&mut name);
}

if !args.directory.is_empty() {
if !dirname.is_empty() {
name.insert(0, '/');
name.insert_str(0, &args.directory);
name.insert_str(0, dirname);
}

println!("Extracting: {}", name);
Expand Down

0 comments on commit daedad3

Please sign in to comment.