fjall_cli/command/
list_keyspace_names_command.rs1use errgonomic::handle;
2use fjall::Database;
3use std::io;
4use std::io::Write;
5use std::process::ExitCode;
6use thiserror::Error;
7
8#[derive(clap::Parser, Clone, Debug)]
9pub struct ListKeyspaceNamesCommand {}
10
11impl ListKeyspaceNamesCommand {
12 pub async fn run(self, db: &Database) -> Result<ExitCode, ListKeyspaceNamesCommandRunError> {
13 use ListKeyspaceNamesCommandRunError::*;
14 let mut stdout = io::stdout().lock();
15 let result = db.list_keyspace_names().into_iter().try_for_each(|name| {
16 stdout
17 .write_all(name.as_bytes())
18 .and_then(|()| stdout.write_all(b"\n"))
19 });
20 handle!(result, WriteFailed);
21 Ok(ExitCode::SUCCESS)
22 }
23}
24
25#[derive(Error, Debug)]
26pub enum ListKeyspaceNamesCommandRunError {
27 #[error("failed to write keyspace names to stdout")]
28 WriteFailed { source: io::Error },
29}