1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! Reading a bulk change back.
//!
//! A group of its own, holding one read and nothing else. The write that starts
//! a bulk change is `issue update`, which is where a caller already looks to
//! change issues; this is the handle on work Tracker is still doing, and it has
//! to be allowlistable without allowing anything to be written.
use clap::Subcommand;
use crate::cli::{Session, emit, report};
use crate::exit::ExitCode;
use crate::render::{Format, bulk, machine};
#[derive(Debug, Subcommand)]
pub enum BulkCommand {
/// Show how far a bulk change got.
#[command(long_about = crate::cli::help::md(crate::cli::help::BULK_STATUS))]
Status {
/// The id `issue update` printed.
id: String,
},
}
pub async fn run(command: &BulkCommand, session: &Session) -> ExitCode {
let client = match session.client() {
Ok(client) => client,
Err(code) => return code,
};
let BulkCommand::Status { id } = command;
let change = match client.bulk_change(id).await {
Ok(change) => change,
Err(error) => {
let code = error.exit_code();
return report(&error, code);
}
};
if session.render.format != Format::Text {
let format = match session.render.format {
Format::JsonRaw => Format::Json,
other => other,
};
return match machine(&change, format) {
Ok(text) => {
emit(&text);
ExitCode::Success
}
Err(error) => report(&error, ExitCode::Failure),
};
}
emit(&bulk::change(&change, &session.render));
// A change still running has nothing per issue to say yet, and one that
// worked has said it in the tally. Only a finished change that did not do
// everything is worth the second request.
if change.finished() && !change.succeeded() {
match client.bulk_change_issues(id).await {
Ok(outcomes) => emit(&bulk::failures(&outcomes, &session.render)),
Err(error) => {
let code = error.exit_code();
return report(&error, code);
}
}
}
// Reading is not judging: this says what happened, and exits zero for having
// answered. `issue update` is where a failed change decides an exit code.
ExitCode::Success
}