Skip to content

Commit

Permalink
feat: Added archive creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Le0X8 committed Aug 2, 2024
1 parent 75d5440 commit b8c2761
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
acridotheres_core = { git = "https://github.com/acridotheres/core.git", tag="v0.2.1" }
acridotheres_core = { git = "https://github.com/acridotheres/core.git", tag="v0.2.2" }
byte-unit = { version = "5.1.4", features = ["u128"] }
clap = { version = "4.5.7", features = ["derive"] }
1 change: 1 addition & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod create;
pub mod extract;
pub mod list;
pub mod metadata;
Expand Down
31 changes: 31 additions & 0 deletions src/commands/create.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use corelib::{archive::{self, EntrySource}, file::FsFile, formats};

pub fn create(
format: String,
input: String,
output: String,
buffer_size: u64,
) {
let files: Vec<EntrySource> = input.split(';').map(|file| {
let file = file.split(':').collect::<Vec<&str>>();
let source_path = file.get(0).unwrap();
let mut target_path = source_path;
match file.get(1) {
Some(path) => {
target_path = path;
}
None => {}
}
EntrySource {
path: target_path.to_string(),
source: FsFile::new(&source_path.to_string()),
}
}).collect();
archive::create(
formats::from_string(&format),
output,
files,
buffer_size,
)
.unwrap();
}
14 changes: 13 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Args {
#[arg(short = 't', long = "type")]
input_type: Option<String>,

/// Path to input file
/// Path to input file (if creating, multiple files can be separated by semicolons)
#[arg(short, long)]
input: Option<String>,

Expand All @@ -34,6 +34,10 @@ struct Args {
#[arg(short = 'x', long = "extract")]
extract: bool,

/// Create archive
#[arg(short, long)]
create: bool,

/// by path
#[arg(short = 'p', long = "path", value_name = "PATH")]
path: Option<String>,
Expand Down Expand Up @@ -64,6 +68,8 @@ fn get_command(args: &Args) -> &'static str {
"list"
} else if args.extract {
"extract"
} else if args.create {
"create"
} else {
""
}
Expand Down Expand Up @@ -98,6 +104,12 @@ fn main() {
!args.skip_integrity_checks,
args.buffer,
),
"create" => commands::create::create(
args.input_type.unwrap(),
args.input.unwrap(),
args.output.unwrap(),
args.buffer,
),
_ => println!("Nothing to do, try --help"),
}
}

0 comments on commit b8c2761

Please sign in to comment.