cli/
data.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 export;
16mod import;
17mod storage_export;
18
19use clap::Subcommand;
20use client::DEFAULT_CATALOG_NAME;
21use common_error::ext::BoxedError;
22
23use crate::Tool;
24use crate::data::export::ExportCommand;
25use crate::data::import::ImportCommand;
26
27pub(crate) const COPY_PATH_PLACEHOLDER: &str = "<PATH/TO/FILES>";
28
29/// Command for data operations including exporting data from and importing data into GreptimeDB.
30#[derive(Subcommand)]
31pub enum DataCommand {
32    Export(ExportCommand),
33    Import(ImportCommand),
34}
35
36impl DataCommand {
37    pub async fn build(&self) -> std::result::Result<Box<dyn Tool>, BoxedError> {
38        match self {
39            DataCommand::Export(cmd) => cmd.build().await,
40            DataCommand::Import(cmd) => cmd.build().await,
41        }
42    }
43}
44
45pub(crate) fn default_database() -> String {
46    format!("{DEFAULT_CATALOG_NAME}-*")
47}