@yadurajfleetos/cli 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/progress.js +54 -2
  2. package/package.json +1 -1
package/dist/progress.js CHANGED
@@ -14,6 +14,7 @@
14
14
  * a persistently unreachable control plane as an error.
15
15
  */
16
16
  import { request, CliError, EXIT } from './api.js';
17
+ import { bar } from './ui.js';
17
18
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
18
19
  /** A failure reason can be a build log tail; a one-line error gets one line of it. */
19
20
  export const firstLine = (text) => text.split('\n')[0].trim().slice(0, 200);
@@ -30,7 +31,51 @@ export function progressLine(p) {
30
31
  return undefined;
31
32
  const counter = p.step && p.ofSteps ? `${p.step}/${p.ofSteps} ` : '';
32
33
  const platform = p.platform ? `${p.platform.replace(/^linux\//, '')} ` : '';
33
- return `${counter}${platform}${p.detail}`;
34
+ // Emulation is the answer to "why is this taking so long", and a build that
35
+ // takes three minutes instead of twenty seconds is almost always this. Said
36
+ // once, on the line already being drawn, rather than as a separate warning.
37
+ const how = p.emulated ? ' (emulated — slow)' : '';
38
+ return `${counter}${platform}${p.detail}${how}`;
39
+ }
40
+ /**
41
+ * A duration a person reads, not a step suffix.
42
+ *
43
+ * ui.ts has `duration`, which is dim, colour-wrapped, prefixed with a space
44
+ * and renders three minutes as "180s" — right for the end of a finished step,
45
+ * wrong for a sentence about how long is left.
46
+ */
47
+ function human(ms) {
48
+ const total = Math.max(0, Math.round(ms / 1000));
49
+ if (total < 60)
50
+ return `${total}s`;
51
+ const minutes = Math.floor(total / 60);
52
+ const seconds = total % 60;
53
+ if (minutes < 60)
54
+ return seconds ? `${minutes}m ${seconds}s` : `${minutes}m`;
55
+ const hours = Math.floor(minutes / 60);
56
+ return `${hours}h ${minutes % 60}m`;
57
+ }
58
+ /**
59
+ * Elapsed against what this service usually takes.
60
+ *
61
+ * Only from real history: on a first deploy there is nothing honest to say,
62
+ * and a bar filled from a number nobody measured is the same lie as the "not
63
+ * needed" it replaces. Overrunning is shown as overrunning rather than parked
64
+ * at the end of the bar — a deploy that is genuinely slow today is exactly
65
+ * when somebody needs to know.
66
+ */
67
+ export function etaLine(p, now = Date.now()) {
68
+ if (!p.typicalMs || !p.since)
69
+ return undefined;
70
+ const elapsed = now - new Date(p.since).getTime();
71
+ if (elapsed < 0)
72
+ return undefined;
73
+ const fraction = Math.min(1, elapsed / p.typicalMs);
74
+ const left = p.typicalMs - elapsed;
75
+ const tail = left > 0
76
+ ? `~${human(left)} left`
77
+ : `${human(-left)} over the usual ${human(p.typicalMs)}`;
78
+ return `${bar(fraction)} ${human(elapsed)} · ${tail}`;
34
79
  }
35
80
  /**
36
81
  * Poll `/progress` in the background while something else is being awaited.
@@ -184,7 +229,14 @@ export function phaseWalker(l, steps = DEPLOY_STEPS) {
184
229
  // poll, and it belongs on the step that decided it.
185
230
  advance(target, at === 0 ? (p.nodeName ?? undefined) : undefined);
186
231
  }
187
- const line = progressLine(p);
232
+ // The build line, or the estimate when there is no build line to show.
233
+ //
234
+ // Both on one row rather than two: the ladder redraws a fixed region and
235
+ // a row that appears and disappears makes the whole block jump. During a
236
+ // build the sub-step is the more useful of the two — it is proof of
237
+ // movement — and the estimate carries the rest of the wait, when the
238
+ // node is pulling an image and nothing is being logged at all.
239
+ const line = progressLine(p) ?? etaLine(p);
188
240
  if (line && at < steps.length)
189
241
  l.detail(steps[at].key, line);
190
242
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yadurajfleetos/cli",
3
- "version": "0.9.2",
3
+ "version": "0.10.0",
4
4
  "description": "Fleet OS command-line interface for deploying and orchestrating services on user-owned hardware",
5
5
  "type": "module",
6
6
  "license": "MIT",