cli/
metadata.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15mod control;
16mod repair;
17mod snapshot;
18mod utils;
19
20use clap::Subcommand;
21use common_error::ext::BoxedError;
22
23use crate::Tool;
24use crate::metadata::control::{DelCommand, GetCommand};
25use crate::metadata::repair::RepairLogicalTablesCommand;
26use crate::metadata::snapshot::SnapshotCommand;
27
28/// Command for managing metadata operations,
29/// including saving and restoring metadata snapshots,
30/// controlling metadata operations, and diagnosing and repairing metadata.
31#[derive(Subcommand)]
32pub enum MetadataCommand {
33    #[clap(subcommand)]
34    Snapshot(SnapshotCommand),
35    #[clap(subcommand)]
36    Get(GetCommand),
37    #[clap(subcommand)]
38    Del(DelCommand),
39    RepairLogicalTables(RepairLogicalTablesCommand),
40}
41
42impl MetadataCommand {
43    pub async fn build(&self) -> Result<Box<dyn Tool>, BoxedError> {
44        match self {
45            MetadataCommand::Snapshot(cmd) => cmd.build().await,
46            MetadataCommand::RepairLogicalTables(cmd) => cmd.build().await,
47            MetadataCommand::Get(cmd) => cmd.build().await,
48            MetadataCommand::Del(cmd) => cmd.build().await,
49        }
50    }
51}