Skip to content

Commit

Permalink
display no other lines than JSON
Browse files Browse the repository at this point in the history
so that the output of --json commands is pipeable
  • Loading branch information
Keksoj committed Dec 6, 2023
1 parent 0e62ff3 commit 95de156
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
21 changes: 17 additions & 4 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ impl CommandManager {

match response.status() {
ResponseStatus::Processing => {
debug!("Proxy is processing: {}", response.message);
if !self.json {
debug!("Proxy is processing: {}", response.message);
}
}
ResponseStatus::Failure => bail!("Request failed: {}", response.message),
ResponseStatus::Ok => {
if !self.json {
info!("{}", response.message);
}
response.display(self.json)?;
break;
}
Expand All @@ -55,7 +60,9 @@ impl CommandManager {

match response.status() {
ResponseStatus::Processing => {
debug!("Processing: {}", response.message);
if !self.json {
debug!("Processing: {}", response.message);
}
}
ResponseStatus::Failure => {
bail!(
Expand Down Expand Up @@ -143,7 +150,11 @@ impl CommandManager {
let response = self.read_channel_message_with_timeout()?;

match response.status() {
ResponseStatus::Processing => info!("Proxy is processing: {}", response.message),
ResponseStatus::Processing => {
if !self.json {
info!("Proxy is processing: {}", response.message);
}
}
ResponseStatus::Failure => bail!(
"could not stop the worker {}: {}",
worker_id,
Expand Down Expand Up @@ -186,7 +197,9 @@ impl CommandManager {

match response.status() {
ResponseStatus::Processing => {
debug!("Proxy is processing: {}", response.message);
if !self.json {
debug!("Proxy is processing: {}", response.message);
}
}
ResponseStatus::Failure | ResponseStatus::Ok => {
response.display(self.json)?;
Expand Down
7 changes: 6 additions & 1 deletion command/src/proto/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ pub fn print_json_response<T: ::serde::Serialize>(input: &T) -> Result<(), Displ
impl Response {
pub fn display(&self, json: bool) -> Result<(), DisplayError> {
match self.status() {
ResponseStatus::Ok => println!("Success: {}", self.message),
ResponseStatus::Ok => {
// avoid displaying anything else than JSON
if !json {
println!("Success: {}", self.message)
}
}
ResponseStatus::Failure => println!("Failure: {}", self.message),
ResponseStatus::Processing => {
return Err(DisplayError::WrongResponseType(
Expand Down

0 comments on commit 95de156

Please sign in to comment.