Skip to content

Commit

Permalink
♻️ use Command trait
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanTsune committed Sep 21, 2023
1 parent d2470de commit 3a17907
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
15 changes: 4 additions & 11 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@ use std::io;

pub fn entry(cli: Cli) -> io::Result<()> {
match cli.commands {
Commands::Create(args) => {
args.execute(cli.verbosity.verbosity())?;
}
Commands::Append(args) => append::append_to_archive(args, cli.verbosity.verbosity())?,
Commands::Extract(args) => {
args.execute(cli.verbosity.verbosity())?;
}
Commands::List(args) => {
args.execute(cli.verbosity.verbosity())?;
}
Commands::Create(args) => args.execute(cli.verbosity.verbosity()),
Commands::Append(args) => args.execute(cli.verbosity.verbosity()),
Commands::Extract(args) => args.execute(cli.verbosity.verbosity()),
Commands::List(args) => args.execute(cli.verbosity.verbosity()),
}
Ok(())
}

fn ask_password(args: PasswordArgs) -> io::Result<Option<String>> {
Expand Down
15 changes: 12 additions & 3 deletions cli/src/command/append.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
use crate::command::commons::{create_entry, entry_option};
use crate::{
cli::{AppendArgs, Verbosity},
command::{ask_password, check_password, commons::collect_items},
command::{
ask_password, check_password,
commons::{collect_items, create_entry, entry_option},
Command,
},
};
use libpna::ArchiveReader;
use rayon::ThreadPoolBuilder;
use std::fs::File;
use std::io;

pub(crate) fn append_to_archive(args: AppendArgs, verbosity: Verbosity) -> io::Result<()> {
impl Command for AppendArgs {
fn execute(self, verbosity: Verbosity) -> io::Result<()> {
append_to_archive(self, verbosity)
}
}

fn append_to_archive(args: AppendArgs, verbosity: Verbosity) -> io::Result<()> {
let password = ask_password(args.password)?;
check_password(&password, &args.cipher);
let archive = args.file.archive;
Expand Down

0 comments on commit 3a17907

Please sign in to comment.