Skip to main content

fjall_cli/command/
keyspace_count_command.rs

1use 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 KeyspaceCountCommand {}
10
11impl KeyspaceCountCommand {
12    pub async fn run(self, db: &Database) -> Result<ExitCode, KeyspaceCountCommandRunError> {
13        use KeyspaceCountCommandRunError::*;
14        let count = db.keyspace_count();
15        let mut stdout = io::stdout().lock();
16        handle!(writeln!(stdout, "{count}"), WriteFailed);
17        Ok(ExitCode::SUCCESS)
18    }
19}
20
21#[derive(Error, Debug)]
22pub enum KeyspaceCountCommandRunError {
23    #[error("failed to write keyspace count to stdout")]
24    WriteFailed { source: io::Error },
25}