Skip to content

Commit

Permalink
Merge pull request #1004 from sozu-proxy/fix-display-in-json-form
Browse files Browse the repository at this point in the history
CLI: all responses are displayable in JSON
  • Loading branch information
Keksoj authored Dec 6, 2023
2 parents e58e388 + 86303a2 commit 0b744b4
Show file tree
Hide file tree
Showing 16 changed files with 1,084 additions and 1,174 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ mio = { version = "^0.8.8", features = ["os-poll", "net"] }
nix = { version = "^0.27.1", features = ["signal", "fs"] }
nom = "^7.1.3"
paw = "^1.0.0"
prettytable-rs = { version = "^0.10.0", default-features = false }
serde = { version = "^1.0.188", features = ["derive"] }
serde_json = "^1.0.107"
time = "^0.3.29"
regex = "^1.10.0"
smol = "^1.3.0"
tempfile = "^3.8.0"
termion = "^2.0.1"
x509-parser = "^0.15.1"

sozu-command-lib = { path = "../command", version = "^0.15.17" }
sozu-lib = { path = "../lib", version = "^0.15.17" }
Expand Down
48 changes: 12 additions & 36 deletions bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ pub struct Args {
help = "Sets a custom timeout for commands (in milliseconds). 0 disables the timeout"
)]
pub timeout: Option<u64>,
#[clap(
short = 'j',
long = "json",
global = true,
help = "display responses to queries in a JSON format"
)]
pub json: bool,
#[clap(subcommand)]
pub cmd: SubCmd,
}
Expand Down Expand Up @@ -109,26 +116,12 @@ pub enum SubCmd {
},

#[clap(name = "status", about = "gets information on the running workers")]
Status {
#[clap(
short = 'j',
long = "json",
help = "Print the command result in JSON format"
)]
json: bool,
},
Status,
#[clap(
name = "metrics",
about = "gets statistics on the main process and its workers"
)]
Metrics {
#[clap(
short = 'j',
long = "json",
help = "Print the command result in JSON format",
global = true
)]
json: bool,
#[clap(subcommand)]
cmd: MetricsCmd,
},
Expand All @@ -153,22 +146,9 @@ pub enum SubCmd {
help = "use a different configuration file from the current one"
)]
file: Option<String>,
#[clap(
short = 'j',
long = "json",
help = "Print the command result in JSON format"
)]
json: bool,
},
#[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 All @@ -189,13 +169,6 @@ pub enum SubCmd {
},
#[clap(name = "certificate", about = "list, add and remove certificates")]
Certificate {
#[clap(
short = 'j',
long = "json",
help = "Print the command result in JSON format",
global = true
)]
json: bool,
#[clap(subcommand)]
cmd: CertificateCmd,
},
Expand All @@ -216,7 +189,10 @@ pub enum MetricsCmd {
Disable,
#[clap(name = "clear", about = "Deletes local metrics data")]
Clear,
#[clap(name = "get", about = "get all or filtered metrics")]
#[clap(
name = "get",
about = "get all metrics, filtered, or a list of available metrics"
)]
Get {
#[clap(short, long, help = "list the available metrics on the proxy level")]
list: bool,
Expand Down
4 changes: 2 additions & 2 deletions bin/src/command/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ impl CommandServer {
),
Some(RequestType::QueryClusterById(cluster_id)) => Some(
ContentType::Clusters(ClusterInformations {
vec: vec![self.state.cluster_state(cluster_id)],
vec: self.state.cluster_state(cluster_id).into_iter().collect(),
})
.into(),
),
Expand All @@ -1030,7 +1030,7 @@ impl CommandServer {
.get_cluster_ids_by_domain(domain.hostname.clone(), domain.path.clone());
let vec = cluster_ids
.iter()
.map(|cluster_id| self.state.cluster_state(cluster_id))
.filter_map(|cluster_id| self.state.cluster_state(cluster_id))
.collect();
Some(ContentType::Clusters(ClusterInformations { vec }).into())
}
Expand Down
Loading

0 comments on commit 0b744b4

Please sign in to comment.