fjall_cli/command/keyspace_command/
delete_command.rs1use errgonomic::{handle, handle_bool};
2use fjall::{Database, KeyspaceCreateOptions};
3use std::process::ExitCode;
4use thiserror::Error;
5
6#[derive(clap::Parser, Clone, Debug)]
7pub struct DeleteCommand {}
8
9impl DeleteCommand {
10 pub async fn run(self, db: &Database, keyspace: impl Into<String>) -> Result<ExitCode, DeleteCommandRunError> {
11 use DeleteCommandRunError::*;
12 let keyspace = keyspace.into();
13 handle_bool!(!db.keyspace_exists(&keyspace), KeyspaceNotFound, keyspace);
14 let keyspace_handle = handle!(db.keyspace(&keyspace, KeyspaceCreateOptions::default), KeyspaceFailed, keyspace);
15 handle!(db.delete_keyspace(keyspace_handle), DeleteKeyspaceFailed, keyspace);
16 Ok(ExitCode::SUCCESS)
17 }
18}
19
20#[derive(Error, Debug)]
21pub enum DeleteCommandRunError {
22 #[error("keyspace '{keyspace}' not found")]
23 KeyspaceNotFound { keyspace: String },
24
25 #[error("failed to open keyspace '{keyspace}'")]
26 KeyspaceFailed { source: fjall::Error, keyspace: String },
27
28 #[error("failed to delete keyspace '{keyspace}'")]
29 DeleteKeyspaceFailed { source: fjall::Error, keyspace: String },
30}