1use clap::Subcommand;
9
10use crate::cli::{Session, emit, report};
11use crate::exit::ExitCode;
12use crate::render::{Format, bulk, machine};
13
14#[derive(Debug, Subcommand)]
15pub enum BulkCommand {
16 #[command(long_about = crate::cli::help::md(crate::cli::help::BULK_STATUS))]
18 Status {
19 id: String,
21 },
22}
23
24pub async fn run(command: &BulkCommand, session: &Session) -> ExitCode {
25 let client = match session.client() {
26 Ok(client) => client,
27 Err(code) => return code,
28 };
29
30 let BulkCommand::Status { id } = command;
31 let change = match client.bulk_change(id).await {
32 Ok(change) => change,
33 Err(error) => {
34 let code = error.exit_code();
35 return report(&error, code);
36 }
37 };
38
39 if session.render.format != Format::Text {
40 let format = match session.render.format {
41 Format::JsonRaw => Format::Json,
42 other => other,
43 };
44 return match machine(&change, format) {
45 Ok(text) => {
46 emit(&text);
47 ExitCode::Success
48 }
49 Err(error) => report(&error, ExitCode::Failure),
50 };
51 }
52
53 emit(&bulk::change(&change, &session.render));
54
55 if change.finished() && !change.succeeded() {
59 match client.bulk_change_issues(id).await {
60 Ok(outcomes) => emit(&bulk::failures(&outcomes, &session.render)),
61 Err(error) => {
62 let code = error.exit_code();
63 return report(&error, code);
64 }
65 }
66 }
67
68 ExitCode::Success
71}