yargs 15.3.2-beta.0 → 15.4.1

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 (83) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +2 -3
  3. package/README.md +4 -4
  4. package/build/lib/apply-extends.d.ts +2 -2
  5. package/build/lib/apply-extends.js +2 -1
  6. package/build/lib/argsert.js +1 -0
  7. package/build/lib/command.d.ts +64 -0
  8. package/build/lib/command.js +416 -0
  9. package/build/lib/common-types.d.ts +36 -0
  10. package/build/lib/common-types.js +25 -0
  11. package/build/lib/completion-templates.js +1 -0
  12. package/build/lib/completion.d.ts +20 -1
  13. package/build/lib/completion.js +14 -5
  14. package/build/lib/is-promise.js +1 -0
  15. package/build/lib/levenshtein.js +1 -0
  16. package/build/lib/middleware.d.ts +10 -0
  17. package/build/lib/middleware.js +57 -0
  18. package/build/lib/obj-filter.d.ts +1 -2
  19. package/build/lib/obj-filter.js +4 -2
  20. package/build/lib/parse-command.d.ts +10 -1
  21. package/build/lib/parse-command.js +1 -0
  22. package/build/lib/process-argv.js +1 -0
  23. package/build/lib/usage.d.ts +48 -2
  24. package/build/lib/usage.js +19 -5
  25. package/build/lib/validation.d.ts +33 -2
  26. package/build/lib/validation.js +6 -4
  27. package/build/lib/yargs.d.ts +274 -0
  28. package/build/lib/yargs.js +1190 -0
  29. package/build/lib/yerror.js +1 -0
  30. package/package.json +5 -8
  31. package/yargs.js +2 -1291
  32. package/build/lib/type-helpers/command-builder.d.ts +0 -2
  33. package/build/lib/type-helpers/command-builder.js +0 -6
  34. package/build/lib/type-helpers/completion-function.d.ts +0 -2
  35. package/build/lib/type-helpers/completion-function.js +0 -6
  36. package/build/lib/type-helpers/index.d.ts +0 -2
  37. package/build/lib/type-helpers/index.js +0 -7
  38. package/build/lib/types/command-builder.d.ts +0 -5
  39. package/build/lib/types/command-builder.js +0 -2
  40. package/build/lib/types/command-handler.d.ts +0 -4
  41. package/build/lib/types/command-handler.js +0 -2
  42. package/build/lib/types/command-instance.d.ts +0 -7
  43. package/build/lib/types/command-instance.js +0 -2
  44. package/build/lib/types/completion-function.d.ts +0 -8
  45. package/build/lib/types/completion-function.js +0 -2
  46. package/build/lib/types/completion-instance.d.ts +0 -10
  47. package/build/lib/types/completion-instance.js +0 -2
  48. package/build/lib/types/context.d.ts +0 -4
  49. package/build/lib/types/context.js +0 -2
  50. package/build/lib/types/custom-check.d.ts +0 -5
  51. package/build/lib/types/custom-check.js +0 -2
  52. package/build/lib/types/dictionary.d.ts +0 -3
  53. package/build/lib/types/dictionary.js +0 -2
  54. package/build/lib/types/electron-process.d.ts +0 -7
  55. package/build/lib/types/electron-process.js +0 -2
  56. package/build/lib/types/failure-function.d.ts +0 -5
  57. package/build/lib/types/failure-function.js +0 -2
  58. package/build/lib/types/frozen-usage-instance.d.ts +0 -11
  59. package/build/lib/types/frozen-usage-instance.js +0 -2
  60. package/build/lib/types/frozen-validation-instance.d.ts +0 -8
  61. package/build/lib/types/frozen-validation-instance.js +0 -2
  62. package/build/lib/types/index.d.ts +0 -20
  63. package/build/lib/types/index.js +0 -2
  64. package/build/lib/types/key-or-pos.d.ts +0 -1
  65. package/build/lib/types/key-or-pos.js +0 -2
  66. package/build/lib/types/logger-instance.d.ts +0 -2
  67. package/build/lib/types/logger-instance.js +0 -2
  68. package/build/lib/types/options.d.ts +0 -19
  69. package/build/lib/types/options.js +0 -2
  70. package/build/lib/types/parsed-command.d.ts +0 -6
  71. package/build/lib/types/parsed-command.js +0 -2
  72. package/build/lib/types/parser-configuration.d.ts +0 -5
  73. package/build/lib/types/parser-configuration.js +0 -2
  74. package/build/lib/types/positional.d.ts +0 -4
  75. package/build/lib/types/positional.js +0 -2
  76. package/build/lib/types/usage-instance.d.ts +0 -37
  77. package/build/lib/types/usage-instance.js +0 -2
  78. package/build/lib/types/validation-instance.d.ts +0 -28
  79. package/build/lib/types/validation-instance.js +0 -2
  80. package/build/lib/types/yargs-instance.d.ts +0 -44
  81. package/build/lib/types/yargs-instance.js +0 -2
  82. package/lib/command.js +0 -435
  83. package/lib/middleware.js +0 -64
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const path = require("path");
3
+ exports.completion = void 0;
4
+ const command_1 = require("./command");
4
5
  const templates = require("./completion-templates");
5
6
  const is_promise_1 = require("./is-promise");
6
7
  const parse_command_1 = require("./parse-command");
7
- const type_helpers_1 = require("./type-helpers");
8
+ const path = require("path");
9
+ const common_types_1 = require("./common-types");
8
10
  // add bash completions to your
9
11
  // yargs-powered applications.
10
12
  function completion(yargs, usage, command) {
@@ -26,8 +28,9 @@ function completion(yargs, usage, command) {
26
28
  const parentCommands = yargs.getContext().commands;
27
29
  // a custom completion function can be provided
28
30
  // to completion().
29
- if (completionFunction) {
30
- if (type_helpers_1.isSyncCompletionFunction(completionFunction)) {
31
+ function runCompletionFunction(argv) {
32
+ common_types_1.assertNotStrictEqual(completionFunction, null);
33
+ if (isSyncCompletionFunction(completionFunction)) {
31
34
  const result = completionFunction(current, argv);
32
35
  // promise based completion function.
33
36
  if (is_promise_1.isPromise(result)) {
@@ -47,11 +50,14 @@ function completion(yargs, usage, command) {
47
50
  });
48
51
  }
49
52
  }
53
+ if (completionFunction) {
54
+ return is_promise_1.isPromise(argv) ? argv.then(runCompletionFunction) : runCompletionFunction(argv);
55
+ }
50
56
  const handlers = command.getCommandHandlers();
51
57
  for (let i = 0, ii = args.length; i < ii; ++i) {
52
58
  if (handlers[args[i]] && handlers[args[i]].builder) {
53
59
  const builder = handlers[args[i]].builder;
54
- if (type_helpers_1.isFunctionCommandBuilder(builder)) {
60
+ if (command_1.isCommandBuilderCallback(builder)) {
55
61
  const y = yargs.reset();
56
62
  builder(y);
57
63
  return y.argv;
@@ -124,3 +130,6 @@ function completion(yargs, usage, command) {
124
130
  return self;
125
131
  }
126
132
  exports.completion = completion;
133
+ function isSyncCompletionFunction(completionFunction) {
134
+ return completionFunction.length < 3;
135
+ }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPromise = void 0;
3
4
  function isPromise(maybePromise) {
4
5
  return !!maybePromise &&
5
6
  !!maybePromise.then &&
@@ -20,6 +20,7 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
20
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
  */
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.levenshtein = void 0;
23
24
  // levenshtein distance algorithm, pulled from Andrei Mackenzie's MIT licensed.
24
25
  // gist, which can be found here: https://gist.github.com/andrei-m/982927
25
26
  // Compute the edit distance between the two given strings
@@ -0,0 +1,10 @@
1
+ import { YargsInstance, Arguments } from './yargs';
2
+ export declare function globalMiddlewareFactory<T>(globalMiddleware: Middleware[], context: T): (callback: MiddlewareCallback | MiddlewareCallback[], applyBeforeValidation?: boolean) => T;
3
+ export declare function commandMiddlewareFactory(commandMiddleware?: MiddlewareCallback[]): Middleware[];
4
+ export declare function applyMiddleware(argv: Arguments | Promise<Arguments>, yargs: YargsInstance, middlewares: Middleware[], beforeValidation: boolean): Arguments | Promise<Arguments>;
5
+ export interface MiddlewareCallback {
6
+ (argv: Arguments, yargs: YargsInstance): Partial<Arguments> | Promise<Partial<Arguments>>;
7
+ }
8
+ export interface Middleware extends MiddlewareCallback {
9
+ applyBeforeValidation: boolean;
10
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyMiddleware = exports.commandMiddlewareFactory = exports.globalMiddlewareFactory = void 0;
4
+ const argsert_1 = require("./argsert");
5
+ const is_promise_1 = require("./is-promise");
6
+ function globalMiddlewareFactory(globalMiddleware, context) {
7
+ return function (callback, applyBeforeValidation = false) {
8
+ argsert_1.argsert('<array|function> [boolean]', [callback, applyBeforeValidation], arguments.length);
9
+ if (Array.isArray(callback)) {
10
+ for (let i = 0; i < callback.length; i++) {
11
+ if (typeof callback[i] !== 'function') {
12
+ throw Error('middleware must be a function');
13
+ }
14
+ callback[i].applyBeforeValidation = applyBeforeValidation;
15
+ }
16
+ Array.prototype.push.apply(globalMiddleware, callback);
17
+ }
18
+ else if (typeof callback === 'function') {
19
+ callback.applyBeforeValidation = applyBeforeValidation;
20
+ globalMiddleware.push(callback);
21
+ }
22
+ return context;
23
+ };
24
+ }
25
+ exports.globalMiddlewareFactory = globalMiddlewareFactory;
26
+ function commandMiddlewareFactory(commandMiddleware) {
27
+ if (!commandMiddleware)
28
+ return [];
29
+ return commandMiddleware.map(middleware => {
30
+ middleware.applyBeforeValidation = false;
31
+ return middleware;
32
+ });
33
+ }
34
+ exports.commandMiddlewareFactory = commandMiddlewareFactory;
35
+ function applyMiddleware(argv, yargs, middlewares, beforeValidation) {
36
+ const beforeValidationError = new Error('middleware cannot return a promise when applyBeforeValidation is true');
37
+ return middlewares
38
+ .reduce((acc, middleware) => {
39
+ if (middleware.applyBeforeValidation !== beforeValidation) {
40
+ return acc;
41
+ }
42
+ if (is_promise_1.isPromise(acc)) {
43
+ return acc
44
+ .then(initialObj => Promise.all([initialObj, middleware(initialObj, yargs)]))
45
+ .then(([initialObj, middlewareObj]) => Object.assign(initialObj, middlewareObj));
46
+ }
47
+ else {
48
+ const result = middleware(acc, yargs);
49
+ if (beforeValidation && is_promise_1.isPromise(result))
50
+ throw beforeValidationError;
51
+ return is_promise_1.isPromise(result)
52
+ ? result.then(middlewareObj => Object.assign(acc, middlewareObj))
53
+ : Object.assign(acc, result);
54
+ }
55
+ }, argv);
56
+ }
57
+ exports.applyMiddleware = applyMiddleware;
@@ -1,2 +1 @@
1
- import { Dictionary } from './types';
2
- export declare function objFilter<T = any>(original: Dictionary<T>, filter?: (k: string, v: T) => boolean): Dictionary<T>;
1
+ export declare function objFilter<T extends object>(original?: T, filter?: (k: keyof T, v: T[keyof T]) => boolean): T;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- function objFilter(original, filter = () => true) {
3
+ exports.objFilter = void 0;
4
+ const common_types_1 = require("./common-types");
5
+ function objFilter(original = {}, filter = () => true) {
4
6
  const obj = {};
5
- Object.keys(original || {}).forEach((key) => {
7
+ common_types_1.objectKeys(original).forEach((key) => {
6
8
  if (filter(key, original[key])) {
7
9
  obj[key] = original[key];
8
10
  }
@@ -1,2 +1,11 @@
1
- import { ParsedCommand } from './types';
1
+ import { NotEmptyArray } from './common-types';
2
2
  export declare function parseCommand(cmd: string): ParsedCommand;
3
+ export interface ParsedCommand {
4
+ cmd: string;
5
+ demanded: Positional[];
6
+ optional: Positional[];
7
+ }
8
+ export interface Positional {
9
+ cmd: NotEmptyArray<string>;
10
+ variadic: boolean;
11
+ }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseCommand = void 0;
3
4
  function parseCommand(cmd) {
4
5
  const extraSpacesStrippedCommand = cmd.replace(/\s{2,}/g, ' ');
5
6
  const splitCommand = extraSpacesStrippedCommand.split(/\s+(?![^[]*]|[^<]*>)/);
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProcessArgvBin = exports.getProcessArgvWithoutBin = void 0;
3
4
  function getProcessArgvBinIndex() {
4
5
  // The binary name is the first command line argument for:
5
6
  // - bundled Electron apps: bin argv1 argv2 ... argvn
@@ -1,3 +1,49 @@
1
- import { UsageInstance, YargsInstance } from './types';
2
- import Y18N = require('y18n');
1
+ import { Dictionary } from './common-types';
2
+ import { YargsInstance } from './yargs';
3
+ import { YError } from './yerror';
4
+ import { Y18N } from 'y18n';
3
5
  export declare function usage(yargs: YargsInstance, y18n: Y18N): UsageInstance;
6
+ /** Instance of the usage module. */
7
+ export interface UsageInstance {
8
+ cacheHelpMessage(): void;
9
+ clearCachedHelpMessage(): void;
10
+ command(cmd: string, description: string | undefined, isDefault: boolean, aliases: string[], deprecated?: boolean): void;
11
+ deferY18nLookup(str: string): string;
12
+ describe(keys: string | string[] | Dictionary<string>, desc?: string): void;
13
+ epilog(msg: string): void;
14
+ example(cmd: string, description?: string): void;
15
+ fail(msg?: string | null, err?: YError | string): void;
16
+ failFn(f: FailureFunction): void;
17
+ freeze(): void;
18
+ functionDescription(fn: {
19
+ name?: string;
20
+ }): string;
21
+ getCommands(): [string, string, boolean, string[], boolean][];
22
+ getDescriptions(): Dictionary<string | undefined>;
23
+ getPositionalGroupName(): string;
24
+ getUsage(): [string, string][];
25
+ getUsageDisabled(): boolean;
26
+ help(): string;
27
+ reset(localLookup: Dictionary<boolean>): UsageInstance;
28
+ showHelp(level: 'error' | 'log' | ((message: string) => void)): void;
29
+ showHelpOnFail(enabled?: boolean | string, message?: string): UsageInstance;
30
+ showVersion(): void;
31
+ stringifiedValues(values?: any[], separator?: string): string;
32
+ unfreeze(): void;
33
+ usage(msg: string | null, description?: string | false): UsageInstance;
34
+ version(ver: any): void;
35
+ wrap(cols: number | null | undefined): void;
36
+ }
37
+ export interface FailureFunction {
38
+ (msg: string | undefined | null, err: YError | string | undefined, usage: UsageInstance): void;
39
+ }
40
+ export interface FrozenUsageInstance {
41
+ failMessage: string | undefined | null;
42
+ failureOutput: boolean;
43
+ usages: [string, string][];
44
+ usageDisabled: boolean;
45
+ epilogs: string[];
46
+ examples: [string, string][];
47
+ commands: [string, string, boolean, string[], boolean][];
48
+ descriptions: Dictionary<string | undefined>;
49
+ }
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usage = void 0;
3
4
  // this file handles outputting usage instructions,
4
5
  // failures, etc. keeps logging in one place.
6
+ const common_types_1 = require("./common-types");
5
7
  const obj_filter_1 = require("./obj-filter");
6
8
  const path = require("path");
7
9
  const yerror_1 = require("./yerror");
@@ -92,7 +94,7 @@ function usage(yargs, y18n) {
92
94
  examples.push([cmd, description || '']);
93
95
  };
94
96
  let commands = [];
95
- self.command = function command(cmd, description, isDefault, aliases) {
97
+ self.command = function command(cmd, description, isDefault, aliases, deprecated = false) {
96
98
  // the last default wins, so cancel out any previously set default
97
99
  if (isDefault) {
98
100
  commands = commands.map((cmdArray) => {
@@ -100,12 +102,17 @@ function usage(yargs, y18n) {
100
102
  return cmdArray;
101
103
  });
102
104
  }
103
- commands.push([cmd, description || '', isDefault, aliases]);
105
+ commands.push([cmd, description || '', isDefault, aliases, deprecated]);
104
106
  };
105
107
  self.getCommands = () => commands;
106
108
  let descriptions = {};
107
109
  self.describe = function describe(keyOrKeys, desc) {
108
- if (typeof keyOrKeys === 'object') {
110
+ if (Array.isArray(keyOrKeys)) {
111
+ keyOrKeys.forEach((k) => {
112
+ self.describe(k, desc);
113
+ });
114
+ }
115
+ else if (typeof keyOrKeys === 'object') {
109
116
  Object.keys(keyOrKeys).forEach((k) => {
110
117
  self.describe(k, keyOrKeys[k]);
111
118
  });
@@ -207,6 +214,14 @@ function usage(yargs, y18n) {
207
214
  if (command[3] && command[3].length) {
208
215
  hints.push(`[${__('aliases:')} ${command[3].join(', ')}]`);
209
216
  }
217
+ if (command[4]) {
218
+ if (typeof command[4] === 'string') {
219
+ hints.push(`[${__('deprecated: %s', command[4])}]`);
220
+ }
221
+ else {
222
+ hints.push(`[${__('deprecated')}]`);
223
+ }
224
+ }
210
225
  if (hints.length) {
211
226
  ui.div({ text: hints.join(' '), padding: [0, 0, 0, 2], align: 'right' });
212
227
  }
@@ -508,8 +523,7 @@ function usage(yargs, y18n) {
508
523
  };
509
524
  self.unfreeze = function unfreeze() {
510
525
  const frozen = frozens.pop();
511
- if (!frozen)
512
- throw new Error('Nothing more to unfreeze');
526
+ common_types_1.assertNotStrictEqual(frozen, undefined);
513
527
  ({
514
528
  failMessage,
515
529
  failureOutput,
@@ -1,3 +1,34 @@
1
- import { YargsInstance, UsageInstance, ValidationInstance } from './types';
2
- import Y18N = require('y18n');
1
+ import { Dictionary } from './common-types';
2
+ import { UsageInstance } from './usage';
3
+ import { YargsInstance, Arguments } from './yargs';
4
+ import { DetailedArguments } from 'yargs-parser';
5
+ import { Y18N } from 'y18n';
3
6
  export declare function validation(yargs: YargsInstance, usage: UsageInstance, y18n: Y18N): ValidationInstance;
7
+ /** Instance of the validation module. */
8
+ export interface ValidationInstance {
9
+ check(f: CustomCheck['func'], global: boolean): void;
10
+ conflicting(argv: Arguments): void;
11
+ conflicts(key: string | Dictionary<string | string[]>, value?: string | string[]): void;
12
+ customChecks(argv: Arguments, aliases: DetailedArguments['aliases']): void;
13
+ freeze(): void;
14
+ getConflicting(): Dictionary<(string | undefined)[]>;
15
+ getImplied(): Dictionary<KeyOrPos[]>;
16
+ implications(argv: Arguments): void;
17
+ implies(key: string | Dictionary<KeyOrPos | KeyOrPos[]>, value?: KeyOrPos | KeyOrPos[]): void;
18
+ isValidAndSomeAliasIsNotNew(key: string, aliases: DetailedArguments['aliases']): boolean;
19
+ limitedChoices(argv: Arguments): void;
20
+ nonOptionCount(argv: Arguments): void;
21
+ positionalCount(required: number, observed: number): void;
22
+ recommendCommands(cmd: string, potentialCommands: string[]): void;
23
+ requiredArguments(argv: Arguments): void;
24
+ reset(localLookup: Dictionary): ValidationInstance;
25
+ unfreeze(): void;
26
+ unknownArguments(argv: Arguments, aliases: DetailedArguments['aliases'], positionalMap: Dictionary, isDefaultCommand: boolean): void;
27
+ unknownCommands(argv: Arguments): boolean;
28
+ }
29
+ interface CustomCheck {
30
+ func: (argv: Arguments, aliases: DetailedArguments['aliases']) => any;
31
+ global: boolean;
32
+ }
33
+ export declare type KeyOrPos = string | number;
34
+ export {};
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validation = void 0;
3
4
  const argsert_1 = require("./argsert");
5
+ const common_types_1 = require("./common-types");
4
6
  const levenshtein_1 = require("./levenshtein");
5
7
  const obj_filter_1 = require("./obj-filter");
6
8
  const specialKeys = ['$0', '--', '_'];
@@ -73,7 +75,7 @@ function validation(yargs, usage, y18n) {
73
75
  }
74
76
  };
75
77
  // check for unknown arguments (strict-mode).
76
- self.unknownArguments = function unknownArguments(argv, aliases, positionalMap) {
78
+ self.unknownArguments = function unknownArguments(argv, aliases, positionalMap, isDefaultCommand) {
77
79
  const commandKeys = yargs.getCommandInstance().getCommands();
78
80
  const unknown = [];
79
81
  const currentContext = yargs.getContext();
@@ -85,7 +87,7 @@ function validation(yargs, usage, y18n) {
85
87
  unknown.push(key);
86
88
  }
87
89
  });
88
- if ((currentContext.commands.length > 0) || (commandKeys.length > 0)) {
90
+ if ((currentContext.commands.length > 0) || (commandKeys.length > 0) || isDefaultCommand) {
89
91
  argv._.slice(currentContext.commands.length).forEach((key) => {
90
92
  if (commandKeys.indexOf(key) === -1) {
91
93
  unknown.push(key);
@@ -201,6 +203,7 @@ function validation(yargs, usage, y18n) {
201
203
  value.forEach((i) => self.implies(key, i));
202
204
  }
203
205
  else {
206
+ common_types_1.assertNotStrictEqual(value, undefined);
204
207
  implied[key].push(value);
205
208
  }
206
209
  }
@@ -315,8 +318,7 @@ function validation(yargs, usage, y18n) {
315
318
  };
316
319
  self.unfreeze = function unfreeze() {
317
320
  const frozen = frozens.pop();
318
- if (!frozen)
319
- throw new Error('Nothing more to unfreeze');
321
+ common_types_1.assertNotStrictEqual(frozen, undefined);
320
322
  ({
321
323
  implied,
322
324
  checks,
@@ -0,0 +1,274 @@
1
+ /// <reference types="node" />
2
+ import { CommandInstance, CommandHandler, CommandBuilderDefinition, CommandBuilder, CommandHandlerCallback, FinishCommandHandler } from './command';
3
+ import { Dictionary } from './common-types';
4
+ import { Arguments as ParserArguments, DetailedArguments as ParserDetailedArguments, Configuration as ParserConfiguration, Options as ParserOptions, ConfigCallback, CoerceCallback } from 'yargs-parser';
5
+ import { YError } from './yerror';
6
+ import { UsageInstance, FailureFunction } from './usage';
7
+ import { CompletionFunction } from './completion';
8
+ import { ValidationInstance, KeyOrPos } from './validation';
9
+ import { Y18N } from 'y18n';
10
+ import { MiddlewareCallback, Middleware } from './middleware';
11
+ import { RequireDirectoryOptions } from 'require-directory';
12
+ export declare function Yargs(processArgs?: string | string[], cwd?: string, parentRequire?: NodeRequire): YargsInstance;
13
+ export declare function rebase(base: string, dir: string): string;
14
+ /** Instance of the yargs module. */
15
+ export interface YargsInstance {
16
+ $0: string;
17
+ argv: Arguments;
18
+ customScriptName: boolean;
19
+ parsed: DetailedArguments | false;
20
+ _copyDoubleDash<T extends Arguments | Promise<Arguments>>(argv: T): T;
21
+ _getLoggerInstance(): LoggerInstance;
22
+ _getParseContext(): Object;
23
+ _hasOutput(): boolean;
24
+ _hasParseCallback(): boolean;
25
+ _parseArgs: {
26
+ (args: null, shortCircuit: null, _calledFromCommand: boolean, commandIndex?: number): Arguments | Promise<Arguments>;
27
+ (args: string | string[], shortCircuit?: boolean): Arguments | Promise<Arguments>;
28
+ };
29
+ _runValidation(argv: Arguments, aliases: Dictionary<string[]>, positionalMap: Dictionary<string[]>, parseErrors: Error | null, isDefaultCommand?: boolean): void;
30
+ _setHasOutput(): void;
31
+ addHelpOpt: {
32
+ (opt?: string | false): YargsInstance;
33
+ (opt?: string, msg?: string): YargsInstance;
34
+ };
35
+ addShowHiddenOpt: {
36
+ (opt?: string | false): YargsInstance;
37
+ (opt?: string, msg?: string): YargsInstance;
38
+ };
39
+ alias: {
40
+ (keys: string | string[], aliases: string | string[]): YargsInstance;
41
+ (keyAliases: Dictionary<string | string[]>): YargsInstance;
42
+ };
43
+ array(keys: string | string[]): YargsInstance;
44
+ boolean(keys: string | string[]): YargsInstance;
45
+ check(f: (argv: Arguments, aliases: Dictionary<string[]>) => any, _global?: boolean): YargsInstance;
46
+ choices: {
47
+ (keys: string | string[], choices: string | string[]): YargsInstance;
48
+ (keyChoices: Dictionary<string | string[]>): YargsInstance;
49
+ };
50
+ coerce: {
51
+ (keys: string | string[], coerceCallback: CoerceCallback): YargsInstance;
52
+ (keyCoerceCallbacks: Dictionary<CoerceCallback>): YargsInstance;
53
+ };
54
+ command(cmd: string | string[], description: CommandHandler['description'], builder?: CommandBuilderDefinition | CommandBuilder, handler?: CommandHandlerCallback, commandMiddleware?: Middleware[], deprecated?: boolean): YargsInstance;
55
+ commandDir(dir: string, opts?: RequireDirectoryOptions<any>): YargsInstance;
56
+ completion: {
57
+ (cmd?: string, fn?: CompletionFunction): YargsInstance;
58
+ (cmd?: string, desc?: string | false, fn?: CompletionFunction): YargsInstance;
59
+ };
60
+ config: {
61
+ (config: Dictionary): YargsInstance;
62
+ (keys?: string | string[], configCallback?: ConfigCallback): YargsInstance;
63
+ (keys?: string | string[], msg?: string, configCallback?: ConfigCallback): YargsInstance;
64
+ };
65
+ conflicts: {
66
+ (key: string, conflictsWith: string | string[]): YargsInstance;
67
+ (keyConflicts: Dictionary<string | string[]>): YargsInstance;
68
+ };
69
+ count(keys: string | string[]): YargsInstance;
70
+ default: {
71
+ (key: string, value: any, defaultDescription?: string): YargsInstance;
72
+ (keys: string[], value: Exclude<any, Function>): YargsInstance;
73
+ (keys: Dictionary<any>): YargsInstance;
74
+ };
75
+ defaults: YargsInstance['default'];
76
+ demand: {
77
+ (min: number, max?: number | string, msg?: string): YargsInstance;
78
+ (keys: string | string[], msg?: string | true): YargsInstance;
79
+ (keys: string | string[], max: string[], msg?: string | true): YargsInstance;
80
+ (keyMsgs: Dictionary<string | undefined>): YargsInstance;
81
+ (keyMsgs: Dictionary<string | undefined>, max: string[], msg?: string): YargsInstance;
82
+ };
83
+ demandCommand(): YargsInstance;
84
+ demandCommand(min: number, minMsg?: string): YargsInstance;
85
+ demandCommand(min: number, max: number, minMsg?: string | null, maxMsg?: string | null): YargsInstance;
86
+ demandOption: {
87
+ (keys: string | string[], msg?: string): YargsInstance;
88
+ (keyMsgs: Dictionary<string | undefined>): YargsInstance;
89
+ };
90
+ deprecateOption(option: string, message?: string | boolean): YargsInstance;
91
+ describe: {
92
+ (keys: string | string[], description?: string): YargsInstance;
93
+ (keyDescriptions: Dictionary<string>): YargsInstance;
94
+ };
95
+ detectLocale(detect: boolean): YargsInstance;
96
+ env(prefix?: string | false): YargsInstance;
97
+ epilog: YargsInstance['epilogue'];
98
+ epilogue(msg: string): YargsInstance;
99
+ example(cmd: string | [string, string?][], description?: string): YargsInstance;
100
+ exit(code: number, err?: YError | string): void;
101
+ exitProcess(enabled: boolean): YargsInstance;
102
+ fail(f: FailureFunction): YargsInstance;
103
+ getCommandInstance(): CommandInstance;
104
+ getCompletion(args: string[], done: (completions: string[]) => any): void;
105
+ getContext(): Context;
106
+ getDemandedCommands(): Options['demandedCommands'];
107
+ getDemandedOptions(): Options['demandedOptions'];
108
+ getDeprecatedOptions(): Options['deprecatedOptions'];
109
+ getDetectLocale(): boolean;
110
+ getExitProcess(): boolean;
111
+ getGroups(): Dictionary<string[]>;
112
+ getHandlerFinishCommand(): FinishCommandHandler | null;
113
+ getOptions(): Options;
114
+ getParserConfiguration(): Configuration;
115
+ getStrict(): boolean;
116
+ getStrictCommands(): boolean;
117
+ getUsageInstance(): UsageInstance;
118
+ getValidationInstance(): ValidationInstance;
119
+ global(keys: string | string[], global?: boolean): YargsInstance;
120
+ group(keys: string | string[], groupName: string): YargsInstance;
121
+ help: YargsInstance['addHelpOpt'];
122
+ hide(key: string): YargsInstance;
123
+ implies: {
124
+ (key: string, implication: KeyOrPos | KeyOrPos[]): YargsInstance;
125
+ (keyImplications: Dictionary<KeyOrPos | KeyOrPos[]>): YargsInstance;
126
+ };
127
+ locale: {
128
+ (): string;
129
+ (locale: string): YargsInstance;
130
+ };
131
+ middleware(callback: MiddlewareCallback | MiddlewareCallback[], applyBeforeValidation?: boolean): YargsInstance;
132
+ nargs: {
133
+ (keys: string | string[], nargs: number): YargsInstance;
134
+ (keyNargs: Dictionary<number>): YargsInstance;
135
+ };
136
+ normalize(keys: string | string[]): YargsInstance;
137
+ number(keys: string | string[]): YargsInstance;
138
+ onFinishCommand(f: FinishCommandHandler): YargsInstance;
139
+ option: {
140
+ (key: string, optionDefinition: OptionDefinition): YargsInstance;
141
+ (keyOptionDefinitions: Dictionary<OptionDefinition>): YargsInstance;
142
+ };
143
+ options: YargsInstance['option'];
144
+ parse: {
145
+ (): Arguments | Promise<Arguments>;
146
+ (args: string | string[], context: object, parseCallback?: ParseCallback): Arguments | Promise<Arguments>;
147
+ (args: string | string[], parseCallback: ParseCallback): Arguments | Promise<Arguments>;
148
+ (args: string | string[], shortCircuit: boolean): Arguments | Promise<Arguments>;
149
+ };
150
+ parserConfiguration(config: Configuration): YargsInstance;
151
+ pkgConf(key: string, rootPath?: string): YargsInstance;
152
+ positional(key: string, positionalDefinition: PositionalDefinition): YargsInstance;
153
+ recommendCommands(recommend: boolean): YargsInstance;
154
+ require: YargsInstance['demand'];
155
+ required: YargsInstance['demand'];
156
+ requiresArg(keys: string | string[] | Dictionary): YargsInstance;
157
+ reset(aliases?: DetailedArguments['aliases']): YargsInstance;
158
+ resetOptions(aliases?: DetailedArguments['aliases']): YargsInstance;
159
+ scriptName(scriptName: string): YargsInstance;
160
+ showCompletionScript($0?: string, cmd?: string): YargsInstance;
161
+ showHelp(level: 'error' | 'log' | ((message: string) => void)): YargsInstance;
162
+ showHelpOnFail: {
163
+ (message?: string): YargsInstance;
164
+ (enabled: boolean, message: string): YargsInstance;
165
+ };
166
+ showHidden: YargsInstance['addShowHiddenOpt'];
167
+ skipValidation(keys: string | string[]): YargsInstance;
168
+ strict(enable?: boolean): YargsInstance;
169
+ strictCommands(enable?: boolean): YargsInstance;
170
+ string(key: string | string[]): YargsInstance;
171
+ terminalWidth(): number | null;
172
+ updateStrings(obj: Dictionary<string>): YargsInstance;
173
+ updateLocale: YargsInstance['updateStrings'];
174
+ usage: {
175
+ (msg: string | null): YargsInstance;
176
+ (msg: string, description: CommandHandler['description'], builder?: CommandBuilderDefinition | CommandBuilder, handler?: CommandHandlerCallback): YargsInstance;
177
+ };
178
+ version: {
179
+ (ver?: string | false): YargsInstance;
180
+ (key?: string, ver?: string): YargsInstance;
181
+ (key?: string, msg?: string, ver?: string): YargsInstance;
182
+ };
183
+ wrap(cols: number | null | undefined): YargsInstance;
184
+ }
185
+ export declare function isYargsInstance(y: YargsInstance | void): y is YargsInstance;
186
+ /** Yargs' context. */
187
+ export interface Context {
188
+ commands: string[];
189
+ files: string[];
190
+ fullCommands: string[];
191
+ }
192
+ declare type LoggerInstance = Pick<Console, 'error' | 'log'>;
193
+ export interface Options extends ParserOptions {
194
+ __: Y18N['__'];
195
+ alias: Dictionary<string[]>;
196
+ array: string[];
197
+ boolean: string[];
198
+ choices: Dictionary<string[]>;
199
+ config: Dictionary<ConfigCallback | boolean>;
200
+ configObjects: Dictionary[];
201
+ configuration: Configuration;
202
+ count: string[];
203
+ defaultDescription: Dictionary<string | undefined>;
204
+ demandedCommands: Dictionary<{
205
+ min: number;
206
+ max: number;
207
+ minMsg?: string | null;
208
+ maxMsg?: string | null;
209
+ }>;
210
+ demandedOptions: Dictionary<string | undefined>;
211
+ deprecatedOptions: Dictionary<string | boolean | undefined>;
212
+ hiddenOptions: string[];
213
+ /** Manually set keys */
214
+ key: Dictionary<boolean | string>;
215
+ local: string[];
216
+ normalize: string[];
217
+ number: string[];
218
+ showHiddenOpt: string;
219
+ skipValidation: string[];
220
+ string: string[];
221
+ }
222
+ export interface Configuration extends Partial<ParserConfiguration> {
223
+ /** Should a config object be deep-merged with the object config it extends? */
224
+ 'deep-merge-config'?: boolean;
225
+ /** Should commands be sorted in help? */
226
+ 'sort-commands'?: boolean;
227
+ }
228
+ export interface OptionDefinition {
229
+ alias?: string | string[];
230
+ array?: boolean;
231
+ boolean?: boolean;
232
+ choices?: string | string[];
233
+ coerce?: CoerceCallback;
234
+ config?: boolean;
235
+ configParser?: ConfigCallback;
236
+ conflicts?: string | string[];
237
+ count?: boolean;
238
+ default?: any;
239
+ defaultDescription?: string;
240
+ deprecate?: string | boolean;
241
+ deprecated?: OptionDefinition['deprecate'];
242
+ desc?: string;
243
+ describe?: OptionDefinition['desc'];
244
+ description?: OptionDefinition['desc'];
245
+ demand?: string | true;
246
+ demandOption?: OptionDefinition['demand'];
247
+ global?: boolean;
248
+ group?: string;
249
+ hidden?: boolean;
250
+ implies?: string | number | KeyOrPos[];
251
+ nargs?: number;
252
+ normalize?: boolean;
253
+ number?: boolean;
254
+ require?: OptionDefinition['demand'];
255
+ required?: OptionDefinition['demand'];
256
+ requiresArg?: boolean;
257
+ skipValidation?: boolean;
258
+ string?: boolean;
259
+ type?: 'array' | 'boolean' | 'count' | 'number' | 'string';
260
+ }
261
+ interface PositionalDefinition extends Pick<OptionDefinition, 'alias' | 'array' | 'coerce' | 'choices' | 'conflicts' | 'default' | 'defaultDescription' | 'demand' | 'desc' | 'describe' | 'description' | 'implies' | 'normalize'> {
262
+ type?: 'boolean' | 'number' | 'string';
263
+ }
264
+ interface ParseCallback {
265
+ (err: YError | string | undefined | null, argv: Arguments | Promise<Arguments>, output: string): void;
266
+ }
267
+ export interface Arguments extends ParserArguments {
268
+ /** The script name or node command */
269
+ $0: string;
270
+ }
271
+ export interface DetailedArguments extends ParserDetailedArguments {
272
+ argv: Arguments;
273
+ }
274
+ export {};