@oclif/core 3.23.1 → 3.25.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.
package/lib/cache.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Config } from './config/config';
1
2
  import { PJSON, Plugin } from './interfaces';
2
3
  type OclifCoreInfo = {
3
4
  name: string;
@@ -5,6 +6,7 @@ type OclifCoreInfo = {
5
6
  };
6
7
  type CacheContents = {
7
8
  rootPlugin: Plugin;
9
+ config: Config;
8
10
  exitCodes: PJSON.Plugin['oclif']['exitCodes'];
9
11
  '@oclif/core': OclifCoreInfo;
10
12
  };
@@ -16,6 +18,7 @@ export default class Cache extends Map<keyof CacheContents, ValueOf<CacheContent
16
18
  static instance: Cache;
17
19
  constructor();
18
20
  static getInstance(): Cache;
21
+ get(key: 'config'): Config | undefined;
19
22
  get(key: '@oclif/core'): OclifCoreInfo;
20
23
  get(key: 'rootPlugin'): Plugin | undefined;
21
24
  get(key: 'exitCodes'): PJSON.Plugin['oclif']['exitCodes'] | undefined;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.tsPath = exports.TS_CONFIGS = void 0;
7
7
  const node_path_1 = require("node:path");
8
8
  const cache_1 = __importDefault(require("../cache"));
9
- const errors_1 = require("../errors");
9
+ const warn_1 = require("../errors/warn");
10
10
  const settings_1 = require("../settings");
11
11
  const fs_1 = require("../util/fs");
12
12
  const read_tsconfig_1 = require("../util/read-tsconfig");
@@ -75,7 +75,7 @@ async function loadTSConfig(root) {
75
75
  if (isErrno(error))
76
76
  return;
77
77
  debug(`Could not parse tsconfig.json. Skipping typescript path lookup for ${root}.`);
78
- (0, errors_1.memoizedWarn)(`Could not parse tsconfig.json for ${root}. Falling back to compiled source.`);
78
+ (0, warn_1.memoizedWarn)(`Could not parse tsconfig.json for ${root}. Falling back to compiled source.`);
79
79
  }
80
80
  }
81
81
  async function registerTSNode(root, tsconfig) {
@@ -90,7 +90,7 @@ async function registerTSNode(root, tsconfig) {
90
90
  }
91
91
  catch {
92
92
  debug(`Could not find ts-node at ${tsNodePath}. Skipping ts-node registration for ${root}.`);
93
- (0, errors_1.memoizedWarn)(`Could not find ts-node at ${tsNodePath}. Please ensure that ts-node is a devDependency. Falling back to compiled source.`);
93
+ (0, warn_1.memoizedWarn)(`Could not find ts-node at ${tsNodePath}. Please ensure that ts-node is a devDependency. Falling back to compiled source.`);
94
94
  return;
95
95
  }
96
96
  const typeRoots = [(0, node_path_1.join)(root, 'node_modules', '@types')];
@@ -207,7 +207,7 @@ async function determinePath(root, orig) {
207
207
  }
208
208
  debug(`No source file found. Returning default path ${orig}`);
209
209
  if (!(0, util_1.isProd)())
210
- (0, errors_1.memoizedWarn)(`Could not find source for ${orig} based on tsconfig. Defaulting to compiled source.`);
210
+ (0, warn_1.memoizedWarn)(`Could not find source for ${orig} based on tsconfig. Defaulting to compiled source.`);
211
211
  return orig;
212
212
  }
213
213
  async function tsPath(root, orig, plugin) {
@@ -230,12 +230,12 @@ async function tsPath(root, orig, plugin) {
230
230
  if (cannotTranspileEsm(rootPlugin, plugin, isProduction)) {
231
231
  debug(`Skipping typescript path lookup for ${root} because it's an ESM module (NODE_ENV: ${process.env.NODE_ENV}, root plugin module type: ${rootPlugin?.moduleType})`);
232
232
  if (plugin?.type === 'link')
233
- (0, errors_1.memoizedWarn)(`${plugin?.name} is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.`);
233
+ (0, warn_1.memoizedWarn)(`${plugin?.name} is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.`);
234
234
  return orig;
235
235
  }
236
236
  if (cannotUseTsNode(root, plugin, isProduction)) {
237
237
  debug(`Skipping typescript path lookup for ${root} because ts-node is run in node version ${process.version}"`);
238
- (0, errors_1.memoizedWarn)(`ts-node executable cannot transpile ESM in Node 20. Existing compiled source will be used instead. See https://github.com/oclif/core/issues/817.`);
238
+ (0, warn_1.memoizedWarn)(`ts-node executable cannot transpile ESM in Node 20. Existing compiled source will be used instead. See https://github.com/oclif/core/issues/817.`);
239
239
  return orig;
240
240
  }
241
241
  try {
@@ -0,0 +1,8 @@
1
+ import { PrettyPrintableError } from '../interfaces';
2
+ export declare function error(input: Error | string, options: {
3
+ exit: false;
4
+ } & PrettyPrintableError): void;
5
+ export declare function error(input: Error | string, options?: {
6
+ exit?: number;
7
+ } & PrettyPrintableError): never;
8
+ export default error;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.error = void 0;
30
+ const write_1 = __importDefault(require("../cli-ux/write"));
31
+ const config_1 = require("./config");
32
+ const cli_1 = require("./errors/cli");
33
+ const pretty_print_1 = __importStar(require("./errors/pretty-print"));
34
+ function error(input, options = {}) {
35
+ let err;
36
+ if (typeof input === 'string') {
37
+ err = new cli_1.CLIError(input, options);
38
+ }
39
+ else if (input instanceof Error) {
40
+ err = (0, cli_1.addOclifExitCode)(input, options);
41
+ }
42
+ else {
43
+ throw new TypeError('first argument must be a string or instance of Error');
44
+ }
45
+ err = (0, pretty_print_1.applyPrettyPrintOptions)(err, options);
46
+ if (options.exit === false) {
47
+ const message = (0, pretty_print_1.default)(err);
48
+ if (message)
49
+ write_1.default.stderr(message + '\n');
50
+ if (config_1.config.errorLogger)
51
+ config_1.config.errorLogger.log(err?.stack ?? '');
52
+ }
53
+ else
54
+ throw err;
55
+ }
56
+ exports.error = error;
57
+ exports.default = error;
@@ -8,6 +8,7 @@ export declare function addOclifExitCode(error: Record<string, any>, options?: {
8
8
  export declare class CLIError extends Error implements OclifError {
9
9
  code?: string;
10
10
  oclif: OclifError['oclif'];
11
+ skipOclifErrorHandling?: boolean;
11
12
  suggestions?: string[];
12
13
  constructor(error: Error | string, options?: {
13
14
  exit?: false | number;
@@ -26,6 +26,7 @@ exports.addOclifExitCode = addOclifExitCode;
26
26
  class CLIError extends Error {
27
27
  code;
28
28
  oclif = {};
29
+ skipOclifErrorHandling;
29
30
  suggestions;
30
31
  constructor(error, options = {}) {
31
32
  super(error instanceof Error ? error.message : error);
@@ -1,4 +1,6 @@
1
1
  import { OclifError, PrettyPrintableError } from '../interfaces';
2
+ import { CLIParseError } from '../parser/errors';
3
+ import { CLIError } from './errors/cli';
2
4
  /**
3
5
  * This is an odd abstraction for process.exit, but it allows us to stub it in tests.
4
6
  *
@@ -7,8 +9,6 @@ import { OclifError, PrettyPrintableError } from '../interfaces';
7
9
  export declare const Exit: {
8
10
  exit(code?: number): never;
9
11
  };
10
- type ErrorToHandle = Error & Partial<PrettyPrintableError> & Partial<OclifError> & {
11
- skipOclifErrorHandling?: boolean;
12
- };
12
+ type ErrorToHandle = Error & Partial<PrettyPrintableError> & Partial<OclifError> & Partial<CLIError> & Partial<CLIParseError>;
13
13
  export declare function handle(err: ErrorToHandle): Promise<void>;
14
14
  export {};
@@ -5,6 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.handle = exports.Exit = void 0;
7
7
  const clean_stack_1 = __importDefault(require("clean-stack"));
8
+ const cache_1 = __importDefault(require("../cache"));
9
+ const index_1 = require("../help/index");
8
10
  const config_1 = require("./config");
9
11
  const cli_1 = require("./errors/cli");
10
12
  const exit_1 = require("./errors/exit");
@@ -31,6 +33,17 @@ async function handle(err) {
31
33
  const stack = (0, clean_stack_1.default)(err.stack || '', { pretty: true });
32
34
  if (shouldPrint) {
33
35
  console.error(pretty ?? stack);
36
+ const config = cache_1.default.getInstance().get('config');
37
+ if (err.showHelp && err.parse?.input?.argv && config) {
38
+ const options = {
39
+ ...(config.pjson.oclif.helpOptions ?? config.pjson.helpOptions),
40
+ sections: ['flags', 'usage', 'arguments'],
41
+ sendToStderr: true,
42
+ };
43
+ const help = new index_1.Help(config, options);
44
+ console.error();
45
+ await help.showHelp(process.argv.slice(2));
46
+ }
34
47
  }
35
48
  const exitCode = err.oclif?.exit ?? 1;
36
49
  if (config_1.config.errorLogger && err.code !== 'EEXIT') {
@@ -1,17 +1,10 @@
1
- import { PrettyPrintableError } from '../interfaces';
2
1
  export { PrettyPrintableError } from '../interfaces';
3
2
  export { config } from './config';
3
+ export { error } from './error';
4
4
  export { CLIError } from './errors/cli';
5
5
  export { ExitError } from './errors/exit';
6
6
  export { ModuleLoadError } from './errors/module-load';
7
7
  export { handle } from './handle';
8
- export declare function exit(code?: number): never;
9
- export declare function error(input: Error | string, options: {
10
- exit: false;
11
- } & PrettyPrintableError): void;
12
- export declare function error(input: Error | string, options?: {
13
- exit?: number;
14
- } & PrettyPrintableError): never;
15
- export declare function warn(input: Error | string): void;
16
- export declare function memoizedWarn(input: Error | string): void;
17
8
  export { Logger } from './logger';
9
+ export declare function exit(code?: number): never;
10
+ export { warn } from './warn';
@@ -1,98 +1,24 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
2
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Logger = exports.memoizedWarn = exports.warn = exports.error = exports.exit = exports.handle = exports.ModuleLoadError = exports.ExitError = exports.CLIError = exports.config = void 0;
30
- const write_1 = __importDefault(require("../cli-ux/write"));
31
- const config_1 = require("./config");
32
- const cli_1 = require("./errors/cli");
3
+ exports.warn = exports.exit = exports.Logger = exports.handle = exports.ModuleLoadError = exports.ExitError = exports.CLIError = exports.error = exports.config = void 0;
33
4
  const exit_1 = require("./errors/exit");
34
- const pretty_print_1 = __importStar(require("./errors/pretty-print"));
35
- var config_2 = require("./config");
36
- Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_2.config; } });
37
- var cli_2 = require("./errors/cli");
38
- Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return cli_2.CLIError; } });
5
+ var config_1 = require("./config");
6
+ Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
7
+ var error_1 = require("./error");
8
+ Object.defineProperty(exports, "error", { enumerable: true, get: function () { return error_1.error; } });
9
+ var cli_1 = require("./errors/cli");
10
+ Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return cli_1.CLIError; } });
39
11
  var exit_2 = require("./errors/exit");
40
12
  Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_2.ExitError; } });
41
13
  var module_load_1 = require("./errors/module-load");
42
14
  Object.defineProperty(exports, "ModuleLoadError", { enumerable: true, get: function () { return module_load_1.ModuleLoadError; } });
43
15
  var handle_1 = require("./handle");
44
16
  Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return handle_1.handle; } });
17
+ var logger_1 = require("./logger");
18
+ Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
45
19
  function exit(code = 0) {
46
20
  throw new exit_1.ExitError(code);
47
21
  }
48
22
  exports.exit = exit;
49
- function error(input, options = {}) {
50
- let err;
51
- if (typeof input === 'string') {
52
- err = new cli_1.CLIError(input, options);
53
- }
54
- else if (input instanceof Error) {
55
- err = (0, cli_1.addOclifExitCode)(input, options);
56
- }
57
- else {
58
- throw new TypeError('first argument must be a string or instance of Error');
59
- }
60
- err = (0, pretty_print_1.applyPrettyPrintOptions)(err, options);
61
- if (options.exit === false) {
62
- const message = (0, pretty_print_1.default)(err);
63
- if (message)
64
- write_1.default.stderr(message + '\n');
65
- if (config_1.config.errorLogger)
66
- config_1.config.errorLogger.log(err?.stack ?? '');
67
- }
68
- else
69
- throw err;
70
- }
71
- exports.error = error;
72
- function warn(input) {
73
- let err;
74
- if (typeof input === 'string') {
75
- err = new cli_1.CLIError.Warn(input);
76
- }
77
- else if (input instanceof Error) {
78
- err = (0, cli_1.addOclifExitCode)(input);
79
- }
80
- else {
81
- throw new TypeError('first argument must be a string or instance of Error');
82
- }
83
- const message = (0, pretty_print_1.default)(err);
84
- if (message)
85
- write_1.default.stderr(message + '\n');
86
- if (config_1.config.errorLogger)
87
- config_1.config.errorLogger.log(err?.stack ?? '');
88
- }
89
- exports.warn = warn;
90
- const WARNINGS = new Set();
91
- function memoizedWarn(input) {
92
- if (!WARNINGS.has(input))
93
- warn(input);
94
- WARNINGS.add(input);
95
- }
96
- exports.memoizedWarn = memoizedWarn;
97
- var logger_1 = require("./logger");
98
- Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
23
+ var warn_1 = require("./warn");
24
+ Object.defineProperty(exports, "warn", { enumerable: true, get: function () { return warn_1.warn; } });
@@ -0,0 +1,3 @@
1
+ export declare function warn(input: Error | string): void;
2
+ export declare function memoizedWarn(input: Error | string): void;
3
+ export default warn;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.memoizedWarn = exports.warn = void 0;
7
+ const write_1 = __importDefault(require("../cli-ux/write"));
8
+ const config_1 = require("./config");
9
+ const cli_1 = require("./errors/cli");
10
+ const pretty_print_1 = __importDefault(require("./errors/pretty-print"));
11
+ function warn(input) {
12
+ let err;
13
+ if (typeof input === 'string') {
14
+ err = new cli_1.CLIError.Warn(input);
15
+ }
16
+ else if (input instanceof Error) {
17
+ err = (0, cli_1.addOclifExitCode)(input);
18
+ }
19
+ else {
20
+ throw new TypeError('first argument must be a string or instance of Error');
21
+ }
22
+ const message = (0, pretty_print_1.default)(err);
23
+ if (message)
24
+ write_1.default.stderr(message + '\n');
25
+ if (config_1.config.errorLogger)
26
+ config_1.config.errorLogger.log(err?.stack ?? '');
27
+ }
28
+ exports.warn = warn;
29
+ const WARNINGS = new Set();
30
+ function memoizedWarn(input) {
31
+ if (!WARNINGS.has(input))
32
+ warn(input);
33
+ WARNINGS.add(input);
34
+ }
35
+ exports.memoizedWarn = memoizedWarn;
36
+ exports.default = warn;
@@ -58,7 +58,8 @@ class CommandHelp extends formatter_1.HelpFormatter {
58
58
  if (args.filter((a) => a.description).length === 0)
59
59
  return;
60
60
  return args.map((a) => {
61
- const name = a.name.toUpperCase();
61
+ // Add ellipsis to indicate that the argument takes multiple values if strict is false
62
+ const name = this.command.strict === false ? `${a.name.toUpperCase()}...` : a.name.toUpperCase();
62
63
  let description = a.description || '';
63
64
  if (a.default)
64
65
  description = `${(0, theme_1.colorize)(this.config?.theme?.flagDefaultValue, `[default: ${a.default}]`)} ${description}`;
@@ -246,7 +247,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
246
247
  return { flagGroups, mainFlags };
247
248
  }
248
249
  sections() {
249
- return [
250
+ const sections = [
250
251
  {
251
252
  generate: () => this.usage(),
252
253
  header: this.opts.usageHeader || 'USAGE',
@@ -291,6 +292,8 @@ class CommandHelp extends formatter_1.HelpFormatter {
291
292
  header: 'FLAG DESCRIPTIONS',
292
293
  },
293
294
  ];
295
+ const allowedSections = this.opts.sections?.map((s) => s.toLowerCase());
296
+ return sections.filter(({ header }) => !allowedSections || allowedSections.includes(header.toLowerCase()));
294
297
  }
295
298
  usage() {
296
299
  const { id, usage } = this.command;
@@ -59,8 +59,8 @@ export declare class DocOpts {
59
59
  private cmd;
60
60
  private flagList;
61
61
  private flagMap;
62
- constructor(cmd: Command.Cached | Command.Class | Command.Loadable);
63
- static generate(cmd: Command.Cached | Command.Class | Command.Loadable): string;
62
+ constructor(cmd: Command.Loadable);
63
+ static generate(cmd: Command.Loadable): string;
64
64
  toString(): string;
65
65
  private combineElementsToFlag;
66
66
  private generateElements;
@@ -79,7 +79,9 @@ class DocOpts {
79
79
  toString() {
80
80
  const opts = ['<%= command.id %>'];
81
81
  if (this.cmd.args) {
82
- const a = Object.values((0, ensure_arg_object_1.ensureArgObject)(this.cmd.args)).map((arg) => arg.required ? arg.name.toUpperCase() : `[${arg.name.toUpperCase()}]`) || [];
82
+ // If strict is false, add ellipsis to indicate that the argument takes multiple values
83
+ const suffix = this.cmd.strict === false ? '...' : '';
84
+ const a = Object.values((0, ensure_arg_object_1.ensureArgObject)(this.cmd.args)).map((arg) => arg.required ? `${arg.name.toUpperCase()}${suffix}` : `[${arg.name.toUpperCase()}${suffix}]`) || [];
83
85
  opts.push(...a);
84
86
  }
85
87
  try {
package/lib/help/index.js CHANGED
@@ -8,7 +8,7 @@ const node_util_1 = require("node:util");
8
8
  const strip_ansi_1 = __importDefault(require("strip-ansi"));
9
9
  const theme_1 = require("../cli-ux/theme");
10
10
  const write_1 = __importDefault(require("../cli-ux/write"));
11
- const errors_1 = require("../errors");
11
+ const error_1 = require("../errors/error");
12
12
  const module_loader_1 = require("../module-loader");
13
13
  const symbols_1 = require("../symbols");
14
14
  const cache_default_value_1 = require("../util/cache-default-value");
@@ -144,7 +144,9 @@ class Help extends HelpBase {
144
144
  return new this.CommandHelpClass(command, this.config, this.opts);
145
145
  }
146
146
  log(...args) {
147
- write_1.default.stdout(node_util_1.format.apply(this, args) + '\n');
147
+ this.opts.sendToStderr
148
+ ? write_1.default.stderr(node_util_1.format.apply(this, args) + '\n')
149
+ : write_1.default.stdout(node_util_1.format.apply(this, args) + '\n');
148
150
  }
149
151
  async showCommandHelp(command) {
150
152
  const name = command.id;
@@ -246,7 +248,7 @@ class Help extends HelpBase {
246
248
  return;
247
249
  }
248
250
  }
249
- (0, errors_1.error)(`Command ${subject} not found.`);
251
+ (0, error_1.error)(`Command ${subject} not found.`);
250
252
  }
251
253
  async showRootHelp() {
252
254
  let rootTopics = this.sortedTopics;
@@ -290,6 +292,8 @@ class Help extends HelpBase {
290
292
  }
291
293
  }
292
294
  summary(c) {
295
+ if (this.opts.sections && !this.opts.sections.map((s) => s.toLowerCase()).includes('summary'))
296
+ return;
293
297
  if (c.summary)
294
298
  return (0, theme_1.colorize)(this.config?.theme?.commandSummary, this.render(c.summary.split('\n')[0]));
295
299
  return c.description && (0, theme_1.colorize)(this.config?.theme?.commandSummary, this.render(c.description).split('\n')[0]);
@@ -24,6 +24,14 @@ export interface HelpOptions {
24
24
  */
25
25
  hideCommandSummaryInDescription?: boolean;
26
26
  maxWidth: number;
27
+ /**
28
+ * Only show the help for the specified sections. Defaults to all sections.
29
+ */
30
+ sections?: string[];
31
+ /**
32
+ * By default, the help output is sent to stdout. If this is true, it will be sent to stderr.
33
+ */
34
+ sendToStderr?: boolean;
27
35
  /**
28
36
  * By default, titles show flag values as `<value>`. Some CLI developers may prefer titles
29
37
  * to show the flag name as the value. i.e. `--myflag=myflag` instead of `--myflag=<value>`.
package/lib/main.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.run = exports.versionAddition = exports.helpAddition = void 0;
4
7
  const node_url_1 = require("node:url");
8
+ const cache_1 = __importDefault(require("./cache"));
5
9
  const cli_ux_1 = require("./cli-ux");
6
10
  const config_1 = require("./config");
7
11
  const help_1 = require("./help");
@@ -53,6 +57,7 @@ async function run(argv, options) {
53
57
  options = (0, node_url_1.fileURLToPath)(options);
54
58
  }
55
59
  const config = await config_1.Config.load(options ?? require.main?.filename ?? __dirname);
60
+ cache_1.default.getInstance().set('config', config);
56
61
  // If this is a single command CLI, then insert the SINGLE_COMMAND_CLI_SYMBOL into the argv array to serve as the command id.
57
62
  if (config.isSingleCommandCLI) {
58
63
  argv = [symbols_1.SINGLE_COMMAND_CLI_SYMBOL, ...argv];
@@ -5,7 +5,7 @@ const node_fs_1 = require("node:fs");
5
5
  const node_path_1 = require("node:path");
6
6
  const node_url_1 = require("node:url");
7
7
  const ts_path_1 = require("./config/ts-path");
8
- const errors_1 = require("./errors");
8
+ const module_load_1 = require("./errors/errors/module-load");
9
9
  const fs_1 = require("./util/fs");
10
10
  const getPackageType = require('get-package-type');
11
11
  /**
@@ -16,7 +16,7 @@ const s_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs', '.mts', '.cts'];
16
16
  const isPlugin = (config) => config.type !== undefined;
17
17
  function handleError(error, isESM, path) {
18
18
  if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ERR_MODULE_NOT_FOUND') {
19
- throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${path}: ${error.message}`);
19
+ throw new module_load_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${path}: ${error.message}`);
20
20
  }
21
21
  throw error;
22
22
  }
@@ -98,10 +98,10 @@ exports.loadWithData = loadWithData;
98
98
  async function loadWithDataFromManifest(cached, modulePath) {
99
99
  const { id, isESM, relativePath } = cached;
100
100
  if (!relativePath) {
101
- throw new errors_1.ModuleLoadError(`Cached command ${id} does not have a relative path`);
101
+ throw new module_load_1.ModuleLoadError(`Cached command ${id} does not have a relative path`);
102
102
  }
103
103
  if (isESM === undefined) {
104
- throw new errors_1.ModuleLoadError(`Cached command ${id} does not have the isESM property set`);
104
+ throw new module_load_1.ModuleLoadError(`Cached command ${id} does not have the isESM property set`);
105
105
  }
106
106
  const filePath = (0, node_path_1.join)(modulePath, relativePath.join(node_path_1.sep));
107
107
  try {
@@ -9,6 +9,7 @@ export type Validation = {
9
9
  };
10
10
  export declare class CLIParseError extends CLIError {
11
11
  parse: CLIParseErrorOptions['parse'];
12
+ showHelp: boolean;
12
13
  constructor(options: CLIParseErrorOptions & {
13
14
  message: string;
14
15
  });
@@ -13,6 +13,7 @@ var errors_2 = require("../errors");
13
13
  Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return errors_2.CLIError; } });
14
14
  class CLIParseError extends errors_1.CLIError {
15
15
  parse;
16
+ showHelp = false;
16
17
  constructor(options) {
17
18
  options.message += '\nSee more help with --help';
18
19
  super(options.message, { exit: options.exit });
@@ -50,6 +51,7 @@ class RequiredArgsError extends CLIParseError {
50
51
  }
51
52
  super({ exit: cache_1.default.getInstance().get('exitCodes')?.requiredArgs ?? exit, message, parse });
52
53
  this.args = args;
54
+ this.showHelp = true;
53
55
  }
54
56
  }
55
57
  exports.RequiredArgsError = RequiredArgsError;
@@ -59,6 +61,7 @@ class UnexpectedArgsError extends CLIParseError {
59
61
  const message = `Unexpected argument${args.length === 1 ? '' : 's'}: ${args.join(', ')}`;
60
62
  super({ exit: cache_1.default.getInstance().get('exitCodes')?.unexpectedArgs ?? exit, message, parse });
61
63
  this.args = args;
64
+ this.showHelp = true;
62
65
  }
63
66
  }
64
67
  exports.UnexpectedArgsError = UnexpectedArgsError;
@@ -68,6 +71,7 @@ class NonExistentFlagsError extends CLIParseError {
68
71
  const message = `Nonexistent flag${flags.length === 1 ? '' : 's'}: ${flags.join(', ')}`;
69
72
  super({ exit: cache_1.default.getInstance().get('exitCodes')?.nonExistentFlag ?? exit, message, parse });
70
73
  this.flags = flags;
74
+ this.showHelp = true;
71
75
  }
72
76
  }
73
77
  exports.NonExistentFlagsError = NonExistentFlagsError;
@@ -7,7 +7,7 @@ exports.readTSConfig = void 0;
7
7
  const debug_1 = __importDefault(require("debug"));
8
8
  const promises_1 = require("node:fs/promises");
9
9
  const node_path_1 = require("node:path");
10
- const errors_1 = require("../errors");
10
+ const warn_1 = require("../errors/warn");
11
11
  const util_1 = require("./util");
12
12
  const debug = (0, debug_1.default)('read-tsconfig');
13
13
  function resolve(root, name) {
@@ -46,7 +46,7 @@ async function readTSConfig(root, tsconfigName = 'tsconfig.json') {
46
46
  catch { }
47
47
  }
48
48
  if (!typescript) {
49
- (0, errors_1.memoizedWarn)('Could not find typescript. Please ensure that typescript is a devDependency. Falling back to compiled source.');
49
+ (0, warn_1.memoizedWarn)('Could not find typescript. Please ensure that typescript is a devDependency. Falling back to compiled source.');
50
50
  return;
51
51
  }
52
52
  const read = async (path) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/core",
3
3
  "description": "base library for oclif CLIs",
4
- "version": "3.23.1",
4
+ "version": "3.25.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {