-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8da30a
commit bce547d
Showing
5 changed files
with
301 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.