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 common;
16mod control;
17mod repair;
18mod snapshot;
19mod utils;
20
21use clap::Subcommand;
22use common_error::ext::BoxedError;
23
24use crate::metadata::control::{DelCommand, GetCommand};
25use crate::metadata::repair::RepairLogicalTablesCommand;
26use crate::metadata::snapshot::SnapshotCommand;
27use crate::Tool;
28
29/// Command for managing metadata operations,
30/// including saving and restoring metadata snapshots,
31/// controlling metadata operations, and diagnosing and repairing metadata.
32#[derive(Subcommand)]
33pub enum MetadataCommand {
34    #[clap(subcommand)]
35    Snapshot(SnapshotCommand),
36    #[clap(subcommand)]
37    Get(GetCommand),
38    #[clap(subcommand)]
39    Del(DelCommand),
40    RepairLogicalTables(RepairLogicalTablesCommand),
41}
42
43impl MetadataCommand {
44    pub async fn build(&self) -> Result<Box<dyn Tool>, BoxedError> {
45        match self {
46            MetadataCommand::Snapshot(cmd) => cmd.build().await,
47            MetadataCommand::RepairLogicalTables(cmd) => cmd.build().await,
48            MetadataCommand::Get(cmd) => cmd.build().await,
49            MetadataCommand::Del(cmd) => cmd.build().await,
50        }
51    }
52}