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 3 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
11 changes: 9 additions & 2 deletions crates/hyperqueue/src/client/commands/autoalloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub async fn command_autoalloc(
print_allocation_queues(gsettings, session).await?;
}
AutoAllocCommand::Add(opts) => {
add_queue(session, opts).await?;
add_queue(gsettings, session, opts).await?;
}
AutoAllocCommand::Info(opts) => {
print_allocations(gsettings, session, opts).await?;
Expand Down Expand Up @@ -348,7 +348,11 @@ wasting resources."
Ok(())
}

async fn add_queue(mut session: ClientSession, opts: AddQueueOpts) -> anyhow::Result<()> {
async fn add_queue(
gsettings: &GlobalSettings,
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 All @@ -370,6 +374,9 @@ async fn add_queue(mut session: ClientSession, opts: AddQueueOpts) -> anyhow::Re
)
.await?;

// print empty response
gsettings.printer().print_empty();

if dry_run {
log::info!(
"A trial allocation was submitted successfully. It was immediately canceled to avoid \
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 @@ -983,6 +983,10 @@ impl Output for CliOutput {
job_id.to_string().color(colored::Color::Green),
);
}

fn print_empty(&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 @@ -238,6 +238,10 @@ impl Output for JsonOutput {
fn print_error(&self, error: Error) {
self.print(json!({ "error": format!("{error:?}") }))
}

fn print_empty(&self) {
self.print(json!("{}"));
}
}

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);

// empty response
fn print_empty(&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 print_empty(&self) {}
}

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