@contember/cli-common 2.2.0-alpha.18 → 2.2.0-alpha.19

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 (73) hide show
  1. package/dist/development/index.cjs +7 -0
  2. package/dist/development/index.cjs.map +1 -1
  3. package/dist/development/index.js +7 -0
  4. package/dist/development/index.js.map +1 -1
  5. package/dist/development/src/application/Application.cjs +7 -7
  6. package/dist/development/src/application/Application.cjs.map +1 -1
  7. package/dist/development/src/application/Application.js +7 -7
  8. package/dist/development/src/application/Application.js.map +1 -1
  9. package/dist/development/src/application/ErrorRenderer.cjs +3 -3
  10. package/dist/development/src/application/ErrorRenderer.cjs.map +1 -1
  11. package/dist/development/src/application/ErrorRenderer.js +3 -3
  12. package/dist/development/src/application/ErrorRenderer.js.map +1 -1
  13. package/dist/development/src/application/Output.cjs +72 -39
  14. package/dist/development/src/application/Output.cjs.map +1 -1
  15. package/dist/development/src/application/Output.js +72 -39
  16. package/dist/development/src/application/Output.js.map +1 -1
  17. package/dist/development/src/application/colors.cjs +29 -0
  18. package/dist/development/src/application/colors.cjs.map +1 -0
  19. package/dist/development/src/application/colors.js +29 -0
  20. package/dist/development/src/application/colors.js.map +1 -0
  21. package/dist/development/src/application/table.cjs +23 -0
  22. package/dist/development/src/application/table.cjs.map +1 -0
  23. package/dist/development/src/application/table.js +23 -0
  24. package/dist/development/src/application/table.js.map +1 -0
  25. package/dist/production/index.cjs +7 -0
  26. package/dist/production/index.cjs.map +1 -1
  27. package/dist/production/index.js +7 -0
  28. package/dist/production/index.js.map +1 -1
  29. package/dist/production/src/application/Application.cjs +7 -7
  30. package/dist/production/src/application/Application.cjs.map +1 -1
  31. package/dist/production/src/application/Application.js +7 -7
  32. package/dist/production/src/application/Application.js.map +1 -1
  33. package/dist/production/src/application/ErrorRenderer.cjs +3 -3
  34. package/dist/production/src/application/ErrorRenderer.cjs.map +1 -1
  35. package/dist/production/src/application/ErrorRenderer.js +3 -3
  36. package/dist/production/src/application/ErrorRenderer.js.map +1 -1
  37. package/dist/production/src/application/Output.cjs +72 -39
  38. package/dist/production/src/application/Output.cjs.map +1 -1
  39. package/dist/production/src/application/Output.js +72 -39
  40. package/dist/production/src/application/Output.js.map +1 -1
  41. package/dist/production/src/application/colors.cjs +29 -0
  42. package/dist/production/src/application/colors.cjs.map +1 -0
  43. package/dist/production/src/application/colors.js +29 -0
  44. package/dist/production/src/application/colors.js.map +1 -0
  45. package/dist/production/src/application/table.cjs +23 -0
  46. package/dist/production/src/application/table.cjs.map +1 -0
  47. package/dist/production/src/application/table.js +23 -0
  48. package/dist/production/src/application/table.js.map +1 -0
  49. package/dist/types/application/Output.d.ts +23 -8
  50. package/dist/types/application/Output.d.ts.map +1 -1
  51. package/dist/types/application/colors.d.ts +10 -0
  52. package/dist/types/application/colors.d.ts.map +1 -0
  53. package/dist/types/application/index.d.ts +2 -0
  54. package/dist/types/application/index.d.ts.map +1 -1
  55. package/dist/types/application/table.d.ts +7 -0
  56. package/dist/types/application/table.d.ts.map +1 -0
  57. package/dist/types/index.d.ts +2 -2
  58. package/dist/types/index.d.ts.map +1 -1
  59. package/dist/types/tsconfig.tsbuildinfo +1 -1
  60. package/package.json +2 -7
  61. package/src/application/Application.ts +7 -7
  62. package/src/application/ErrorRenderer.ts +3 -3
  63. package/src/application/Output.ts +85 -49
  64. package/src/application/colors.ts +36 -0
  65. package/src/application/index.ts +2 -0
  66. package/src/application/table.ts +31 -0
  67. package/src/index.ts +8 -1
  68. package/tests/cases/unit/application.test.ts +2 -2
  69. package/tests/cases/unit/cliError.test.ts +2 -2
  70. package/tests/cases/unit/colors.test.ts +49 -0
  71. package/tests/cases/unit/output.test.ts +63 -22
  72. package/tests/lib/testOutput.ts +10 -2
  73. package/types/chalk-table/index.d.ts +0 -9
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const Application = require("./src/application/Application.cjs");
4
4
  const CliError = require("./src/application/CliError.cjs");
5
+ const colors = require("./src/application/colors.cjs");
5
6
  const Command = require("./src/application/Command.cjs");
6
7
  const CommandManager = require("./src/application/CommandManager.cjs");
7
8
  const CommandConfiguration = require("./src/application/CommandConfiguration.cjs");
@@ -12,6 +13,7 @@ const Input = require("./src/application/Input.cjs");
12
13
  const InputParser = require("./src/application/InputParser.cjs");
13
14
  const Option = require("./src/application/Option.cjs");
14
15
  const Output = require("./src/application/Output.cjs");
16
+ const table = require("./src/application/table.cjs");
15
17
  const CommandRunner = require("./src/npm/CommandRunner.cjs");
16
18
  const PackageWorkspace = require("./src/npm/PackageWorkspace.cjs");
17
19
  const Bun = require("./src/npm/packageManagers/Bun.cjs");
@@ -25,6 +27,10 @@ exports.Application = Application.Application;
25
27
  exports.CliError = CliError.CliError;
26
28
  exports.ExitCode = CliError.ExitCode;
27
29
  exports.toCliError = CliError.toCliError;
30
+ exports.areColorsEnabled = colors.areColorsEnabled;
31
+ exports.setColorsEnabled = colors.setColorsEnabled;
32
+ exports.style = colors.style;
33
+ exports.terminalSupportsColor = colors.terminalSupportsColor;
28
34
  exports.Command = Command.Command;
29
35
  exports.CommandManager = CommandManager.CommandManager;
30
36
  exports.CommandConfiguration = CommandConfiguration.CommandConfiguration;
@@ -39,6 +45,7 @@ exports.OptionMode = Option.OptionMode;
39
45
  exports.mergeOptions = Option.mergeOptions;
40
46
  exports.Output = Output.Output;
41
47
  exports.escapeTerminalText = Output.escapeTerminalText;
48
+ exports.formatTable = table.formatTable;
42
49
  exports.ChildProcessError = CommandRunner.ChildProcessError;
43
50
  exports.CommandRunner = CommandRunner.CommandRunner;
44
51
  exports.PackageWorkspace = PackageWorkspace.PackageWorkspace;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,6 @@
1
1
  import { Application } from "./src/application/Application.js";
2
2
  import { CliError, ExitCode, toCliError } from "./src/application/CliError.js";
3
+ import { areColorsEnabled, setColorsEnabled, style, terminalSupportsColor } from "./src/application/colors.js";
3
4
  import { Command } from "./src/application/Command.js";
4
5
  import { CommandManager } from "./src/application/CommandManager.js";
5
6
  import { CommandConfiguration, InvalidConfigurationError } from "./src/application/CommandConfiguration.js";
@@ -10,6 +11,7 @@ import { Input } from "./src/application/Input.js";
10
11
  import { InvalidInputError } from "./src/application/InputParser.js";
11
12
  import { OptionMode, mergeOptions } from "./src/application/Option.js";
12
13
  import { Output, escapeTerminalText } from "./src/application/Output.js";
14
+ import { formatTable } from "./src/application/table.js";
13
15
  import { ChildProcessError, CommandRunner } from "./src/npm/CommandRunner.js";
14
16
  import { PackageWorkspace } from "./src/npm/PackageWorkspace.js";
15
17
  import { Bun } from "./src/npm/packageManagers/Bun.js";
@@ -40,13 +42,18 @@ export {
40
42
  Pnpm,
41
43
  Yarn,
42
44
  YarnClassic,
45
+ areColorsEnabled,
43
46
  escapeTerminalText,
44
47
  exitProcess,
45
48
  findPackageRoot,
49
+ formatTable,
46
50
  globalOptions,
47
51
  mergeOptions,
48
52
  readGlobalOptionsFromArgs,
49
53
  renderCliError,
54
+ setColorsEnabled,
55
+ style,
56
+ terminalSupportsColor,
50
57
  toCliError
51
58
  };
52
59
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const chalk = require("chalk");
3
+ const colors = require("./colors.cjs");
4
4
  const Command = require("./Command.cjs");
5
5
  const InputParser = require("./InputParser.cjs");
6
6
  const Output = require("./Output.cjs");
@@ -82,7 +82,7 @@ class Application {
82
82
  const exitCode = ErrorRenderer.renderCliError(e, this.output);
83
83
  if (e instanceof InputParser.InvalidInputError && command !== void 0 && this.output.mode === "human") {
84
84
  const usage = command.getConfiguration().getUsage({ format: "line" });
85
- this.output.writeStderr(`${showCommandName && entry ? chalk.greenBright(entry.name) + " " : ""}${chalk.green(usage)}`);
85
+ this.output.writeStderr(`${showCommandName && entry ? colors.style("greenBright", entry.name) + " " : ""}${colors.style("green", usage)}`);
86
86
  }
87
87
  return exitCode;
88
88
  }
@@ -98,11 +98,11 @@ class Application {
98
98
  const indent = " ";
99
99
  for (const entry of commands) {
100
100
  const configuration = entry.create().getConfiguration();
101
- this.output.writeStderr(`${indent}${chalk.greenBright(entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`);
101
+ this.output.writeStderr(`${indent}${colors.style("greenBright", entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`);
102
102
  if (verbose) {
103
103
  const helpIndent = `${indent}${" ".repeat(maxCommandNameLength)}${indent}`;
104
104
  const usage = configuration.getUsage({ format: "multiline", indent: helpIndent });
105
- this.output.writeStderr(usage ? chalk.green(usage) : `${helpIndent}${chalk.gray("No options")}`);
105
+ this.output.writeStderr(usage ? colors.style("green", usage) : `${helpIndent}${colors.style("gray", "No options")}`);
106
106
  }
107
107
  }
108
108
  }
@@ -112,12 +112,12 @@ class Application {
112
112
  const indent = " ";
113
113
  for (const entry of [...entries].sort((a, b) => a.name.localeCompare(b.name))) {
114
114
  const configuration = entry.create().getConfiguration();
115
- this.output.writeStderr(`${indent}${chalk.greenBright(entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`);
115
+ this.output.writeStderr(`${indent}${colors.style("greenBright", entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`);
116
116
  }
117
117
  }
118
118
  printCommandHelp(name, command, showCommandName) {
119
119
  if (showCommandName) {
120
- this.output.writeStderr(chalk.greenBright(name));
120
+ this.output.writeStderr(colors.style("greenBright", name));
121
121
  }
122
122
  const configuration = command.getConfiguration();
123
123
  const commandDescription = configuration.getDescription();
@@ -127,7 +127,7 @@ class Application {
127
127
  const shortUsage = configuration.getUsage({ format: "short" });
128
128
  if (shortUsage) {
129
129
  this.output.writeStderr("\nUsage:");
130
- this.output.writeStderr(chalk.green(shortUsage));
130
+ this.output.writeStderr(colors.style("green", shortUsage));
131
131
  this.output.writeStderr("\nArguments and options:");
132
132
  this.output.writeStderr(configuration.getUsage({ format: "multiline" }));
133
133
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Application.cjs","sources":["../../../../../packages/cli-common/src/application/Application.ts"],"sourcesContent":["import chalk from 'chalk'\nimport { CommandCatalogEntry, CommandFactory, CommandManager } from './CommandManager.js'\nimport { Command } from './Command.js'\nimport { InvalidInputError } from './InputParser.js'\nimport { Output } from './Output.js'\nimport { ExitCode } from './CliError.js'\nimport { renderCliError } from './ErrorRenderer.js'\nimport { exitProcess } from './exitProcess.js'\nimport { globalOptions, hasHelpFlag, readGlobalOptionsFromArgs } from './GlobalOptions.js'\nimport { UsageFormatter } from './UsageFormatter.js'\n\nexport class Application {\n\tprivate readonly commandManager: CommandManager\n\tprivate readonly applicationDescription: string\n\tprivate readonly output: Output\n\tprivate readonly options: ApplicationOptions\n\n\tconstructor(commandManager: CommandManager, applicationDescription: string, options?: ApplicationOptions)\n\tconstructor(commandManager: CommandManager, applicationDescription: string, output: Output, options?: ApplicationOptions)\n\tconstructor(\n\t\tcommandManager: CommandManager,\n\t\tapplicationDescription: string,\n\t\toutputOrOptions: Output | ApplicationOptions = {},\n\t\toptions: ApplicationOptions = {},\n\t) {\n\t\tthis.commandManager = commandManager\n\t\tthis.applicationDescription = applicationDescription\n\t\tthis.output = outputOrOptions instanceof Output ? outputOrOptions : new Output()\n\t\tthis.options = outputOrOptions instanceof Output ? options : outputOrOptions\n\t}\n\n\tasync run(args: string[]): Promise<void> {\n\t\tif (args.length === 0 || readGlobalOptionsFromArgs(args.slice(0, 1)).help) {\n\t\t\texitProcess(await this.execute(args))\n\t\t\treturn\n\t\t}\n\t\tconst [name, ...commandArgs] = args\n\t\tawait this.runCommandInternal(name, commandArgs, true)\n\t}\n\n\tpublic async runCommand(name: string, args: string[]): Promise<void> {\n\t\tawait this.runCommandInternal(name, args, false)\n\t}\n\n\tpublic async runCommandInternal(name: string, args: string[], showCommandName: boolean): Promise<void> {\n\t\texitProcess(await this.executeArgs([name, ...args], showCommandName))\n\t}\n\n\t/** Runs the given argv and returns the exit code instead of terminating the process. */\n\tpublic async execute(args: string[]): Promise<number> {\n\t\tconst help = readGlobalOptionsFromArgs(args.slice(0, 1)).help\n\t\tif (args.length === 0 || help) {\n\t\t\tthis.printApplicationHelp(help)\n\t\t\treturn ExitCode.Success\n\t\t}\n\t\treturn this.executeArgs(args, true)\n\t}\n\n\tpublic async executeCommand(name: string, args: string[]): Promise<number> {\n\t\treturn this.executeArgs([name, ...args], false)\n\t}\n\n\tprivate async executeArgs(args: string[], showCommandName: boolean): Promise<number> {\n\t\tlet entry: CommandCatalogEntry | undefined\n\t\tlet command: ReturnType<CommandFactory> | undefined\n\t\t// the mode has to be known before anything can fail, so that every error is reported in the requested format\n\t\tthis.output.applyGlobalOptions(readGlobalOptionsFromArgs(args))\n\t\ttry {\n\t\t\tconst resolution = this.commandManager.resolve(args)\n\t\t\tif (resolution.type === 'group') {\n\t\t\t\tconst groupHelp = resolution.args.length === 1 && (resolution.args[0] === '--help' || resolution.args[0] === '-h')\n\t\t\t\tif (resolution.args.length > 0 && !groupHelp) {\n\t\t\t\t\tthrow new InvalidInputError(`Unexpected input after command group \"${resolution.name}\": ${resolution.args.join(' ')}`)\n\t\t\t\t}\n\t\t\t\tthis.printGroupHelp(resolution.name, resolution.entries)\n\t\t\t\treturn ExitCode.Success\n\t\t\t}\n\t\t\tentry = resolution.entry\n\t\t\tconst commandArgs = resolution.args\n\t\t\tcommand = entry.create()\n\n\t\t\tif (hasHelpFlag(commandArgs)) {\n\t\t\t\tthis.printCommandHelp(entry.name, command, showCommandName)\n\t\t\t\treturn ExitCode.Success\n\t\t\t}\n\n\t\t\tif (command.run !== Command.prototype.run) {\n\t\t\t\tawait this.options.beforeRun?.({ command, args: commandArgs, name: entry.name })\n\t\t\t\treturn await command.run(commandArgs, this.output)\n\t\t\t}\n\n\t\t\tconst parsed = command.parse(commandArgs)\n\t\t\tthis.output.applyGlobalOptions(parsed.globals)\n\n\t\t\tawait this.options.beforeRun?.({ command, args: commandArgs, name: entry.name })\n\n\t\t\treturn await command.runParsed(parsed, this.output)\n\t\t} catch (e) {\n\t\t\tconst exitCode = renderCliError(e, this.output)\n\t\t\tif (e instanceof InvalidInputError && command !== undefined && this.output.mode === 'human') {\n\t\t\t\tconst usage = command.getConfiguration().getUsage({ format: 'line' })\n\t\t\t\tthis.output.writeStderr(`${showCommandName && entry ? chalk.greenBright(entry.name) + ' ' : ''}${chalk.green(usage)}`)\n\t\t\t}\n\t\t\treturn exitCode\n\t\t}\n\t}\n\n\tprivate printApplicationHelp(verbose: boolean): void {\n\t\tthis.output.writeStderr(this.applicationDescription)\n\t\tthis.output.writeStderr(`Usage: <command> <command args>`)\n\t\tconst commands = this.commandManager.getCommands()\n\t\tif (commands.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst maxCommandNameLength = Math.max(...commands.map(it => it.name.length))\n\t\tconst indent = ' '\n\t\tfor (const entry of commands) {\n\t\t\tconst configuration = entry.create().getConfiguration()\n\t\t\tthis.output.writeStderr(`${indent}${chalk.greenBright(entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`)\n\t\t\tif (verbose) {\n\t\t\t\tconst helpIndent = `${indent}${' '.repeat(maxCommandNameLength)}${indent}`\n\t\t\t\tconst usage = configuration.getUsage({ format: 'multiline', indent: helpIndent })\n\t\t\t\tthis.output.writeStderr(usage ? chalk.green(usage) : `${helpIndent}${chalk.gray('No options')}`)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate printGroupHelp(name: string, entries: readonly CommandCatalogEntry[]): void {\n\t\tthis.output.writeStderr(`Usage: ${name} <command> <command args>`)\n\t\tconst maxCommandNameLength = Math.max(...entries.map(it => it.name.length))\n\t\tconst indent = ' '\n\t\tfor (const entry of [...entries].sort((a, b) => a.name.localeCompare(b.name))) {\n\t\t\tconst configuration = entry.create().getConfiguration()\n\t\t\tthis.output.writeStderr(`${indent}${chalk.greenBright(entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`)\n\t\t}\n\t}\n\n\tprivate printCommandHelp(name: string, command: ReturnType<CommandFactory>, showCommandName: boolean): void {\n\t\tif (showCommandName) {\n\t\t\tthis.output.writeStderr(chalk.greenBright(name))\n\t\t}\n\t\tconst configuration = command.getConfiguration()\n\t\tconst commandDescription = configuration.getDescription()\n\t\tif (commandDescription) {\n\t\t\tthis.output.writeStderr(commandDescription)\n\t\t}\n\t\tconst shortUsage = configuration.getUsage({ format: 'short' })\n\t\tif (shortUsage) {\n\t\t\tthis.output.writeStderr('\\nUsage:')\n\t\t\tthis.output.writeStderr(chalk.green(shortUsage))\n\t\t\tthis.output.writeStderr('\\nArguments and options:')\n\t\t\tthis.output.writeStderr(configuration.getUsage({ format: 'multiline' }))\n\t\t}\n\t\tthis.output.writeStderr('\\nGlobal options:')\n\t\tthis.output.writeStderr(UsageFormatter.format([], [...globalOptions], { format: 'multiline' }))\n\t}\n}\n\ninterface ApplicationOptions {\n\tbeforeRun?: (args: { command: ReturnType<CommandFactory>; name: string; args: string[] }) => void | Promise<void>\n}\n"],"names":["Output","readGlobalOptionsFromArgs","exitProcess","ExitCode","InvalidInputError","hasHelpFlag","Command","renderCliError","UsageFormatter","globalOptions"],"mappings":";;;;;;;;;;;;;;AAWO,MAAM,YAAY;AAAA,EAQxB,YACC,gBACA,wBACA,kBAA+C,CAAA,GAC/C,UA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KAAK,CAAC,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC,GAAG;AAC9E,YAAM,gBAAgB,MAAM,OAAA,EAAS,iBAAA;AACrC,WAAK,OAAO,YAAY,GAAG,MAAM,GAAG,MAAM,YAAY,MAAM,KAAK,OAAO,oBAAoB,CAAC,CAAC,GAAG,MAAM,GAAG,cAAc,eAAA,CAAgB,EAAE;AAAA,IAC3I;AAAA,EACD;AAAA,EAEQ,iBAAiB,MAAc,SAAqC,iBAAgC;AAC3G,QAAI,iBAAiB;AACpB,WAAK,OAAO,YAAY,MAAM,YAAY,IAAI,CAAC;AAAA,IAChD;AACA,UAAM,gBAAgB,QAAQ,iBAAA;AAC9B,UAAM,qBAAqB,cAAc,eAAA;AACzC,QAAI,oBAAoB;AACvB,WAAK,OAAO,YAAY,kBAAkB;AAAA,IAC3C;AACA,UAAM,aAAa,cAAc,SAAS,EAAE,QAAQ,SAAS;AAC7D,QAAI,YAAY;AACf,WAAK,OAAO,YAAY,UAAU;AAClC,WAAK,OAAO,YAAY,MAAM,MAAM,UAAU,CAAC;AAC/C,WAAK,OAAO,YAAY,0BAA0B;AAClD,WAAK,OAAO,YAAY,cAAc,SAAS,EAAE,QAAQ,YAAA,CAAa,CAAC;AAAA,IACxE;AACA,SAAK,OAAO,YAAY,mBAAmB;AAC3C,SAAK,OAAO,YAAYI,eAAAA,eAAe,OAAO,CAAA,GAAI,CAAC,GAAGC,cAAAA,aAAa,GAAG,EAAE,QAAQ,YAAA,CAAa,CAAC;AAAA,EAC/F;AACD;;"}
1
+ {"version":3,"file":"Application.cjs","sources":["../../../../../packages/cli-common/src/application/Application.ts"],"sourcesContent":["import { style } from './colors.js'\nimport { CommandCatalogEntry, CommandFactory, CommandManager } from './CommandManager.js'\nimport { Command } from './Command.js'\nimport { InvalidInputError } from './InputParser.js'\nimport { Output } from './Output.js'\nimport { ExitCode } from './CliError.js'\nimport { renderCliError } from './ErrorRenderer.js'\nimport { exitProcess } from './exitProcess.js'\nimport { globalOptions, hasHelpFlag, readGlobalOptionsFromArgs } from './GlobalOptions.js'\nimport { UsageFormatter } from './UsageFormatter.js'\n\nexport class Application {\n\tprivate readonly commandManager: CommandManager\n\tprivate readonly applicationDescription: string\n\tprivate readonly output: Output\n\tprivate readonly options: ApplicationOptions\n\n\tconstructor(commandManager: CommandManager, applicationDescription: string, options?: ApplicationOptions)\n\tconstructor(commandManager: CommandManager, applicationDescription: string, output: Output, options?: ApplicationOptions)\n\tconstructor(\n\t\tcommandManager: CommandManager,\n\t\tapplicationDescription: string,\n\t\toutputOrOptions: Output | ApplicationOptions = {},\n\t\toptions: ApplicationOptions = {},\n\t) {\n\t\tthis.commandManager = commandManager\n\t\tthis.applicationDescription = applicationDescription\n\t\tthis.output = outputOrOptions instanceof Output ? outputOrOptions : new Output()\n\t\tthis.options = outputOrOptions instanceof Output ? options : outputOrOptions\n\t}\n\n\tasync run(args: string[]): Promise<void> {\n\t\tif (args.length === 0 || readGlobalOptionsFromArgs(args.slice(0, 1)).help) {\n\t\t\texitProcess(await this.execute(args))\n\t\t\treturn\n\t\t}\n\t\tconst [name, ...commandArgs] = args\n\t\tawait this.runCommandInternal(name, commandArgs, true)\n\t}\n\n\tpublic async runCommand(name: string, args: string[]): Promise<void> {\n\t\tawait this.runCommandInternal(name, args, false)\n\t}\n\n\tpublic async runCommandInternal(name: string, args: string[], showCommandName: boolean): Promise<void> {\n\t\texitProcess(await this.executeArgs([name, ...args], showCommandName))\n\t}\n\n\t/** Runs the given argv and returns the exit code instead of terminating the process. */\n\tpublic async execute(args: string[]): Promise<number> {\n\t\tconst help = readGlobalOptionsFromArgs(args.slice(0, 1)).help\n\t\tif (args.length === 0 || help) {\n\t\t\tthis.printApplicationHelp(help)\n\t\t\treturn ExitCode.Success\n\t\t}\n\t\treturn this.executeArgs(args, true)\n\t}\n\n\tpublic async executeCommand(name: string, args: string[]): Promise<number> {\n\t\treturn this.executeArgs([name, ...args], false)\n\t}\n\n\tprivate async executeArgs(args: string[], showCommandName: boolean): Promise<number> {\n\t\tlet entry: CommandCatalogEntry | undefined\n\t\tlet command: ReturnType<CommandFactory> | undefined\n\t\t// the mode has to be known before anything can fail, so that every error is reported in the requested format\n\t\tthis.output.applyGlobalOptions(readGlobalOptionsFromArgs(args))\n\t\ttry {\n\t\t\tconst resolution = this.commandManager.resolve(args)\n\t\t\tif (resolution.type === 'group') {\n\t\t\t\tconst groupHelp = resolution.args.length === 1 && (resolution.args[0] === '--help' || resolution.args[0] === '-h')\n\t\t\t\tif (resolution.args.length > 0 && !groupHelp) {\n\t\t\t\t\tthrow new InvalidInputError(`Unexpected input after command group \"${resolution.name}\": ${resolution.args.join(' ')}`)\n\t\t\t\t}\n\t\t\t\tthis.printGroupHelp(resolution.name, resolution.entries)\n\t\t\t\treturn ExitCode.Success\n\t\t\t}\n\t\t\tentry = resolution.entry\n\t\t\tconst commandArgs = resolution.args\n\t\t\tcommand = entry.create()\n\n\t\t\tif (hasHelpFlag(commandArgs)) {\n\t\t\t\tthis.printCommandHelp(entry.name, command, showCommandName)\n\t\t\t\treturn ExitCode.Success\n\t\t\t}\n\n\t\t\tif (command.run !== Command.prototype.run) {\n\t\t\t\tawait this.options.beforeRun?.({ command, args: commandArgs, name: entry.name })\n\t\t\t\treturn await command.run(commandArgs, this.output)\n\t\t\t}\n\n\t\t\tconst parsed = command.parse(commandArgs)\n\t\t\tthis.output.applyGlobalOptions(parsed.globals)\n\n\t\t\tawait this.options.beforeRun?.({ command, args: commandArgs, name: entry.name })\n\n\t\t\treturn await command.runParsed(parsed, this.output)\n\t\t} catch (e) {\n\t\t\tconst exitCode = renderCliError(e, this.output)\n\t\t\tif (e instanceof InvalidInputError && command !== undefined && this.output.mode === 'human') {\n\t\t\t\tconst usage = command.getConfiguration().getUsage({ format: 'line' })\n\t\t\t\tthis.output.writeStderr(`${showCommandName && entry ? style('greenBright', entry.name) + ' ' : ''}${style('green', usage)}`)\n\t\t\t}\n\t\t\treturn exitCode\n\t\t}\n\t}\n\n\tprivate printApplicationHelp(verbose: boolean): void {\n\t\tthis.output.writeStderr(this.applicationDescription)\n\t\tthis.output.writeStderr(`Usage: <command> <command args>`)\n\t\tconst commands = this.commandManager.getCommands()\n\t\tif (commands.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst maxCommandNameLength = Math.max(...commands.map(it => it.name.length))\n\t\tconst indent = ' '\n\t\tfor (const entry of commands) {\n\t\t\tconst configuration = entry.create().getConfiguration()\n\t\t\tthis.output.writeStderr(`${indent}${style('greenBright', entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`)\n\t\t\tif (verbose) {\n\t\t\t\tconst helpIndent = `${indent}${' '.repeat(maxCommandNameLength)}${indent}`\n\t\t\t\tconst usage = configuration.getUsage({ format: 'multiline', indent: helpIndent })\n\t\t\t\tthis.output.writeStderr(usage ? style('green', usage) : `${helpIndent}${style('gray', 'No options')}`)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate printGroupHelp(name: string, entries: readonly CommandCatalogEntry[]): void {\n\t\tthis.output.writeStderr(`Usage: ${name} <command> <command args>`)\n\t\tconst maxCommandNameLength = Math.max(...entries.map(it => it.name.length))\n\t\tconst indent = ' '\n\t\tfor (const entry of [...entries].sort((a, b) => a.name.localeCompare(b.name))) {\n\t\t\tconst configuration = entry.create().getConfiguration()\n\t\t\tthis.output.writeStderr(`${indent}${style('greenBright', entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`)\n\t\t}\n\t}\n\n\tprivate printCommandHelp(name: string, command: ReturnType<CommandFactory>, showCommandName: boolean): void {\n\t\tif (showCommandName) {\n\t\t\tthis.output.writeStderr(style('greenBright', name))\n\t\t}\n\t\tconst configuration = command.getConfiguration()\n\t\tconst commandDescription = configuration.getDescription()\n\t\tif (commandDescription) {\n\t\t\tthis.output.writeStderr(commandDescription)\n\t\t}\n\t\tconst shortUsage = configuration.getUsage({ format: 'short' })\n\t\tif (shortUsage) {\n\t\t\tthis.output.writeStderr('\\nUsage:')\n\t\t\tthis.output.writeStderr(style('green', shortUsage))\n\t\t\tthis.output.writeStderr('\\nArguments and options:')\n\t\t\tthis.output.writeStderr(configuration.getUsage({ format: 'multiline' }))\n\t\t}\n\t\tthis.output.writeStderr('\\nGlobal options:')\n\t\tthis.output.writeStderr(UsageFormatter.format([], [...globalOptions], { format: 'multiline' }))\n\t}\n}\n\ninterface ApplicationOptions {\n\tbeforeRun?: (args: { command: ReturnType<CommandFactory>; name: string; args: string[] }) => void | Promise<void>\n}\n"],"names":["Output","readGlobalOptionsFromArgs","exitProcess","ExitCode","InvalidInputError","hasHelpFlag","Command","renderCliError","style","UsageFormatter","globalOptions"],"mappings":";;;;;;;;;;;;;;AAWO,MAAM,YAAY;AAAA,EAQxB,YACC,gBACA,wBACA,kBAA+C,CAAA,GAC/C,UAA8B,IAC7B;AAZF,kBAAA,MAAiB,gBAAA;AACjB,kBAAA,MAAiB,wBAAA;AACjB,kBAAA,MAAiB,QAAA;AACjB,kBAAA,MAAiB,SAAA;AAUhB,SAAK,iBAAiB;AACtB,SAAK,yBAAyB;AAC9B,SAAK,SAAS,2BAA2BA,OAAAA,SAAS,kBAAkB,IAAIA,OAAAA,OAAA;AACxE,SAAK,UAAU,2BAA2BA,OAAAA,SAAS,UAAU;AAAA,EAC9D;AAAA,EAEA,MAAM,IAAI,MAA+B;AACxC,QAAI,KAAK,WAAW,KAAKC,wCAA0B,KAAK,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM;AAC1EC,kBAAAA,YAAY,MAAM,KAAK,QAAQ,IAAI,CAAC;AACpC;AAAA,IACD;AACA,UAAM,CAAC,MAAM,GAAG,WAAW,IAAI;AAC/B,UAAM,KAAK,mBAAmB,MAAM,aAAa,IAAI;AAAA,EACtD;AAAA,EAEA,MAAa,WAAW,MAAc,MAA+B;AACpE,UAAM,KAAK,mBAAmB,MAAM,MAAM,KAAK;AAAA,EAChD;AAAA,EAEA,MAAa,mBAAmB,MAAc,MAAgB,iBAAyC;AACtGA,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SAAS,UAAU,CAAC;AAClD,WAAK,OAAO,YAAY,0BAA0B;AAClD,WAAK,OAAO,YAAY,cAAc,SAAS,EAAE,QAAQ,YAAA,CAAa,CAAC;AAAA,IACxE;AACA,SAAK,OAAO,YAAY,mBAAmB;AAC3C,SAAK,OAAO,YAAYC,eAAAA,eAAe,OAAO,CAAA,GAAI,CAAC,GAAGC,cAAAA,aAAa,GAAG,EAAE,QAAQ,YAAA,CAAa,CAAC;AAAA,EAC/F;AACD;;"}
@@ -1,4 +1,4 @@
1
- import chalk from "chalk";
1
+ import { style } from "./colors.js";
2
2
  import { Command } from "./Command.js";
3
3
  import { InvalidInputError } from "./InputParser.js";
4
4
  import { Output } from "./Output.js";
@@ -80,7 +80,7 @@ class Application {
80
80
  const exitCode = renderCliError(e, this.output);
81
81
  if (e instanceof InvalidInputError && command !== void 0 && this.output.mode === "human") {
82
82
  const usage = command.getConfiguration().getUsage({ format: "line" });
83
- this.output.writeStderr(`${showCommandName && entry ? chalk.greenBright(entry.name) + " " : ""}${chalk.green(usage)}`);
83
+ this.output.writeStderr(`${showCommandName && entry ? style("greenBright", entry.name) + " " : ""}${style("green", usage)}`);
84
84
  }
85
85
  return exitCode;
86
86
  }
@@ -96,11 +96,11 @@ class Application {
96
96
  const indent = " ";
97
97
  for (const entry of commands) {
98
98
  const configuration = entry.create().getConfiguration();
99
- this.output.writeStderr(`${indent}${chalk.greenBright(entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`);
99
+ this.output.writeStderr(`${indent}${style("greenBright", entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`);
100
100
  if (verbose) {
101
101
  const helpIndent = `${indent}${" ".repeat(maxCommandNameLength)}${indent}`;
102
102
  const usage = configuration.getUsage({ format: "multiline", indent: helpIndent });
103
- this.output.writeStderr(usage ? chalk.green(usage) : `${helpIndent}${chalk.gray("No options")}`);
103
+ this.output.writeStderr(usage ? style("green", usage) : `${helpIndent}${style("gray", "No options")}`);
104
104
  }
105
105
  }
106
106
  }
@@ -110,12 +110,12 @@ class Application {
110
110
  const indent = " ";
111
111
  for (const entry of [...entries].sort((a, b) => a.name.localeCompare(b.name))) {
112
112
  const configuration = entry.create().getConfiguration();
113
- this.output.writeStderr(`${indent}${chalk.greenBright(entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`);
113
+ this.output.writeStderr(`${indent}${style("greenBright", entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`);
114
114
  }
115
115
  }
116
116
  printCommandHelp(name, command, showCommandName) {
117
117
  if (showCommandName) {
118
- this.output.writeStderr(chalk.greenBright(name));
118
+ this.output.writeStderr(style("greenBright", name));
119
119
  }
120
120
  const configuration = command.getConfiguration();
121
121
  const commandDescription = configuration.getDescription();
@@ -125,7 +125,7 @@ class Application {
125
125
  const shortUsage = configuration.getUsage({ format: "short" });
126
126
  if (shortUsage) {
127
127
  this.output.writeStderr("\nUsage:");
128
- this.output.writeStderr(chalk.green(shortUsage));
128
+ this.output.writeStderr(style("green", shortUsage));
129
129
  this.output.writeStderr("\nArguments and options:");
130
130
  this.output.writeStderr(configuration.getUsage({ format: "multiline" }));
131
131
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Application.js","sources":["../../../../../packages/cli-common/src/application/Application.ts"],"sourcesContent":["import chalk from 'chalk'\nimport { CommandCatalogEntry, CommandFactory, CommandManager } from './CommandManager.js'\nimport { Command } from './Command.js'\nimport { InvalidInputError } from './InputParser.js'\nimport { Output } from './Output.js'\nimport { ExitCode } from './CliError.js'\nimport { renderCliError } from './ErrorRenderer.js'\nimport { exitProcess } from './exitProcess.js'\nimport { globalOptions, hasHelpFlag, readGlobalOptionsFromArgs } from './GlobalOptions.js'\nimport { UsageFormatter } from './UsageFormatter.js'\n\nexport class Application {\n\tprivate readonly commandManager: CommandManager\n\tprivate readonly applicationDescription: string\n\tprivate readonly output: Output\n\tprivate readonly options: ApplicationOptions\n\n\tconstructor(commandManager: CommandManager, applicationDescription: string, options?: ApplicationOptions)\n\tconstructor(commandManager: CommandManager, applicationDescription: string, output: Output, options?: ApplicationOptions)\n\tconstructor(\n\t\tcommandManager: CommandManager,\n\t\tapplicationDescription: string,\n\t\toutputOrOptions: Output | ApplicationOptions = {},\n\t\toptions: ApplicationOptions = {},\n\t) {\n\t\tthis.commandManager = commandManager\n\t\tthis.applicationDescription = applicationDescription\n\t\tthis.output = outputOrOptions instanceof Output ? outputOrOptions : new Output()\n\t\tthis.options = outputOrOptions instanceof Output ? options : outputOrOptions\n\t}\n\n\tasync run(args: string[]): Promise<void> {\n\t\tif (args.length === 0 || readGlobalOptionsFromArgs(args.slice(0, 1)).help) {\n\t\t\texitProcess(await this.execute(args))\n\t\t\treturn\n\t\t}\n\t\tconst [name, ...commandArgs] = args\n\t\tawait this.runCommandInternal(name, commandArgs, true)\n\t}\n\n\tpublic async runCommand(name: string, args: string[]): Promise<void> {\n\t\tawait this.runCommandInternal(name, args, false)\n\t}\n\n\tpublic async runCommandInternal(name: string, args: string[], showCommandName: boolean): Promise<void> {\n\t\texitProcess(await this.executeArgs([name, ...args], showCommandName))\n\t}\n\n\t/** Runs the given argv and returns the exit code instead of terminating the process. */\n\tpublic async execute(args: string[]): Promise<number> {\n\t\tconst help = readGlobalOptionsFromArgs(args.slice(0, 1)).help\n\t\tif (args.length === 0 || help) {\n\t\t\tthis.printApplicationHelp(help)\n\t\t\treturn ExitCode.Success\n\t\t}\n\t\treturn this.executeArgs(args, true)\n\t}\n\n\tpublic async executeCommand(name: string, args: string[]): Promise<number> {\n\t\treturn this.executeArgs([name, ...args], false)\n\t}\n\n\tprivate async executeArgs(args: string[], showCommandName: boolean): Promise<number> {\n\t\tlet entry: CommandCatalogEntry | undefined\n\t\tlet command: ReturnType<CommandFactory> | undefined\n\t\t// the mode has to be known before anything can fail, so that every error is reported in the requested format\n\t\tthis.output.applyGlobalOptions(readGlobalOptionsFromArgs(args))\n\t\ttry {\n\t\t\tconst resolution = this.commandManager.resolve(args)\n\t\t\tif (resolution.type === 'group') {\n\t\t\t\tconst groupHelp = resolution.args.length === 1 && (resolution.args[0] === '--help' || resolution.args[0] === '-h')\n\t\t\t\tif (resolution.args.length > 0 && !groupHelp) {\n\t\t\t\t\tthrow new InvalidInputError(`Unexpected input after command group \"${resolution.name}\": ${resolution.args.join(' ')}`)\n\t\t\t\t}\n\t\t\t\tthis.printGroupHelp(resolution.name, resolution.entries)\n\t\t\t\treturn ExitCode.Success\n\t\t\t}\n\t\t\tentry = resolution.entry\n\t\t\tconst commandArgs = resolution.args\n\t\t\tcommand = entry.create()\n\n\t\t\tif (hasHelpFlag(commandArgs)) {\n\t\t\t\tthis.printCommandHelp(entry.name, command, showCommandName)\n\t\t\t\treturn ExitCode.Success\n\t\t\t}\n\n\t\t\tif (command.run !== Command.prototype.run) {\n\t\t\t\tawait this.options.beforeRun?.({ command, args: commandArgs, name: entry.name })\n\t\t\t\treturn await command.run(commandArgs, this.output)\n\t\t\t}\n\n\t\t\tconst parsed = command.parse(commandArgs)\n\t\t\tthis.output.applyGlobalOptions(parsed.globals)\n\n\t\t\tawait this.options.beforeRun?.({ command, args: commandArgs, name: entry.name })\n\n\t\t\treturn await command.runParsed(parsed, this.output)\n\t\t} catch (e) {\n\t\t\tconst exitCode = renderCliError(e, this.output)\n\t\t\tif (e instanceof InvalidInputError && command !== undefined && this.output.mode === 'human') {\n\t\t\t\tconst usage = command.getConfiguration().getUsage({ format: 'line' })\n\t\t\t\tthis.output.writeStderr(`${showCommandName && entry ? chalk.greenBright(entry.name) + ' ' : ''}${chalk.green(usage)}`)\n\t\t\t}\n\t\t\treturn exitCode\n\t\t}\n\t}\n\n\tprivate printApplicationHelp(verbose: boolean): void {\n\t\tthis.output.writeStderr(this.applicationDescription)\n\t\tthis.output.writeStderr(`Usage: <command> <command args>`)\n\t\tconst commands = this.commandManager.getCommands()\n\t\tif (commands.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst maxCommandNameLength = Math.max(...commands.map(it => it.name.length))\n\t\tconst indent = ' '\n\t\tfor (const entry of commands) {\n\t\t\tconst configuration = entry.create().getConfiguration()\n\t\t\tthis.output.writeStderr(`${indent}${chalk.greenBright(entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`)\n\t\t\tif (verbose) {\n\t\t\t\tconst helpIndent = `${indent}${' '.repeat(maxCommandNameLength)}${indent}`\n\t\t\t\tconst usage = configuration.getUsage({ format: 'multiline', indent: helpIndent })\n\t\t\t\tthis.output.writeStderr(usage ? chalk.green(usage) : `${helpIndent}${chalk.gray('No options')}`)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate printGroupHelp(name: string, entries: readonly CommandCatalogEntry[]): void {\n\t\tthis.output.writeStderr(`Usage: ${name} <command> <command args>`)\n\t\tconst maxCommandNameLength = Math.max(...entries.map(it => it.name.length))\n\t\tconst indent = ' '\n\t\tfor (const entry of [...entries].sort((a, b) => a.name.localeCompare(b.name))) {\n\t\t\tconst configuration = entry.create().getConfiguration()\n\t\t\tthis.output.writeStderr(`${indent}${chalk.greenBright(entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`)\n\t\t}\n\t}\n\n\tprivate printCommandHelp(name: string, command: ReturnType<CommandFactory>, showCommandName: boolean): void {\n\t\tif (showCommandName) {\n\t\t\tthis.output.writeStderr(chalk.greenBright(name))\n\t\t}\n\t\tconst configuration = command.getConfiguration()\n\t\tconst commandDescription = configuration.getDescription()\n\t\tif (commandDescription) {\n\t\t\tthis.output.writeStderr(commandDescription)\n\t\t}\n\t\tconst shortUsage = configuration.getUsage({ format: 'short' })\n\t\tif (shortUsage) {\n\t\t\tthis.output.writeStderr('\\nUsage:')\n\t\t\tthis.output.writeStderr(chalk.green(shortUsage))\n\t\t\tthis.output.writeStderr('\\nArguments and options:')\n\t\t\tthis.output.writeStderr(configuration.getUsage({ format: 'multiline' }))\n\t\t}\n\t\tthis.output.writeStderr('\\nGlobal options:')\n\t\tthis.output.writeStderr(UsageFormatter.format([], [...globalOptions], { format: 'multiline' }))\n\t}\n}\n\ninterface ApplicationOptions {\n\tbeforeRun?: (args: { command: ReturnType<CommandFactory>; name: string; args: string[] }) => void | Promise<void>\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAWO,MAAM,YAAY;AAAA,EAQxB,YACC,gBACA,wBACA,kBAA+C,CAAA,GAC/C,UAA8B,IAC7B;AAZF,kBAAA,MAAiB,gBAAA;AACjB,kBAAA,MAAiB,wBAAA;AACjB,kBAAA,MAAiB,QAAA;AACjB,kBAAA,MAAiB,SAAA;AAUhB,SAAK,iBAAiB;AACtB,SAAK,yBAAyB;AAC9B,SAAK,SAAS,2BAA2B,SAAS,kBAAkB,IAAI,OAAA;AACxE,SAAK,UAAU,2BAA2B,SAAS,UAAU;AAAA,EAC9D;AAAA,EAEA,MAAM,IAAI,MAA+B;AACxC,QAAI,KAAK,WAAW,KAAK,0BAA0B,KAAK,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM;AAC1E,kBAAY,MAAM,KAAK,QAAQ,IAAI,CAAC;AACpC;AAAA,IACD;AACA,UAAM,CAAC,MAAM,GAAG,WAAW,IAAI;AAC/B,UAAM,KAAK,mBAAmB,MAAM,aAAa,IAAI;AAAA,EACtD;AAAA,EAEA,MAAa,WAAW,MAAc,MAA+B;AACpE,UAAM,KAAK,mBAAmB,MAAM,MAAM,KAAK;AAAA,EAChD;AAAA,EAEA,MAAa,mBAAmB,MAAc,MAAgB,iBAAyC;AACtG,gBAAY,MAAM,KAAK,YAAY,CAAC,MAAM,GAAG,IAAI,GAAG,eAAe,CAAC;AAAA,EACrE;AAAA;AAAA,EAGA,MAAa,QAAQ,MAAiC;AACrD,UAAM,OAAO,0BAA0B,KAAK,MAAM,GAAG,CAAC,CAAC,EAAE;AACzD,QAAI,KAAK,WAAW,KAAK,MAAM;AAC9B,WAAK,qBAAqB,IAAI;AAC9B,aAAO,SAAS;AAAA,IACjB;AACA,WAAO,KAAK,YAAY,MAAM,IAAI;AAAA,EACnC;AAAA,EAEA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CAAA,OAAM,GAAG,KAAK,MAAM,CAAC;AAC1E,UAAM,SAAS;AACf,eAAW,SAAS,CAAC,GAAG,OAAO,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC,GAAG;AAC9E,YAAM,gBAAgB,MAAM,OAAA,EAAS,iBAAA;AACrC,WAAK,OAAO,YAAY,GAAG,MAAM,GAAG,MAAM,YAAY,MAAM,KAAK,OAAO,oBAAoB,CAAC,CAAC,GAAG,MAAM,GAAG,cAAc,eAAA,CAAgB,EAAE;AAAA,IAC3I;AAAA,EACD;AAAA,EAEQ,iBAAiB,MAAc,SAAqC,iBAAgC;AAC3G,QAAI,iBAAiB;AACpB,WAAK,OAAO,YAAY,MAAM,YAAY,IAAI,CAAC;AAAA,IAChD;AACA,UAAM,gBAAgB,QAAQ,iBAAA;AAC9B,UAAM,qBAAqB,cAAc,eAAA;AACzC,QAAI,oBAAoB;AACvB,WAAK,OAAO,YAAY,kBAAkB;AAAA,IAC3C;AACA,UAAM,aAAa,cAAc,SAAS,EAAE,QAAQ,SAAS;AAC7D,QAAI,YAAY;AACf,WAAK,OAAO,YAAY,UAAU;AAClC,WAAK,OAAO,YAAY,MAAM,MAAM,UAAU,CAAC;AAC/C,WAAK,OAAO,YAAY,0BAA0B;AAClD,WAAK,OAAO,YAAY,cAAc,SAAS,EAAE,QAAQ,YAAA,CAAa,CAAC;AAAA,IACxE;AACA,SAAK,OAAO,YAAY,mBAAmB;AAC3C,SAAK,OAAO,YAAY,eAAe,OAAO,CAAA,GAAI,CAAC,GAAG,aAAa,GAAG,EAAE,QAAQ,YAAA,CAAa,CAAC;AAAA,EAC/F;AACD;"}
1
+ {"version":3,"file":"Application.js","sources":["../../../../../packages/cli-common/src/application/Application.ts"],"sourcesContent":["import { style } from './colors.js'\nimport { CommandCatalogEntry, CommandFactory, CommandManager } from './CommandManager.js'\nimport { Command } from './Command.js'\nimport { InvalidInputError } from './InputParser.js'\nimport { Output } from './Output.js'\nimport { ExitCode } from './CliError.js'\nimport { renderCliError } from './ErrorRenderer.js'\nimport { exitProcess } from './exitProcess.js'\nimport { globalOptions, hasHelpFlag, readGlobalOptionsFromArgs } from './GlobalOptions.js'\nimport { UsageFormatter } from './UsageFormatter.js'\n\nexport class Application {\n\tprivate readonly commandManager: CommandManager\n\tprivate readonly applicationDescription: string\n\tprivate readonly output: Output\n\tprivate readonly options: ApplicationOptions\n\n\tconstructor(commandManager: CommandManager, applicationDescription: string, options?: ApplicationOptions)\n\tconstructor(commandManager: CommandManager, applicationDescription: string, output: Output, options?: ApplicationOptions)\n\tconstructor(\n\t\tcommandManager: CommandManager,\n\t\tapplicationDescription: string,\n\t\toutputOrOptions: Output | ApplicationOptions = {},\n\t\toptions: ApplicationOptions = {},\n\t) {\n\t\tthis.commandManager = commandManager\n\t\tthis.applicationDescription = applicationDescription\n\t\tthis.output = outputOrOptions instanceof Output ? outputOrOptions : new Output()\n\t\tthis.options = outputOrOptions instanceof Output ? options : outputOrOptions\n\t}\n\n\tasync run(args: string[]): Promise<void> {\n\t\tif (args.length === 0 || readGlobalOptionsFromArgs(args.slice(0, 1)).help) {\n\t\t\texitProcess(await this.execute(args))\n\t\t\treturn\n\t\t}\n\t\tconst [name, ...commandArgs] = args\n\t\tawait this.runCommandInternal(name, commandArgs, true)\n\t}\n\n\tpublic async runCommand(name: string, args: string[]): Promise<void> {\n\t\tawait this.runCommandInternal(name, args, false)\n\t}\n\n\tpublic async runCommandInternal(name: string, args: string[], showCommandName: boolean): Promise<void> {\n\t\texitProcess(await this.executeArgs([name, ...args], showCommandName))\n\t}\n\n\t/** Runs the given argv and returns the exit code instead of terminating the process. */\n\tpublic async execute(args: string[]): Promise<number> {\n\t\tconst help = readGlobalOptionsFromArgs(args.slice(0, 1)).help\n\t\tif (args.length === 0 || help) {\n\t\t\tthis.printApplicationHelp(help)\n\t\t\treturn ExitCode.Success\n\t\t}\n\t\treturn this.executeArgs(args, true)\n\t}\n\n\tpublic async executeCommand(name: string, args: string[]): Promise<number> {\n\t\treturn this.executeArgs([name, ...args], false)\n\t}\n\n\tprivate async executeArgs(args: string[], showCommandName: boolean): Promise<number> {\n\t\tlet entry: CommandCatalogEntry | undefined\n\t\tlet command: ReturnType<CommandFactory> | undefined\n\t\t// the mode has to be known before anything can fail, so that every error is reported in the requested format\n\t\tthis.output.applyGlobalOptions(readGlobalOptionsFromArgs(args))\n\t\ttry {\n\t\t\tconst resolution = this.commandManager.resolve(args)\n\t\t\tif (resolution.type === 'group') {\n\t\t\t\tconst groupHelp = resolution.args.length === 1 && (resolution.args[0] === '--help' || resolution.args[0] === '-h')\n\t\t\t\tif (resolution.args.length > 0 && !groupHelp) {\n\t\t\t\t\tthrow new InvalidInputError(`Unexpected input after command group \"${resolution.name}\": ${resolution.args.join(' ')}`)\n\t\t\t\t}\n\t\t\t\tthis.printGroupHelp(resolution.name, resolution.entries)\n\t\t\t\treturn ExitCode.Success\n\t\t\t}\n\t\t\tentry = resolution.entry\n\t\t\tconst commandArgs = resolution.args\n\t\t\tcommand = entry.create()\n\n\t\t\tif (hasHelpFlag(commandArgs)) {\n\t\t\t\tthis.printCommandHelp(entry.name, command, showCommandName)\n\t\t\t\treturn ExitCode.Success\n\t\t\t}\n\n\t\t\tif (command.run !== Command.prototype.run) {\n\t\t\t\tawait this.options.beforeRun?.({ command, args: commandArgs, name: entry.name })\n\t\t\t\treturn await command.run(commandArgs, this.output)\n\t\t\t}\n\n\t\t\tconst parsed = command.parse(commandArgs)\n\t\t\tthis.output.applyGlobalOptions(parsed.globals)\n\n\t\t\tawait this.options.beforeRun?.({ command, args: commandArgs, name: entry.name })\n\n\t\t\treturn await command.runParsed(parsed, this.output)\n\t\t} catch (e) {\n\t\t\tconst exitCode = renderCliError(e, this.output)\n\t\t\tif (e instanceof InvalidInputError && command !== undefined && this.output.mode === 'human') {\n\t\t\t\tconst usage = command.getConfiguration().getUsage({ format: 'line' })\n\t\t\t\tthis.output.writeStderr(`${showCommandName && entry ? style('greenBright', entry.name) + ' ' : ''}${style('green', usage)}`)\n\t\t\t}\n\t\t\treturn exitCode\n\t\t}\n\t}\n\n\tprivate printApplicationHelp(verbose: boolean): void {\n\t\tthis.output.writeStderr(this.applicationDescription)\n\t\tthis.output.writeStderr(`Usage: <command> <command args>`)\n\t\tconst commands = this.commandManager.getCommands()\n\t\tif (commands.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst maxCommandNameLength = Math.max(...commands.map(it => it.name.length))\n\t\tconst indent = ' '\n\t\tfor (const entry of commands) {\n\t\t\tconst configuration = entry.create().getConfiguration()\n\t\t\tthis.output.writeStderr(`${indent}${style('greenBright', entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`)\n\t\t\tif (verbose) {\n\t\t\t\tconst helpIndent = `${indent}${' '.repeat(maxCommandNameLength)}${indent}`\n\t\t\t\tconst usage = configuration.getUsage({ format: 'multiline', indent: helpIndent })\n\t\t\t\tthis.output.writeStderr(usage ? style('green', usage) : `${helpIndent}${style('gray', 'No options')}`)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate printGroupHelp(name: string, entries: readonly CommandCatalogEntry[]): void {\n\t\tthis.output.writeStderr(`Usage: ${name} <command> <command args>`)\n\t\tconst maxCommandNameLength = Math.max(...entries.map(it => it.name.length))\n\t\tconst indent = ' '\n\t\tfor (const entry of [...entries].sort((a, b) => a.name.localeCompare(b.name))) {\n\t\t\tconst configuration = entry.create().getConfiguration()\n\t\t\tthis.output.writeStderr(`${indent}${style('greenBright', entry.name.padEnd(maxCommandNameLength))}${indent}${configuration.getDescription()}`)\n\t\t}\n\t}\n\n\tprivate printCommandHelp(name: string, command: ReturnType<CommandFactory>, showCommandName: boolean): void {\n\t\tif (showCommandName) {\n\t\t\tthis.output.writeStderr(style('greenBright', name))\n\t\t}\n\t\tconst configuration = command.getConfiguration()\n\t\tconst commandDescription = configuration.getDescription()\n\t\tif (commandDescription) {\n\t\t\tthis.output.writeStderr(commandDescription)\n\t\t}\n\t\tconst shortUsage = configuration.getUsage({ format: 'short' })\n\t\tif (shortUsage) {\n\t\t\tthis.output.writeStderr('\\nUsage:')\n\t\t\tthis.output.writeStderr(style('green', shortUsage))\n\t\t\tthis.output.writeStderr('\\nArguments and options:')\n\t\t\tthis.output.writeStderr(configuration.getUsage({ format: 'multiline' }))\n\t\t}\n\t\tthis.output.writeStderr('\\nGlobal options:')\n\t\tthis.output.writeStderr(UsageFormatter.format([], [...globalOptions], { format: 'multiline' }))\n\t}\n}\n\ninterface ApplicationOptions {\n\tbeforeRun?: (args: { command: ReturnType<CommandFactory>; name: string; args: string[] }) => void | Promise<void>\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAWO,MAAM,YAAY;AAAA,EAQxB,YACC,gBACA,wBACA,kBAA+C,CAAA,GAC/C,UAA8B,IAC7B;AAZF,kBAAA,MAAiB,gBAAA;AACjB,kBAAA,MAAiB,wBAAA;AACjB,kBAAA,MAAiB,QAAA;AACjB,kBAAA,MAAiB,SAAA;AAUhB,SAAK,iBAAiB;AACtB,SAAK,yBAAyB;AAC9B,SAAK,SAAS,2BAA2B,SAAS,kBAAkB,IAAI,OAAA;AACxE,SAAK,UAAU,2BAA2B,SAAS,UAAU;AAAA,EAC9D;AAAA,EAEA,MAAM,IAAI,MAA+B;AACxC,QAAI,KAAK,WAAW,KAAK,0BAA0B,KAAK,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM;AAC1E,kBAAY,MAAM,KAAK,QAAQ,IAAI,CAAC;AACpC;AAAA,IACD;AACA,UAAM,CAAC,MAAM,GAAG,WAAW,IAAI;AAC/B,UAAM,KAAK,mBAAmB,MAAM,aAAa,IAAI;AAAA,EACtD;AAAA,EAEA,MAAa,WAAW,MAAc,MAA+B;AACpE,UAAM,KAAK,mBAAmB,MAAM,MAAM,KAAK;AAAA,EAChD;AAAA,EAEA,MAAa,mBAAmB,MAAc,MAAgB,iBAAyC;AACtG,gBAAY,MAAM,KAAK,YAAY,CAAC,MAAM,GAAG,IAAI,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,OAAO,CAAA,GAAI,CAAC,GAAG,aAAa,GAAG,EAAE,QAAQ,YAAA,CAAa,CAAC;AAAA,EAC/F;AACD;"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const chalk = require("chalk");
3
+ const colors = require("./colors.cjs");
4
4
  const CliError = require("./CliError.cjs");
5
5
  const Output = require("./Output.cjs");
6
6
  const renderCliError = (error, output) => {
@@ -9,9 +9,9 @@ const renderCliError = (error, output) => {
9
9
  output.writeStderr(serializeError(cliError, CliError.isUnexpectedCliError(cliError)));
10
10
  return cliError.exitCode;
11
11
  }
12
- output.writeStderr(chalk.red(`Error [${Output.escapeTerminalText(cliError.code)}]: ${Output.escapeTerminalText(cliError.message)}`));
12
+ output.writeStderr(colors.style("red", `Error [${Output.escapeTerminalText(cliError.code)}]: ${Output.escapeTerminalText(cliError.message)}`));
13
13
  if (cliError.exitCode === CliError.ExitCode.InternalError && typeof cliError.details === "string") {
14
- output.writeStderr(chalk.gray(Output.escapeTerminalText(cliError.details)));
14
+ output.writeStderr(colors.style("gray", Output.escapeTerminalText(cliError.details)));
15
15
  }
16
16
  return cliError.exitCode;
17
17
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorRenderer.cjs","sources":["../../../../../packages/cli-common/src/application/ErrorRenderer.ts"],"sourcesContent":["import chalk from 'chalk'\nimport { ExitCode, isUnexpectedCliError, toCliError } from './CliError.js'\nimport { escapeTerminalText, Output } from './Output.js'\n\n/**\n * The single place where an error becomes user visible. Always writes to stderr — in json mode as the\n * `{ ok: false, error }` envelope, otherwise as a colored one-liner. Returns the process exit code.\n */\nexport const renderCliError = (error: unknown, output: Output): ExitCode => {\n\tconst cliError = toCliError(error)\n\tif (output.isJson) {\n\t\toutput.writeStderr(serializeError(cliError, isUnexpectedCliError(cliError)))\n\t\treturn cliError.exitCode\n\t}\n\toutput.writeStderr(chalk.red(`Error [${escapeTerminalText(cliError.code)}]: ${escapeTerminalText(cliError.message)}`))\n\tif (cliError.exitCode === ExitCode.InternalError && typeof cliError.details === 'string') {\n\t\toutput.writeStderr(chalk.gray(escapeTerminalText(cliError.details)))\n\t}\n\treturn cliError.exitCode\n}\n\nconst serializeError = (error: ReturnType<typeof toCliError>, unexpected: boolean): string => {\n\ttry {\n\t\treturn JSON.stringify(\n\t\t\t{\n\t\t\t\tok: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: error.code,\n\t\t\t\t\tmessage: unexpected ? 'An unexpected error occurred.' : error.message,\n\t\t\t\t\tretryable: error.retryable,\n\t\t\t\t\tdetails: unexpected ? null : error.details ?? null,\n\t\t\t\t},\n\t\t\t},\n\t\t\tnull,\n\t\t\t2,\n\t\t)\n\t} catch {\n\t\treturn '{\"ok\":false,\"error\":{\"code\":\"UNKNOWN\",\"message\":\"Unable to serialize error\",\"retryable\":false,\"details\":null}}'\n\t}\n}\n"],"names":["toCliError","isUnexpectedCliError","escapeTerminalText","ExitCode"],"mappings":";;;;;AAQO,MAAM,iBAAiB,CAAC,OAAgB,WAA6B;AAC3E,QAAM,WAAWA,SAAAA,WAAW,KAAK;AACjC,MAAI,OAAO,QAAQ;AAClB,WAAO,YAAY,eAAe,UAAUC,SAAAA,qBAAqB,QAAQ,CAAC,CAAC;AAC3E,WAAO,SAAS;AAAA,EACjB;AACA,SAAO,YAAY,MAAM,IAAI,UAAUC,OAAAA,mBAAmB,SAAS,IAAI,CAAC,MAAMA,OAAAA,mBAAmB,SAAS,OAAO,CAAC,EAAE,CAAC;AACrH,MAAI,SAAS,aAAaC,SAAAA,SAAS,iBAAiB,OAAO,SAAS,YAAY,UAAU;AACzF,WAAO,YAAY,MAAM,KAAKD,OAAAA,mBAAmB,SAAS,OAAO,CAAC,CAAC;AAAA,EACpE;AACA,SAAO,SAAS;AACjB;AAEA,MAAM,iBAAiB,CAAC,OAAsC,eAAgC;AAC7F,MAAI;AACH,WAAO,KAAK;AAAA,MACX;AAAA,QACC,IAAI;AAAA,QACJ,OAAO;AAAA,UACN,MAAM,MAAM;AAAA,UACZ,SAAS,aAAa,kCAAkC,MAAM;AAAA,UAC9D,WAAW,MAAM;AAAA,UACjB,SAAS,aAAa,OAAO,MAAM,WAAW;AAAA,QAAA;AAAA,MAC/C;AAAA,MAED;AAAA,MACA;AAAA,IAAA;AAAA,EAEF,QAAQ;AACP,WAAO;AAAA,EACR;AACD;;"}
1
+ {"version":3,"file":"ErrorRenderer.cjs","sources":["../../../../../packages/cli-common/src/application/ErrorRenderer.ts"],"sourcesContent":["import { style } from './colors.js'\nimport { ExitCode, isUnexpectedCliError, toCliError } from './CliError.js'\nimport { escapeTerminalText, Output } from './Output.js'\n\n/**\n * The single place where an error becomes user visible. Always writes to stderr — in json mode as the\n * `{ ok: false, error }` envelope, otherwise as a colored one-liner. Returns the process exit code.\n */\nexport const renderCliError = (error: unknown, output: Output): ExitCode => {\n\tconst cliError = toCliError(error)\n\tif (output.isJson) {\n\t\toutput.writeStderr(serializeError(cliError, isUnexpectedCliError(cliError)))\n\t\treturn cliError.exitCode\n\t}\n\toutput.writeStderr(style('red', `Error [${escapeTerminalText(cliError.code)}]: ${escapeTerminalText(cliError.message)}`))\n\tif (cliError.exitCode === ExitCode.InternalError && typeof cliError.details === 'string') {\n\t\toutput.writeStderr(style('gray', escapeTerminalText(cliError.details)))\n\t}\n\treturn cliError.exitCode\n}\n\nconst serializeError = (error: ReturnType<typeof toCliError>, unexpected: boolean): string => {\n\ttry {\n\t\treturn JSON.stringify(\n\t\t\t{\n\t\t\t\tok: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: error.code,\n\t\t\t\t\tmessage: unexpected ? 'An unexpected error occurred.' : error.message,\n\t\t\t\t\tretryable: error.retryable,\n\t\t\t\t\tdetails: unexpected ? null : error.details ?? null,\n\t\t\t\t},\n\t\t\t},\n\t\t\tnull,\n\t\t\t2,\n\t\t)\n\t} catch {\n\t\treturn '{\"ok\":false,\"error\":{\"code\":\"UNKNOWN\",\"message\":\"Unable to serialize error\",\"retryable\":false,\"details\":null}}'\n\t}\n}\n"],"names":["toCliError","isUnexpectedCliError","style","escapeTerminalText","ExitCode"],"mappings":";;;;;AAQO,MAAM,iBAAiB,CAAC,OAAgB,WAA6B;AAC3E,QAAM,WAAWA,SAAAA,WAAW,KAAK;AACjC,MAAI,OAAO,QAAQ;AAClB,WAAO,YAAY,eAAe,UAAUC,SAAAA,qBAAqB,QAAQ,CAAC,CAAC;AAC3E,WAAO,SAAS;AAAA,EACjB;AACA,SAAO,YAAYC,OAAAA,MAAM,OAAO,UAAUC,OAAAA,mBAAmB,SAAS,IAAI,CAAC,MAAMA,OAAAA,mBAAmB,SAAS,OAAO,CAAC,EAAE,CAAC;AACxH,MAAI,SAAS,aAAaC,SAAAA,SAAS,iBAAiB,OAAO,SAAS,YAAY,UAAU;AACzF,WAAO,YAAYF,aAAM,QAAQC,OAAAA,mBAAmB,SAAS,OAAO,CAAC,CAAC;AAAA,EACvE;AACA,SAAO,SAAS;AACjB;AAEA,MAAM,iBAAiB,CAAC,OAAsC,eAAgC;AAC7F,MAAI;AACH,WAAO,KAAK;AAAA,MACX;AAAA,QACC,IAAI;AAAA,QACJ,OAAO;AAAA,UACN,MAAM,MAAM;AAAA,UACZ,SAAS,aAAa,kCAAkC,MAAM;AAAA,UAC9D,WAAW,MAAM;AAAA,UACjB,SAAS,aAAa,OAAO,MAAM,WAAW;AAAA,QAAA;AAAA,MAC/C;AAAA,MAED;AAAA,MACA;AAAA,IAAA;AAAA,EAEF,QAAQ;AACP,WAAO;AAAA,EACR;AACD;;"}
@@ -1,4 +1,4 @@
1
- import chalk from "chalk";
1
+ import { style } from "./colors.js";
2
2
  import { toCliError, isUnexpectedCliError, ExitCode } from "./CliError.js";
3
3
  import { escapeTerminalText } from "./Output.js";
4
4
  const renderCliError = (error, output) => {
@@ -7,9 +7,9 @@ const renderCliError = (error, output) => {
7
7
  output.writeStderr(serializeError(cliError, isUnexpectedCliError(cliError)));
8
8
  return cliError.exitCode;
9
9
  }
10
- output.writeStderr(chalk.red(`Error [${escapeTerminalText(cliError.code)}]: ${escapeTerminalText(cliError.message)}`));
10
+ output.writeStderr(style("red", `Error [${escapeTerminalText(cliError.code)}]: ${escapeTerminalText(cliError.message)}`));
11
11
  if (cliError.exitCode === ExitCode.InternalError && typeof cliError.details === "string") {
12
- output.writeStderr(chalk.gray(escapeTerminalText(cliError.details)));
12
+ output.writeStderr(style("gray", escapeTerminalText(cliError.details)));
13
13
  }
14
14
  return cliError.exitCode;
15
15
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorRenderer.js","sources":["../../../../../packages/cli-common/src/application/ErrorRenderer.ts"],"sourcesContent":["import chalk from 'chalk'\nimport { ExitCode, isUnexpectedCliError, toCliError } from './CliError.js'\nimport { escapeTerminalText, Output } from './Output.js'\n\n/**\n * The single place where an error becomes user visible. Always writes to stderr — in json mode as the\n * `{ ok: false, error }` envelope, otherwise as a colored one-liner. Returns the process exit code.\n */\nexport const renderCliError = (error: unknown, output: Output): ExitCode => {\n\tconst cliError = toCliError(error)\n\tif (output.isJson) {\n\t\toutput.writeStderr(serializeError(cliError, isUnexpectedCliError(cliError)))\n\t\treturn cliError.exitCode\n\t}\n\toutput.writeStderr(chalk.red(`Error [${escapeTerminalText(cliError.code)}]: ${escapeTerminalText(cliError.message)}`))\n\tif (cliError.exitCode === ExitCode.InternalError && typeof cliError.details === 'string') {\n\t\toutput.writeStderr(chalk.gray(escapeTerminalText(cliError.details)))\n\t}\n\treturn cliError.exitCode\n}\n\nconst serializeError = (error: ReturnType<typeof toCliError>, unexpected: boolean): string => {\n\ttry {\n\t\treturn JSON.stringify(\n\t\t\t{\n\t\t\t\tok: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: error.code,\n\t\t\t\t\tmessage: unexpected ? 'An unexpected error occurred.' : error.message,\n\t\t\t\t\tretryable: error.retryable,\n\t\t\t\t\tdetails: unexpected ? null : error.details ?? null,\n\t\t\t\t},\n\t\t\t},\n\t\t\tnull,\n\t\t\t2,\n\t\t)\n\t} catch {\n\t\treturn '{\"ok\":false,\"error\":{\"code\":\"UNKNOWN\",\"message\":\"Unable to serialize error\",\"retryable\":false,\"details\":null}}'\n\t}\n}\n"],"names":[],"mappings":";;;AAQO,MAAM,iBAAiB,CAAC,OAAgB,WAA6B;AAC3E,QAAM,WAAW,WAAW,KAAK;AACjC,MAAI,OAAO,QAAQ;AAClB,WAAO,YAAY,eAAe,UAAU,qBAAqB,QAAQ,CAAC,CAAC;AAC3E,WAAO,SAAS;AAAA,EACjB;AACA,SAAO,YAAY,MAAM,IAAI,UAAU,mBAAmB,SAAS,IAAI,CAAC,MAAM,mBAAmB,SAAS,OAAO,CAAC,EAAE,CAAC;AACrH,MAAI,SAAS,aAAa,SAAS,iBAAiB,OAAO,SAAS,YAAY,UAAU;AACzF,WAAO,YAAY,MAAM,KAAK,mBAAmB,SAAS,OAAO,CAAC,CAAC;AAAA,EACpE;AACA,SAAO,SAAS;AACjB;AAEA,MAAM,iBAAiB,CAAC,OAAsC,eAAgC;AAC7F,MAAI;AACH,WAAO,KAAK;AAAA,MACX;AAAA,QACC,IAAI;AAAA,QACJ,OAAO;AAAA,UACN,MAAM,MAAM;AAAA,UACZ,SAAS,aAAa,kCAAkC,MAAM;AAAA,UAC9D,WAAW,MAAM;AAAA,UACjB,SAAS,aAAa,OAAO,MAAM,WAAW;AAAA,QAAA;AAAA,MAC/C;AAAA,MAED;AAAA,MACA;AAAA,IAAA;AAAA,EAEF,QAAQ;AACP,WAAO;AAAA,EACR;AACD;"}
1
+ {"version":3,"file":"ErrorRenderer.js","sources":["../../../../../packages/cli-common/src/application/ErrorRenderer.ts"],"sourcesContent":["import { style } from './colors.js'\nimport { ExitCode, isUnexpectedCliError, toCliError } from './CliError.js'\nimport { escapeTerminalText, Output } from './Output.js'\n\n/**\n * The single place where an error becomes user visible. Always writes to stderr — in json mode as the\n * `{ ok: false, error }` envelope, otherwise as a colored one-liner. Returns the process exit code.\n */\nexport const renderCliError = (error: unknown, output: Output): ExitCode => {\n\tconst cliError = toCliError(error)\n\tif (output.isJson) {\n\t\toutput.writeStderr(serializeError(cliError, isUnexpectedCliError(cliError)))\n\t\treturn cliError.exitCode\n\t}\n\toutput.writeStderr(style('red', `Error [${escapeTerminalText(cliError.code)}]: ${escapeTerminalText(cliError.message)}`))\n\tif (cliError.exitCode === ExitCode.InternalError && typeof cliError.details === 'string') {\n\t\toutput.writeStderr(style('gray', escapeTerminalText(cliError.details)))\n\t}\n\treturn cliError.exitCode\n}\n\nconst serializeError = (error: ReturnType<typeof toCliError>, unexpected: boolean): string => {\n\ttry {\n\t\treturn JSON.stringify(\n\t\t\t{\n\t\t\t\tok: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: error.code,\n\t\t\t\t\tmessage: unexpected ? 'An unexpected error occurred.' : error.message,\n\t\t\t\t\tretryable: error.retryable,\n\t\t\t\t\tdetails: unexpected ? null : error.details ?? null,\n\t\t\t\t},\n\t\t\t},\n\t\t\tnull,\n\t\t\t2,\n\t\t)\n\t} catch {\n\t\treturn '{\"ok\":false,\"error\":{\"code\":\"UNKNOWN\",\"message\":\"Unable to serialize error\",\"retryable\":false,\"details\":null}}'\n\t}\n}\n"],"names":[],"mappings":";;;AAQO,MAAM,iBAAiB,CAAC,OAAgB,WAA6B;AAC3E,QAAM,WAAW,WAAW,KAAK;AACjC,MAAI,OAAO,QAAQ;AAClB,WAAO,YAAY,eAAe,UAAU,qBAAqB,QAAQ,CAAC,CAAC;AAC3E,WAAO,SAAS;AAAA,EACjB;AACA,SAAO,YAAY,MAAM,OAAO,UAAU,mBAAmB,SAAS,IAAI,CAAC,MAAM,mBAAmB,SAAS,OAAO,CAAC,EAAE,CAAC;AACxH,MAAI,SAAS,aAAa,SAAS,iBAAiB,OAAO,SAAS,YAAY,UAAU;AACzF,WAAO,YAAY,MAAM,QAAQ,mBAAmB,SAAS,OAAO,CAAC,CAAC;AAAA,EACvE;AACA,SAAO,SAAS;AACjB;AAEA,MAAM,iBAAiB,CAAC,OAAsC,eAAgC;AAC7F,MAAI;AACH,WAAO,KAAK;AAAA,MACX;AAAA,QACC,IAAI;AAAA,QACJ,OAAO;AAAA,UACN,MAAM,MAAM;AAAA,UACZ,SAAS,aAAa,kCAAkC,MAAM;AAAA,UAC9D,WAAW,MAAM;AAAA,UACjB,SAAS,aAAa,OAAO,MAAM,WAAW;AAAA,QAAA;AAAA,MAC/C;AAAA,MAED;AAAA,MACA;AAAA,IAAA;AAAA,EAEF,QAAQ;AACP,WAAO;AAAA,EACR;AACD;"}
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const chalk = require("chalk");
4
- const chalkTable = require("chalk-table");
5
- const node_stream = require("node:stream");
3
+ const node_readline = require("node:readline");
4
+ const CliError = require("./CliError.cjs");
5
+ const colors = require("./colors.cjs");
6
+ const table = require("./table.cjs");
6
7
  var __defProp = Object.defineProperty;
7
8
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
9
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
- let supportedChalkLevel = chalk.level;
10
10
  const resolveOutputMode = (globals) => {
11
11
  if (globals.json) {
12
12
  return "json";
@@ -23,11 +23,11 @@ class Output {
23
23
  __publicField(this, "stdout");
24
24
  __publicField(this, "stderr");
25
25
  __publicField(this, "stdinIsTty");
26
- __publicField(this, "promptStderr");
26
+ __publicField(this, "readPromptLine");
27
27
  this.stdout = options.stdout ?? createProcessStream(process.stdout);
28
28
  this.stderr = options.stderr ?? createProcessStream(process.stderr);
29
29
  this.stdinIsTty = options.isStdinTty ?? (() => process.stdin.isTTY === true);
30
- this.promptStderr = options.stderr === void 0 ? process.stderr : createPromptStream(this.stderr);
30
+ this.readPromptLine = options.readPromptLine ?? readStdinLine;
31
31
  this.stdout.onError?.(handleStreamError);
32
32
  this.stderr.onError?.(handleStreamError);
33
33
  }
@@ -46,18 +46,7 @@ class Output {
46
46
  }
47
47
  applyGlobalOptions(globals) {
48
48
  this.setMode(resolveOutputMode(globals));
49
- if (globals.color && this.currentMode === "human") {
50
- if (chalk.level === 0) {
51
- chalk.level = supportedChalkLevel;
52
- } else {
53
- supportedChalkLevel = chalk.level;
54
- }
55
- } else {
56
- if (chalk.level !== 0) {
57
- supportedChalkLevel = chalk.level;
58
- }
59
- chalk.level = 0;
60
- }
49
+ colors.setColorsEnabled(globals.color && this.currentMode === "human" && colors.terminalSupportsColor);
61
50
  }
62
51
  data(value, rendering) {
63
52
  const human = typeof rendering === "function" ? rendering : rendering?.human;
@@ -99,17 +88,17 @@ class Output {
99
88
  }
100
89
  return cells;
101
90
  });
102
- this.writeStdout(chalkTable({ columns: columns.map((it) => ({ field: it.field, name: it.name })) }, data));
91
+ this.writeStdout(table.formatTable(columns.map((it) => ({ field: it.field, name: it.name })), data));
103
92
  }
104
93
  // DIAGNOSTICS → stderr
105
94
  info(message) {
106
95
  this.writeDiagnostic(message);
107
96
  }
108
97
  warn(message) {
109
- this.writeDiagnostic(message, (text) => chalk.yellow(text));
98
+ this.writeDiagnostic(message, (text) => colors.style("yellow", text));
110
99
  }
111
100
  error(message) {
112
- this.writeDiagnostic(message, (text) => chalk.red(text));
101
+ this.writeDiagnostic(message, (text) => colors.style("red", text));
113
102
  }
114
103
  // PROGRESS → stderr
115
104
  progress(message) {
@@ -131,9 +120,14 @@ class Output {
131
120
  canPrompt() {
132
121
  return this.currentMode === "human" && this.stdinIsTty() && this.stderr.isTty;
133
122
  }
134
- /** A real Writable suitable for the `stdout` option of interactive prompt libraries. */
135
- get promptOutput() {
136
- return this.promptStderr;
123
+ /** Writes `question` to stderr and reads one answer line. */
124
+ prompt(question) {
125
+ if (!this.canPrompt()) {
126
+ throw new CliError.CliError("TTY not available. Pass --yes to confirm.", { code: "TTY_UNAVAILABLE", exitCode: CliError.ExitCode.InputError });
127
+ }
128
+ this.clearProgress();
129
+ writeStream(this.stderr, question);
130
+ return this.readPromptLine();
137
131
  }
138
132
  /**
139
133
  * Writes a line to stderr regardless of the mode. Reserved for content the user explicitly asked for
@@ -169,26 +163,64 @@ const createProcessStream = (stream) => ({
169
163
  stream.on("error", (error) => listener(error));
170
164
  }
171
165
  });
172
- class PromptWritable extends node_stream.Writable {
173
- constructor(stream) {
174
- super({ decodeStrings: false });
175
- this.stream = stream;
176
- __publicField(this, "isTTY");
177
- this.isTTY = stream.isTty;
166
+ let stdinReader;
167
+ const readStdinLine = () => {
168
+ stdinReader ?? (stdinReader = new LineReader(process.stdin));
169
+ return stdinReader.read();
170
+ };
171
+ class LineReader {
172
+ constructor(input) {
173
+ this.input = input;
174
+ __publicField(this, "reader");
175
+ __publicField(this, "lines", []);
176
+ __publicField(this, "waiting");
177
+ __publicField(this, "closed", false);
178
178
  }
179
- get columns() {
180
- return this.stream.columns ?? 80;
179
+ read() {
180
+ if (this.waiting) {
181
+ throw new Error("LineReader: a read is already pending");
182
+ }
183
+ const line = this.lines.shift();
184
+ if (line !== void 0) {
185
+ return Promise.resolve(line);
186
+ }
187
+ if (this.closed || this.input.readableEnded) {
188
+ this.closed = true;
189
+ return Promise.resolve(void 0);
190
+ }
191
+ return new Promise((resolve) => {
192
+ this.waiting = resolve;
193
+ this.open().resume();
194
+ });
195
+ }
196
+ open() {
197
+ if (this.reader) {
198
+ return this.reader;
199
+ }
200
+ const reader = node_readline.createInterface({ input: this.input, terminal: false });
201
+ reader.on("line", (line) => this.settle(line));
202
+ reader.on("close", () => {
203
+ this.closed = true;
204
+ this.settle(void 0);
205
+ });
206
+ this.reader = reader;
207
+ return reader;
181
208
  }
182
- _write(chunk, encoding, callback) {
183
- try {
184
- writeStream(this.stream, typeof chunk === "string" ? chunk : Buffer.from(chunk).toString(encoding));
185
- callback();
186
- } catch (error) {
187
- callback(error instanceof Error ? error : new Error(String(error)));
209
+ settle(line) {
210
+ const waiting = this.waiting;
211
+ if (!waiting) {
212
+ if (line !== void 0) {
213
+ this.lines.push(line);
214
+ }
215
+ return;
216
+ }
217
+ this.waiting = void 0;
218
+ if (!this.closed) {
219
+ this.reader?.pause();
188
220
  }
221
+ waiting(line);
189
222
  }
190
223
  }
191
- const createPromptStream = (stream) => new PromptWritable(stream);
192
224
  const writeStream = (stream, text) => {
193
225
  try {
194
226
  stream.write(text);
@@ -236,6 +268,7 @@ const toScalarLines = (value) => {
236
268
  return values.filter((it) => it !== void 0 && it !== null).map(formatCell);
237
269
  };
238
270
  const isOutputScalar = (value) => value === null || value === void 0 || ["string", "number", "boolean", "bigint"].includes(typeof value);
271
+ exports.LineReader = LineReader;
239
272
  exports.Output = Output;
240
273
  exports.escapeTerminalText = escapeTerminalText;
241
274
  exports.resolveOutputMode = resolveOutputMode;