Skip to content

Commit

Permalink
change function for building ExtractorOpts object in order to make ar…
Browse files Browse the repository at this point in the history
…range the interface same with ArchiverOpts
  • Loading branch information
tamada committed May 3, 2024
1 parent 25de98e commit 08c030d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ pub struct ExtractorOpts {
}

impl ExtractorOpts {
pub fn new(opts: &CliOpts) -> ExtractorOpts {
let d = opts.output.clone();
ExtractorOpts {
dest: d.unwrap_or_else(|| {
PathBuf::from(".")
}),
use_archive_name_dir: opts.to_archive_name_dir,
overwrite: opts.overwrite,
v: create_verboser(opts.verbose),
}
}

pub fn destination(&self, target: &PathBuf) -> PathBuf {
if self.use_archive_name_dir {
let file_name = target.file_name().unwrap().to_str().unwrap();
Expand All @@ -36,18 +48,6 @@ pub trait Extractor {
fn format(&self) -> Format;
}

pub fn create_extract_opts(opts: &CliOpts) -> ExtractorOpts {
let d = opts.output.clone();
ExtractorOpts {
dest: d.unwrap_or_else(|| {
PathBuf::from(".")
}),
use_archive_name_dir: opts.to_archive_name_dir,
overwrite: opts.overwrite,
v: create_verboser(opts.verbose),
}
}

pub fn create_extractor(file: &PathBuf) -> Result<Box<dyn Extractor>> {
let format = find_format(file.file_name());
match format {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::Parser;
use cli::*;
use cli::{ToatError, RunMode};
use archiver::{archiver_info, ArchiverOpts};
use extractor::{create_extract_opts, extractor_info};
use extractor::{extractor_info, ExtractorOpts};

mod cli;
mod format;
Expand Down Expand Up @@ -32,7 +32,7 @@ fn perform(mut opts: CliOpts) -> Result<()> {

fn perform_extract(opts: CliOpts) -> Result<()> {
let args = opts.args.clone();
let extract_opts = create_extract_opts(&opts);
let extract_opts = ExtractorOpts::new(&opts);
for arg in args.iter() {
let extractor = extractor::create_extractor(arg).unwrap();
let target = arg.to_path_buf();
Expand Down

0 comments on commit 08c030d

Please sign in to comment.