@oclif/core 4.11.14 → 4.12.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/args.d.ts CHANGED
@@ -36,3 +36,21 @@ export declare const file: ArgDefinition<string, {
36
36
  export declare const url: ArgDefinition<URL, Record<string, unknown>>;
37
37
  declare const stringArg: ArgDefinition<string, Record<string, unknown>>;
38
38
  export { stringArg as string };
39
+ type ReadonlyElementOf<T extends ReadonlyArray<unknown>> = T[number];
40
+ /**
41
+ * Create an arg that infers the type from the provided options.
42
+ *
43
+ * The provided `options` must be a readonly array in order for type inference to work.
44
+ *
45
+ * @example
46
+ * export default class MyCommand extends Command {
47
+ * static args = {
48
+ * stage: Args.option({
49
+ * options: ['production', 'staging', 'development'] as const,
50
+ * })(),
51
+ * }
52
+ * }
53
+ */
54
+ export declare function option<T extends readonly string[]>(defaults: Omit<Partial<Arg<ReadonlyElementOf<T>>>, 'default' | 'multiple' | 'required'> & {
55
+ options: T;
56
+ }): ArgDefinition<(typeof defaults.options)[number]>;
package/lib/args.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.string = exports.url = exports.file = exports.directory = exports.integer = exports.boolean = void 0;
4
4
  exports.custom = custom;
5
+ exports.option = option;
5
6
  const node_url_1 = require("node:url");
6
7
  const fs_1 = require("./util/fs");
7
8
  const util_1 = require("./util/util");
@@ -59,3 +60,26 @@ exports.url = custom({
59
60
  });
60
61
  const stringArg = custom({});
61
62
  exports.string = stringArg;
63
+ /**
64
+ * Create an arg that infers the type from the provided options.
65
+ *
66
+ * The provided `options` must be a readonly array in order for type inference to work.
67
+ *
68
+ * @example
69
+ * export default class MyCommand extends Command {
70
+ * static args = {
71
+ * stage: Args.option({
72
+ * options: ['production', 'staging', 'development'] as const,
73
+ * })(),
74
+ * }
75
+ * }
76
+ */
77
+ function option(defaults) {
78
+ return (options = {}) => ({
79
+ parse: async (i, _context, _opts) => i,
80
+ ...defaults,
81
+ ...options,
82
+ input: [],
83
+ type: 'option',
84
+ });
85
+ }
@@ -198,7 +198,7 @@ export type ArgProps = {
198
198
  * All args after a variadic arg must be required.
199
199
  */
200
200
  multiple?: boolean;
201
- options?: string[];
201
+ options?: readonly string[];
202
202
  ignoreStdin?: boolean;
203
203
  /**
204
204
  * If true, the value returned by defaultHelp will not be cached in the oclif.manifest.json.
@@ -244,7 +244,7 @@ export type ArgParserContext = Command & {
244
244
  };
245
245
  export type ArgParser<T, P = CustomOptions> = (input: string, context: ArgParserContext, opts: P & Arg<T, P>) => Promise<T>;
246
246
  export type Arg<T, P = CustomOptions> = ArgProps & {
247
- options?: T[];
247
+ options?: readonly T[];
248
248
  defaultHelp?: ArgDefaultHelp<T>;
249
249
  input: string[];
250
250
  default?: ArgDefault<T | undefined>;
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": "4.11.14",
4
+ "version": "4.12.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {