Skip to content

Commit

Permalink
refactor: add simple clap cli.
Browse files Browse the repository at this point in the history
  • Loading branch information
UserIsntAvailable committed Oct 30, 2024
1 parent 51fc305 commit 3d94f6b
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 6 deletions.
193 changes: 193 additions & 0 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 ashen/src/asset/pack_file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This only works with the last version of Ashen :).
mod directory;
pub mod directory;

use crate::utils::nom::*;

Expand Down
6 changes: 3 additions & 3 deletions ashen/src/asset/pack_file/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ impl FileHandle {
}

#[derive(Default, Debug)]
struct PackFileDirectory {
pub struct VirtualFileSystem {
files: BTreeMap<PathBuf, FileHandle>,
}

impl PackFileDirectory {
impl VirtualFileSystem {
pub fn from_106_packfile(pack: PackFile) -> Option<Self> {
let mut files = BTreeMap::new();

Expand Down Expand Up @@ -250,7 +250,7 @@ mod tests {
fn packfile_directory_works() -> eyre::Result<()> {
let (_, pack_file) = PackFile::new(&ROM_DATA)?;

let dir = PackFileDirectory::from_106_packfile(pack_file).unwrap();
let dir = VirtualFileSystem::from_106_packfile(pack_file).unwrap();
let dir = dir.walk("/", true)?;

for file in dir {
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ edition = "2021"

[dependencies]
ashen = { path = "../ashen/" }
clap = { version = "4.5.20", features = ["derive"] }
39 changes: 37 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
fn main() {
println!("Hello, world!");
use std::{error::Error, io, path::PathBuf};

use ashen::asset::pack_file::{directory::VirtualFileSystem, PackFile};
use clap::Parser;

#[derive(Parser)]
#[command(version, about)]
pub enum Cli {
/// Output packfile contents.
Output {
/// The path of the 'pack'.file
path: PathBuf,
},
}

// enum AssetKind {
// Copyright,
// }

fn main() -> Result<(), Box<dyn Error>> {
let cli = Cli::parse();

match cli {
Cli::Output { path } => {
let pack = std::fs::read(path)?;
let (_, pack) = PackFile::new(&pack)?;

let dir = VirtualFileSystem::from_106_packfile(pack)
.ok_or_else(|| io::Error::from(io::ErrorKind::InvalidInput))?;

let handle = dir.read("/copyright")?;

std::fs::write("./output/cli/copyright.txt", handle.bytes())?;
}
}

Ok(())
}

0 comments on commit 3d94f6b

Please sign in to comment.