cli/metadata/control/
put.rs1mod key;
16mod table;
17
18use clap::Subcommand;
19use common_error::ext::BoxedError;
20use snafu::ResultExt;
21use tokio::io::{AsyncRead, AsyncReadExt};
22
23use crate::Tool;
24use crate::error::FileIoSnafu;
25use crate::metadata::control::put::key::PutKeyCommand;
26use crate::metadata::control::put::table::PutTableCommand;
27
28pub(crate) async fn read_value<R>(mut reader: R) -> Result<Vec<u8>, BoxedError>
29where
30 R: AsyncRead + Unpin,
31{
32 let mut value = Vec::new();
33 reader
34 .read_to_end(&mut value)
35 .await
36 .context(FileIoSnafu)
37 .map_err(BoxedError::new)?;
38 Ok(value)
39}
40
41#[derive(Subcommand)]
43pub enum PutCommand {
44 Key(PutKeyCommand),
45 #[clap(subcommand)]
46 Table(PutTableCommand),
47}
48
49impl PutCommand {
50 pub async fn build(&self) -> Result<Box<dyn Tool>, BoxedError> {
51 match self {
52 PutCommand::Key(cmd) => cmd.build().await,
53 PutCommand::Table(cmd) => cmd.build().await,
54 }
55 }
56}