Skip to content

Feat: Add empty json output mode #844

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions crates/hyperqueue/src/bin/hq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,10 @@ async fn main() -> hyperqueue::Result<()> {

if let Err(e) = result {
gsettings.printer().print_error(e);
gsettings.printer().finalize_output();
std::process::exit(1);
}

gsettings.printer().finalize_output();
Ok(())
}
5 changes: 4 additions & 1 deletion crates/hyperqueue/src/client/commands/autoalloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,10 @@ wasting resources."
Ok(())
}

async fn add_queue(mut session: ClientSession, opts: AddQueueOpts) -> anyhow::Result<()> {
async fn add_queue(
mut session: ClientSession,
opts: AddQueueOpts,
) -> anyhow::Result<()> {
let (parameters, dry_run) = match opts.subcmd {
AddQueueCommand::Pbs(params) => {
let no_dry_run = params.no_dry_run;
Expand Down
4 changes: 4 additions & 0 deletions crates/hyperqueue/src/client/output/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,10 @@ impl Output for CliOutput {
job_id.to_string().color(colored::Color::Green),
);
}

fn finalize_output(&self) {
println!()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to print anything here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks will fix this.

}
}

struct AllocationTimes {
Expand Down
4 changes: 4 additions & 0 deletions crates/hyperqueue/src/client/output/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ impl Output for JsonOutput {
fn print_error(&self, error: Error) {
self.print(json!({ "error": format!("{error:?}") }))
}

fn finalize_output(&self) {
self.print(json!({}));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only be printed if we did not print anything in the JSON printer. Otherwise we will print multiple JSON objects, which is invalid JSON.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh thanks I will work on this now.

}
}

fn format_task_description(task_desc: &TaskDescription) -> Value {
Expand Down
3 changes: 3 additions & 0 deletions crates/hyperqueue/src/client/output/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,7 @@ pub trait Output {
fn print_hw(&self, descriptor: &ResourceDescriptor);

fn print_error(&self, error: anyhow::Error);

// this will be called before hq quits
fn finalize_output(&self);
}
2 changes: 2 additions & 0 deletions crates/hyperqueue/src/client/output/quiet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ impl Output for Quiet {
fn print_error(&self, error: Error) {
eprintln!("{error:?}");
}

fn finalize_output(&self) {}
}

fn format_status(status: &Status) -> &str {
Expand Down