Skip to content

Commit

Permalink
Added BELD tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
facundo-villa committed Apr 9, 2024
1 parent e8da30a commit bce547d
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 19 deletions.
121 changes: 121 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
workspace = { members = ["tests/gi"] }
workspace = { members = [ "beld","tests/gi"] }

[package]
name = "byte_engine"
Expand Down
10 changes: 10 additions & 0 deletions beld/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "beld"
version = "0.1.0"
edition = "2021"

[dependencies]
resource_management = { path = "../resource_management" }

clap = { version = "4.5.4", features = ["derive"] }
smol = "2.0.0"
75 changes: 75 additions & 0 deletions beld/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use clap::{Parser, Subcommand};
use resource_management::StorageBackend;

#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Cli {
/// The full path to the resources database. Example: ./resource/resources.db
#[arg(short, long)]
path: Option<String>,

#[command(subcommand)]
command: Commands,
}

#[derive(Subcommand)]
enum Commands {
/// Wipes all resources
Wipe {},
/// Lists all resources
List {},
/// Deletes a resource
Delete {
/// The ID of the resource to delete
id: String,
},
}

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

let command = cli.command;

let path = cli.path.unwrap_or("resources/resources.db".to_string());

let storage_backend = resource_management::DbStorageBackend::new(std::path::Path::new(&path));

match command {
Commands::Wipe { } => {
std::process::Command::new("rm").arg("-rf").arg("resources/*").spawn().unwrap();
std::process::Command::new("rm").arg("-rf").arg(".byte-editor/*").spawn().unwrap();
Ok(())
}
Commands::List { } => {
match smol::block_on(storage_backend.list()) {
Ok(resources) => {
if resources.is_empty() {
println!("No resources found.");
}

for resource in resources {
println!("{}", resource);
}

Ok(())
}
Err(e) => {
println!("Failed to list resources. Error: {}", e);
Err(1)
}
}
}
Commands::Delete { id } => {
match smol::block_on(storage_backend.delete(&id)) {
Ok(()) => {
println!("Deleted resource '{}'", id);
Ok(())
}
Err(e) => {
println!("Failed to delete '{}'. Error: {}", id, e);
Err(1)
}
}
}
}
}
Loading

0 comments on commit bce547d

Please sign in to comment.