@hardfin/cli 0.1.1-dev.76 → 0.1.1-dev.77

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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d62922d3-3556-5760-b61b-d76b2266166b")}catch(e){}}();
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b343e726-5fb7-5910-a08a-b9c77c5a7691")}catch(e){}}();
4
4
  import module from "node:module";
5
5
  //#region src/cli.ts
6
6
  module.enableCompileCache?.();
@@ -14,7 +14,7 @@ process.on("unhandledRejection", (error) => void toCrash(error));
14
14
  try {
15
15
  const answer = await toQuickAnswer(process.argv.slice(2));
16
16
  if (answer === void 0) {
17
- const { toCli, toParseExitCode, wasReportAttempted } = await import("./program-CqSt-pBK.js");
17
+ const { toCli, toParseExitCode, wasReportAttempted } = await import("./program-CTAOEcIl.js");
18
18
  const { startUpdateCheck, writeUpdateNotice } = await import("./notice-DWvcEHhw.js");
19
19
  const pending = startUpdateCheck(process.argv.slice(2));
20
20
  try {
@@ -36,7 +36,7 @@ async function toCrash(error) {
36
36
  isCrashing = true;
37
37
  const isJSON = process.argv.includes("--json") || !process.stdout.isTTY;
38
38
  try {
39
- const { toReported, writeCrash } = await import("./program-CqSt-pBK.js");
39
+ const { toReported, writeCrash } = await import("./program-CTAOEcIl.js");
40
40
  writeCrash(error, isJSON);
41
41
  await toReported(error, isJSON, void 0, "fatal");
42
42
  } catch {
@@ -57,4 +57,4 @@ async function toQuickAnswer(args) {
57
57
  export {};
58
58
 
59
59
  //# sourceMappingURL=cli.js.map
60
- //# debugId=d62922d3-3556-5760-b61b-d76b2266166b
60
+ //# debugId=b343e726-5fb7-5910-a08a-b9c77c5a7691
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="2c148a55-44de-51fb-ad05-0794aa41fd77")}catch(e){}}();
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0e61ba79-b67a-56d5-a2fd-a7a450bc463c")}catch(e){}}();
4
4
  import { a as defineCommand, i as GLOBAL_FLAGS, r as ExitCode, t as toInvocation } from "./scrub-BZ0egWxC.js";
5
5
  import { C as Interrupted, S as ExpectedFailure, T as TimedOut, _ as ConfigFailure, a as isShipped, b as toTelemetry, g as CONFIG_FILE, h as writeFailure, i as toUpdateCheckRefusal, l as toStateDirectory, m as writeData, o as toPackageDirectory, p as toText, r as toCheck, s as noteNotices, t as PACKAGE, u as isJSONOutput, v as toSettings, w as LockHeld, x as version$1, y as API_VERSION } from "./check-8Ta7vSnU.js";
6
6
  import { n as toAnswer$1, r as toCompletion, t as PATH_VALUES } from "./completion-tree-DLC6ARLR.js";
@@ -1125,7 +1125,8 @@ function toTaken(flag) {
1125
1125
  return flag.valueName ?? "nothing";
1126
1126
  }
1127
1127
  async function runAgentGuide(input) {
1128
- const found = toNamed(input.commands, input.args);
1128
+ const words = input.args.flatMap((arg) => arg.split(/\s+/)).filter((word) => word.length > 0);
1129
+ const found = toNamed(input.commands, words);
1129
1130
  if (found === void 0) {
1130
1131
  writeFailure("invalid_arguments", `no command is called ${input.args.join(" ")}. Run hardfin --help for the list`, input.isJSON);
1131
1132
  return ExitCode.USAGE;
@@ -1254,6 +1255,9 @@ function toHelpDescription(flag) {
1254
1255
  function toProgram(root, command, onRun, isSilent) {
1255
1256
  const program = new Command(command.name).summary(command.summary).description(command.description ?? command.summary);
1256
1257
  toQuietParser(program, isSilent);
1258
+ program.exitOverride((error) => {
1259
+ throw toSuggested(error, command);
1260
+ });
1257
1261
  for (const argument of command.arguments) {
1258
1262
  const name = argument.variadic ? `${argument.name}...` : argument.name;
1259
1263
  program.argument(argument.required ? `<${name}>` : `[${name}]`, argument.description);
@@ -1299,6 +1303,32 @@ function toQuietParser(program, isSilent) {
1299
1303
  writeErr: () => void 0
1300
1304
  });
1301
1305
  }
1306
+ /** The most flags an unknown flag's error suggests. */
1307
+ const MAX_SUGGESTIONS = 3;
1308
+ /**
1309
+ * toSuggested names the flags an unknown flag may have meant, when the parser's own spelling
1310
+ * check found none, by matching the words of its name.
1311
+ */
1312
+ function toSuggested(error, command) {
1313
+ const unknown = /unknown option '--([^']+)'/.exec(error.message)?.[1];
1314
+ if (error.code !== "commander.unknownOption" || unknown === void 0 || error.message.includes("Did you mean")) return error;
1315
+ const words = toWords(unknown);
1316
+ const matches = command.flags.map((flag) => ({
1317
+ name: flag.name,
1318
+ words: toWords(flag.name)
1319
+ })).filter((flag) => words.every((word) => flag.words.some((other) => isSameWord(word, other)))).sort((a, b) => a.words.length - b.words.length || a.name.localeCompare(b.name)).slice(0, MAX_SUGGESTIONS).map((flag) => `--${flag.name}`);
1320
+ if (matches.length === 0) return error;
1321
+ const suggestion = matches.length === 1 ? matches[0] : `one of ${matches.join(", ")}`;
1322
+ return new CommanderError(error.exitCode, error.code, `${error.message}\n(Did you mean ${suggestion}?)`);
1323
+ }
1324
+ function toWords(name) {
1325
+ return name.split("-").filter((word) => word.length > 0);
1326
+ }
1327
+ /** isSameWord treats a word and its plural, such as status and statuses, as one. */
1328
+ function isSameWord(given, other) {
1329
+ const [shorter, longer] = given.length <= other.length ? [given, other] : [other, given];
1330
+ return longer.startsWith(shorter) && longer.length - shorter.length <= 2;
1331
+ }
1302
1332
  function toArgumentList(value) {
1303
1333
  if (Array.isArray(value)) return value.map(String);
1304
1334
  return value === void 0 ? [] : [toText(value)];
@@ -14483,5 +14513,5 @@ async function toReported(error, isJSON, resolved, level = "error") {
14483
14513
  //#endregion
14484
14514
  export { toCli, toParseExitCode, toReported, wasReportAttempted, writeCrash };
14485
14515
 
14486
- //# sourceMappingURL=program-CqSt-pBK.js.map
14487
- //# debugId=2c148a55-44de-51fb-ad05-0794aa41fd77
14516
+ //# sourceMappingURL=program-CTAOEcIl.js.map
14517
+ //# debugId=0e61ba79-b67a-56d5-a2fd-a7a450bc463c
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardfin/cli",
3
- "version": "0.1.1-dev.76",
3
+ "version": "0.1.1-dev.77",
4
4
  "description": "Command line interface for the Hardfin API",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Hardfin, Inc.",