Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: all responses are displayable in JSON #1004

Merged
merged 4 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading