-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathshow.rs
77 lines (63 loc) · 1.98 KB
/
show.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use clap::Parser;
use secrecy::{ExposeSecret, Secret};
use std::error::Error;
use url::Url;
use crate::commands::common::Format;
mod system;
use system::SystemConfig;
#[derive(Debug, Parser)]
pub struct Config {
#[clap(subcommand)]
cmd: SubCommand,
}
#[derive(Debug, Parser)]
pub enum SubCommand {
/// List databases
Databases(DatabaseConfig),
/// Display system table data.
System(SystemConfig),
}
#[derive(Debug, Parser)]
pub struct DatabaseConfig {
/// The host URL of the running InfluxDB 3 Core server
#[clap(
short = 'H',
long = "host",
env = "INFLUXDB3_HOST_URL",
default_value = "http://127.0.0.1:8181"
)]
host_url: Url,
/// The token for authentication with the InfluxDB 3 Core server
#[clap(long = "token", env = "INFLUXDB3_AUTH_TOKEN")]
auth_token: Option<Secret<String>>,
/// Include databases that were marked as deleted in the output
#[clap(long = "show-deleted", default_value = "false")]
show_deleted: bool,
/// The format in which to output the list of databases
#[clap(value_enum, long = "format", default_value = "pretty")]
output_format: Format,
}
pub(crate) async fn command(config: Config) -> Result<(), Box<dyn Error>> {
match config.cmd {
SubCommand::Databases(DatabaseConfig {
host_url,
auth_token,
show_deleted,
output_format,
}) => {
let mut client = influxdb3_client::Client::new(host_url)?;
if let Some(t) = auth_token {
client = client.with_auth_token(t.expose_secret());
}
let resp_bytes = client
.api_v3_configure_db_show()
.with_format(output_format.into())
.with_show_deleted(show_deleted)
.send()
.await?;
println!("{}", std::str::from_utf8(&resp_bytes)?);
}
SubCommand::System(cfg) => system::command(cfg).await?,
}
Ok(())
}