Skip to content

Commit

Permalink
transform CLI command "query clusters" to "cluster get"
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed May 22, 2023
1 parent acdc8c9 commit cf5964b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
46 changes: 22 additions & 24 deletions bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ pub enum SubCmd {
},
#[clap(name = "cluster", about = "cluster management")]
Cluster {
#[clap(
short = 'j',
long = "json",
help = "Print the command result in JSON format",
global = true
)]
json: bool,
#[clap(subcommand)]
cmd: ClusterCmd,
},
Expand Down Expand Up @@ -192,18 +199,6 @@ pub enum SubCmd {
#[clap(subcommand)]
cmd: CertificateCmd,
},
#[clap(name = "query", about = "configuration state verification")]
Query {
#[clap(
short = 'j',
long = "json",
help = "Print the command result in JSON format",
global = true
)]
json: bool,
#[clap(subcommand)]
cmd: QueryCmd,
},
#[clap(name = "config", about = "configuration file management")]
Config {
#[clap(subcommand)]
Expand Down Expand Up @@ -290,6 +285,16 @@ pub enum StateCmd {

#[derive(Subcommand, PartialEq, Eq, Clone, Debug)]
pub enum ClusterCmd {
#[clap(
name = "get",
about = "Query clusters, all of them, or filtered by id or domain"
)]
Get {
#[clap(short = 'i', long = "id", help = "cluster identifier")]
id: Option<String>,
#[clap(short = 'd', long = "domain", help = "cluster domain name")]
domain: Option<String>,
},
#[clap(name = "remove", about = "Remove a cluster")]
Remove {
#[clap(short = 'i', long = "id", help = "cluster id")]
Expand Down Expand Up @@ -757,7 +762,11 @@ pub enum CertificateCmd {
Get {
#[clap(short = 'f', long = "fingerprint", help = "certificate fingerprint")]
fingerprint: Option<String>,
#[clap(short = 'd', long = "domain", help = "domain name of the queried certificates")]
#[clap(
short = 'd',
long = "domain",
help = "domain name of the queried certificates"
)]
domain: Option<String>,
},
#[clap(name = "add", about = "Add a certificate")]
Expand Down Expand Up @@ -826,17 +835,6 @@ pub enum CertificateCmd {
},
}

#[derive(Subcommand, PartialEq, Eq, Clone, Debug)]
pub enum QueryCmd {
#[clap(name = "clusters", about = "Query clusters matching a specific filter")]
Clusters {
#[clap(short = 'i', long = "id", help = "cluster identifier")]
id: Option<String>,
#[clap(short = 'd', long = "domain", help = "cluster domain name")]
domain: Option<String>,
},
}

#[derive(Subcommand, PartialEq, Eq, Clone, Debug)]
pub enum ConfigCmd {
#[clap(name = "check", about = "check configuration file syntax and exit")]
Expand Down
5 changes: 1 addition & 4 deletions bin/src/ctl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl CommandManager {
StateCmd::Load { file } => self.load_state(file),
},
SubCmd::Reload { file, json } => self.reload_configuration(file, json),
SubCmd::Cluster { cmd } => self.cluster_command(cmd),
SubCmd::Cluster { cmd, json } => self.cluster_command(cmd, json),
SubCmd::Backend { cmd } => self.backend_command(cmd),
SubCmd::Frontend { cmd } => match cmd {
FrontendCmd::Http { cmd } => self.http_frontend_command(cmd),
Expand Down Expand Up @@ -148,9 +148,6 @@ impl CommandManager {
tls_versions,
),
},
SubCmd::Query { cmd, json } => match cmd {
QueryCmd::Clusters { id, domain } => self.query_cluster(json, id, domain),
},
SubCmd::Config { cmd: _ } => Ok(()), // noop, handled at the beginning of the method
SubCmd::Events => self.events(),
rest => {
Expand Down
3 changes: 2 additions & 1 deletion bin/src/ctl/request_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl CommandManager {
}
}

pub fn cluster_command(&mut self, cmd: ClusterCmd) -> anyhow::Result<()> {
pub fn cluster_command(&mut self, cmd: ClusterCmd, json: bool) -> anyhow::Result<()> {
match cmd {
ClusterCmd::Add {
id,
Expand Down Expand Up @@ -199,6 +199,7 @@ impl CommandManager {
ClusterCmd::Remove { id } => self.order_request(Request {
request_type: Some(RequestType::RemoveCluster(id)),
}),
ClusterCmd::Get { id, domain } => self.query_cluster(json, id, domain),
}
}

Expand Down

0 comments on commit cf5964b

Please sign in to comment.