@theholocron/cli 5.0.0-alpha.233 → 5.0.0-alpha.234

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.
package/dist/cli.mjs CHANGED
@@ -770,6 +770,53 @@ async function withSpinner(label, fn) {
770
770
  throw err;
771
771
  }
772
772
  }
773
+ let allowed = true;
774
+ /** Turn progress off for the run (`--quiet`, `--log`), so nothing extra shares the terminal with what those print. */
775
+ function allowProgress(on) {
776
+ allowed = on;
777
+ }
778
+ /**
779
+ * Whether to draw a progress line: only when a person is watching a terminal (stdout and stderr both), not in CI, and not
780
+ * switched off. Everywhere else the output stays the plain line-per-step text that scripts and the docs rely on.
781
+ */
782
+ function progressEnabled() {
783
+ return allowed && Boolean(process.stdout.isTTY) && Boolean(process.stderr.isTTY) && !process.env["CI"];
784
+ }
785
+ /**
786
+ * A spinner for one step at a time that a step can print through. Steps that only return a result use {@link
787
+ * withProgress}; a step that prints its own result line while it runs (`notifications setup`) prints through `print`.
788
+ */
789
+ function createProgress(print, enabled = progressEnabled) {
790
+ let active;
791
+ return {
792
+ async run(label, fn) {
793
+ if (!enabled()) return fn();
794
+ const spinner = ora({
795
+ text: label,
796
+ stream: process.stderr,
797
+ discardStdin: false
798
+ }).start();
799
+ active = spinner;
800
+ try {
801
+ return await fn();
802
+ } finally {
803
+ spinner.stop();
804
+ active = void 0;
805
+ }
806
+ },
807
+ print(line) {
808
+ const spinner = active;
809
+ if (!spinner) return print(line);
810
+ spinner.stop();
811
+ print(line);
812
+ spinner.start();
813
+ }
814
+ };
815
+ }
816
+ /** `fn` under a cleared-when-done spinner named `label`, on a terminal only. */
817
+ function withProgress(label, fn) {
818
+ return createProgress(() => {}).run(label, fn);
819
+ }
773
820
  //#endregion
774
821
  //#region src/ui/prompt-options/prompt-options.ts
775
822
  /**
@@ -1124,6 +1171,7 @@ function resolveCliAxiom(opts) {
1124
1171
  */
1125
1172
  function buildCliLogger(argv, opts = {}) {
1126
1173
  const { command, configLevel } = opts;
1174
+ allowProgress(!argv.quiet && !argv.log);
1127
1175
  if (command) rootCommand = command;
1128
1176
  const level = resolveLogLevel(argv, configLevel);
1129
1177
  const consoleOutput = resolveConsoleOutput(argv);
@@ -2508,11 +2556,12 @@ async function runDoctor(input) {
2508
2556
  const impls = loader.get(key);
2509
2557
  for (const [idx, impl] of impls.entries()) {
2510
2558
  const name = impl.providerName ?? providers[idx];
2511
- rows.push(await smokeCheck(key, name, impl));
2559
+ rows.push(await withProgress(`Checking ${key} (${name})…`, () => smokeCheck(key, name, impl)));
2512
2560
  }
2513
2561
  } else {
2514
2562
  const impl = loader.get(key);
2515
- const row = await smokeCheck(key, providers[0] ?? "?", impl);
2563
+ const provider = providers[0] ?? "?";
2564
+ const row = await withProgress(`Checking ${key} (${provider})…`, () => smokeCheck(key, provider, impl));
2516
2565
  rows.push(row);
2517
2566
  }
2518
2567
  }
@@ -5192,7 +5241,8 @@ function serverLayoutProblem(layout) {
5192
5241
  }
5193
5242
  }
5194
5243
  async function runNotificationsSetup(input$1) {
5195
- const print = input$1.print ?? ((line) => console.log(line));
5244
+ const progress = createProgress(input$1.print ?? ((line) => console.log(line)));
5245
+ const print = progress.print;
5196
5246
  const logger = input$1.logger ?? getLogger();
5197
5247
  /* v8 ignore next -- the real loader is only built outside tests, which always inject one */
5198
5248
  const loader = input$1.loader ?? new PluginLoader(input$1.loaded.resolved, input$1.context);
@@ -5315,7 +5365,7 @@ async function runNotificationsSetup(input$1) {
5315
5365
  const made = (created) => void (created ? tally.ok++ : tally.skip++);
5316
5366
  const attempt = async (step, fn) => {
5317
5367
  try {
5318
- await fn();
5368
+ await progress.run(`${step}…`, fn);
5319
5369
  return true;
5320
5370
  } catch (err) {
5321
5371
  const message = describeProviderError(err);
@@ -7077,20 +7127,27 @@ function coreProbes(loader, builtIn = /* @__PURE__ */ new Map()) {
7077
7127
  for (const one of Array.isArray(impl) ? impl : [impl]) if (one.providerName) names.add(one.providerName);
7078
7128
  }
7079
7129
  for (const name of offered.keys()) names.add(name);
7130
+ const failedOnly = /* @__PURE__ */ new Map();
7131
+ for (const f of loader.loadFailures()) if (!names.has(f.provider) && !failedOnly.has(f.provider)) failedOnly.set(f.provider, f.error);
7080
7132
  ctx.say({
7081
7133
  status: "heading",
7082
7134
  label: "Providers"
7083
7135
  });
7136
+ for (const [name, error] of [...failedOnly].sort(([a], [b]) => a.localeCompare(b))) ctx.say({
7137
+ status: "fail",
7138
+ label: name,
7139
+ detail: `did not load: ${describeProviderError(error)}`
7140
+ });
7084
7141
  for (const name of [...names].sort()) {
7085
7142
  const own = offered.get(name);
7086
7143
  ctx.say({
7087
- status: "info",
7144
+ status: own ? "ok" : "info",
7088
7145
  label: name,
7089
7146
  detail: own ? Object.keys(own).sort().join(", ") : "no probes yet"
7090
7147
  });
7091
7148
  }
7092
- for (const [name, own] of [...builtIn].sort(([a], [b]) => a.localeCompare(b))) ctx.say({
7093
- status: "info",
7149
+ for (const [name, own] of builtIn) ctx.say({
7150
+ status: "ok",
7094
7151
  label: `${name} (built in)`,
7095
7152
  detail: Object.keys(own).sort().join(", ")
7096
7153
  });
@@ -7169,7 +7226,8 @@ const defaultInterrupt = (handler) => {
7169
7226
  * failed or was interrupted.
7170
7227
  */
7171
7228
  async function runProbe(input) {
7172
- const print = input.print ?? ((line) => console.log(line));
7229
+ const progress = createProgress(input.print ?? ((line) => console.log(line)));
7230
+ const print = progress.print;
7173
7231
  const secrets = new Set(input.secrets ?? []);
7174
7232
  const scrub = createScrubber(secrets);
7175
7233
  const rows = [];
@@ -7245,7 +7303,7 @@ async function runProbe(input) {
7245
7303
  };
7246
7304
  const stopListening = (input.onInterrupt ?? defaultInterrupt)(runCleanups);
7247
7305
  try {
7248
- await input.probe.run(ctx);
7306
+ await progress.run(`${input.name}…`, () => input.probe.run(ctx));
7249
7307
  } catch (err) {
7250
7308
  emit({
7251
7309
  status: "fail",
@@ -9314,7 +9372,7 @@ async function execStep(capability, step, dryRun, body, opts = {}) {
9314
9372
  status: "dry-run"
9315
9373
  };
9316
9374
  try {
9317
- const note = await body();
9375
+ const note = await withProgress(`${capability}: ${step}…`, body);
9318
9376
  const result = {
9319
9377
  capability,
9320
9378
  step,