Skip to main content

smbcloud_deploy/
report.rs

1//! Progress reporting, inverted.
2//!
3//! The engine calls a [`Reporter`] instead of touching the terminal. Each
4//! front-end supplies its own implementation:
5//! - the CLI renders steps as `spinners` lines with themed symbols,
6//! - CI prints plain, timestamped lines,
7//! - the server-side git receiver streams lines over the push sideband.
8
9/// How the engine tells the outside world what it is doing.
10///
11/// A "step" is one unit of work (detect runner, build, upload, restart). The
12/// engine brackets each with [`step_start`](Reporter::step_start) and one of
13/// [`step_done`](Reporter::step_done) / [`step_fail`](Reporter::step_fail).
14pub trait Reporter: Send + Sync {
15    /// A unit of work has started.
16    fn step_start(&self, msg: &str);
17
18    /// The current step finished successfully.
19    fn step_done(&self, msg: &str);
20
21    /// The current step failed.
22    fn step_fail(&self, msg: &str);
23
24    /// An informational note not tied to a step. Defaults to no-op.
25    fn info(&self, msg: &str) {
26        let _ = msg;
27    }
28
29    /// A single line of streamed output from a build or the remote (e.g. a line
30    /// of `next build` output, or a git receive-pack message). Defaults to no-op.
31    fn remote_line(&self, line: &str) {
32        let _ = line;
33    }
34}
35
36/// A [`Reporter`] that discards everything.
37///
38/// Useful for tests and for non-interactive callers that only care about the
39/// final `Result`.
40pub struct NoopReporter;
41
42impl Reporter for NoopReporter {
43    fn step_start(&self, _msg: &str) {}
44    fn step_done(&self, _msg: &str) {}
45    fn step_fail(&self, _msg: &str) {}
46}