projen 0.71.38 → 0.71.39
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/.jsii +3 -3
- package/lib/awscdk/auto-discover.js +5 -5
- package/lib/awscdk/awscdk-app-java.js +1 -1
- package/lib/awscdk/awscdk-app-py.js +1 -1
- package/lib/awscdk/awscdk-app-ts.js +1 -1
- package/lib/awscdk/awscdk-construct.js +2 -2
- package/lib/awscdk/awscdk-deps-java.js +1 -1
- package/lib/awscdk/awscdk-deps-js.js +1 -1
- package/lib/awscdk/awscdk-deps-py.js +1 -1
- package/lib/awscdk/awscdk-deps.js +1 -1
- package/lib/awscdk/cdk-config.js +1 -1
- package/lib/awscdk/cdk-tasks.js +1 -1
- package/lib/awscdk/integration-test.js +1 -1
- package/lib/awscdk/lambda-extension.js +1 -1
- package/lib/awscdk/lambda-function.js +2 -2
- package/lib/build/build-workflow.js +1 -1
- package/lib/cdk/auto-discover-base.js +2 -2
- package/lib/cdk/construct-lib.js +1 -1
- package/lib/cdk/integration-test-base.js +1 -1
- package/lib/cdk/jsii-docgen.js +1 -1
- package/lib/cdk/jsii-project.js +1 -1
- package/lib/cdk8s/auto-discover.js +2 -2
- package/lib/cdk8s/cdk8s-app-py.js +1 -1
- package/lib/cdk8s/cdk8s-app-ts.js +1 -1
- package/lib/cdk8s/cdk8s-construct.js +1 -1
- package/lib/cdk8s/cdk8s-deps-py.js +1 -1
- package/lib/cdk8s/cdk8s-deps.js +1 -1
- package/lib/cdk8s/integration-test.js +1 -1
- package/lib/cdktf/cdktf-construct.js +1 -1
- package/lib/circleci/circleci.js +1 -1
- package/lib/cli/cmds/new.js +27 -19
- package/lib/cli/index.js +2 -2
- package/lib/cli/util.d.ts +3 -0
- package/lib/cli/util.js +9 -2
- package/lib/component.js +1 -1
- package/lib/dependencies.js +1 -1
- package/lib/dev-env.js +1 -1
- package/lib/docker-compose/docker-compose-service.js +1 -1
- package/lib/docker-compose/docker-compose.js +1 -1
- package/lib/file.js +1 -1
- package/lib/gitattributes.js +1 -1
- package/lib/github/actions-provider.js +1 -1
- package/lib/github/auto-approve.js +1 -1
- package/lib/github/auto-merge.js +1 -1
- package/lib/github/dependabot.js +1 -1
- package/lib/github/github-credentials.js +1 -1
- package/lib/github/github-project.js +1 -1
- package/lib/github/github.js +1 -1
- package/lib/github/mergify.js +1 -1
- package/lib/github/pr-template.js +1 -1
- package/lib/github/pull-request-lint.js +1 -1
- package/lib/github/stale.js +1 -1
- package/lib/github/task-workflow.js +1 -1
- package/lib/github/workflow-actions.js +1 -1
- package/lib/github/workflow-jobs.js +1 -1
- package/lib/github/workflows.js +1 -1
- package/lib/gitlab/configuration.js +1 -1
- package/lib/gitlab/gitlab-configuration.js +1 -1
- package/lib/gitlab/nested-configuration.js +1 -1
- package/lib/gitpod.js +1 -1
- package/lib/ignore-file.js +1 -1
- package/lib/ini.js +1 -1
- package/lib/java/java-project.js +1 -1
- package/lib/java/junit.js +1 -1
- package/lib/java/maven-compile.js +1 -1
- package/lib/java/maven-packaging.js +1 -1
- package/lib/java/maven-sample.js +1 -1
- package/lib/java/pom.js +1 -1
- package/lib/java/projenrc.js +1 -1
- package/lib/javascript/bundler.js +1 -1
- package/lib/javascript/eslint.js +1 -1
- package/lib/javascript/jest.js +4 -4
- package/lib/javascript/node-package.js +1 -1
- package/lib/javascript/node-project.js +1 -1
- package/lib/javascript/npm-config.js +1 -1
- package/lib/javascript/prettier.js +1 -1
- package/lib/javascript/projenrc.js +1 -1
- package/lib/javascript/typescript-config.js +2 -2
- package/lib/javascript/upgrade-dependencies.js +2 -2
- package/lib/json-patch.js +1 -1
- package/lib/json.js +1 -1
- package/lib/license.js +1 -1
- package/lib/logger.js +1 -1
- package/lib/makefile.js +1 -1
- package/lib/object-file.js +1 -1
- package/lib/project-build.js +1 -1
- package/lib/project.js +1 -1
- package/lib/projects.js +1 -1
- package/lib/projenrc-json.js +2 -2
- package/lib/projenrc.js +1 -1
- package/lib/python/pip.js +1 -1
- package/lib/python/poetry.js +2 -2
- package/lib/python/projenrc.js +1 -1
- package/lib/python/pytest-sample.js +1 -1
- package/lib/python/pytest.js +1 -1
- package/lib/python/python-project.js +1 -1
- package/lib/python/python-sample.js +1 -1
- package/lib/python/requirements-file.js +1 -1
- package/lib/python/setuppy.js +1 -1
- package/lib/python/setuptools.js +1 -1
- package/lib/python/venv.js +1 -1
- package/lib/readme.js +1 -1
- package/lib/release/publisher.js +1 -1
- package/lib/release/release-trigger.js +1 -1
- package/lib/release/release.js +1 -1
- package/lib/renovatebot.js +1 -1
- package/lib/sample-file.js +2 -2
- package/lib/semver.js +1 -1
- package/lib/source-code.js +1 -1
- package/lib/task-runtime.js +1 -1
- package/lib/task.js +1 -1
- package/lib/tasks.js +1 -1
- package/lib/testing.js +1 -1
- package/lib/textfile.js +1 -1
- package/lib/toml.js +1 -1
- package/lib/typescript/projenrc-ts.js +1 -1
- package/lib/typescript/projenrc.js +1 -1
- package/lib/typescript/typescript-typedoc.js +1 -1
- package/lib/typescript/typescript.js +3 -3
- package/lib/version.js +1 -1
- package/lib/vscode/devcontainer.js +1 -1
- package/lib/vscode/extensions.js +1 -1
- package/lib/vscode/launch-config.js +1 -1
- package/lib/vscode/settings.js +1 -1
- package/lib/vscode/vscode.js +1 -1
- package/lib/web/next.js +3 -3
- package/lib/web/postcss.js +1 -1
- package/lib/web/react.js +4 -4
- package/lib/web/tailwind.js +1 -1
- package/lib/xmlfile.js +1 -1
- package/lib/yaml.js +1 -1
- package/node_modules/cliui/CHANGELOG.md +18 -0
- package/node_modules/cliui/build/index.d.cts +43 -0
- package/node_modules/cliui/package.json +6 -6
- package/node_modules/yargs/README.md +8 -6
- package/node_modules/yargs/browser.d.ts +5 -0
- package/node_modules/yargs/browser.mjs +2 -2
- package/node_modules/yargs/build/index.cjs +1 -2920
- package/node_modules/yargs/build/lib/command.js +277 -210
- package/node_modules/yargs/build/lib/completion-templates.js +5 -4
- package/node_modules/yargs/build/lib/completion.js +201 -86
- package/node_modules/yargs/build/lib/middleware.js +51 -16
- package/node_modules/yargs/build/lib/usage.js +88 -52
- package/node_modules/yargs/build/lib/utils/levenshtein.js +9 -1
- package/node_modules/yargs/build/lib/utils/maybe-async-result.js +17 -0
- package/node_modules/yargs/build/lib/validation.js +51 -54
- package/node_modules/yargs/build/lib/yargs-factory.js +1253 -884
- package/node_modules/yargs/build/lib/yerror.js +3 -1
- package/node_modules/yargs/index.cjs +22 -8
- package/node_modules/yargs/index.mjs +2 -2
- package/node_modules/yargs/lib/platform-shims/browser.mjs +3 -0
- package/node_modules/yargs/lib/platform-shims/esm.mjs +9 -3
- package/node_modules/yargs/locales/cs.json +51 -0
- package/node_modules/yargs/locales/en.json +4 -0
- package/node_modules/yargs/locales/fi.json +1 -1
- package/node_modules/yargs/locales/ko.json +25 -25
- package/node_modules/yargs/locales/ru.json +6 -1
- package/node_modules/yargs/locales/uk_UA.json +51 -0
- package/node_modules/yargs/locales/uz.json +52 -0
- package/node_modules/yargs/locales/zh_TW.json +50 -46
- package/node_modules/{yargs-parser → yargs/node_modules/yargs-parser}/CHANGELOG.md +45 -0
- package/node_modules/{yargs-parser → yargs/node_modules/yargs-parser}/build/index.cjs +25 -17
- package/node_modules/{yargs-parser → yargs/node_modules/yargs-parser}/build/lib/index.js +8 -5
- package/node_modules/{yargs-parser → yargs/node_modules/yargs-parser}/build/lib/yargs-parser.js +20 -12
- package/node_modules/{yargs-parser → yargs/node_modules/yargs-parser}/package.json +14 -9
- package/node_modules/yargs/package.json +25 -24
- package/node_modules/yargs/yargs.mjs +10 -0
- package/package.json +2 -2
- package/node_modules/yargs/CHANGELOG.md +0 -88
- /package/node_modules/{yargs-parser → yargs/node_modules/yargs-parser}/LICENSE.txt +0 -0
- /package/node_modules/{yargs-parser → yargs/node_modules/yargs-parser}/README.md +0 -0
- /package/node_modules/{yargs-parser → yargs/node_modules/yargs-parser}/browser.js +0 -0
- /package/node_modules/{yargs-parser → yargs/node_modules/yargs-parser}/build/lib/string-utils.js +0 -0
- /package/node_modules/{yargs-parser → yargs/node_modules/yargs-parser}/build/lib/tokenize-arg-string.js +0 -0
- /package/node_modules/{yargs-parser → yargs/node_modules/yargs-parser}/build/lib/yargs-parser-types.js +0 -0
|
@@ -3,68 +3,52 @@ import { assertNotStrictEqual } from './typings/common-types.js';
|
|
|
3
3
|
import * as templates from './completion-templates.js';
|
|
4
4
|
import { isPromise } from './utils/is-promise.js';
|
|
5
5
|
import { parseCommand } from './parse-command.js';
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (isSyncCompletionFunction(completionFunction)) {
|
|
24
|
-
const result = completionFunction(current, argv);
|
|
25
|
-
if (isPromise(result)) {
|
|
26
|
-
return result
|
|
27
|
-
.then(list => {
|
|
28
|
-
shim.process.nextTick(() => {
|
|
29
|
-
done(list);
|
|
30
|
-
});
|
|
31
|
-
})
|
|
32
|
-
.catch(err => {
|
|
33
|
-
shim.process.nextTick(() => {
|
|
34
|
-
throw err;
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
return done(result);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
return completionFunction(current, argv, completions => {
|
|
42
|
-
done(completions);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (completionFunction) {
|
|
47
|
-
return isPromise(argv)
|
|
48
|
-
? argv.then(runCompletionFunction)
|
|
49
|
-
: runCompletionFunction(argv);
|
|
50
|
-
}
|
|
51
|
-
const handlers = command.getCommandHandlers();
|
|
6
|
+
export class Completion {
|
|
7
|
+
constructor(yargs, usage, command, shim) {
|
|
8
|
+
var _a, _b, _c;
|
|
9
|
+
this.yargs = yargs;
|
|
10
|
+
this.usage = usage;
|
|
11
|
+
this.command = command;
|
|
12
|
+
this.shim = shim;
|
|
13
|
+
this.completionKey = 'get-yargs-completions';
|
|
14
|
+
this.aliases = null;
|
|
15
|
+
this.customCompletionFunction = null;
|
|
16
|
+
this.indexAfterLastReset = 0;
|
|
17
|
+
this.zshShell =
|
|
18
|
+
(_c = (((_a = this.shim.getEnv('SHELL')) === null || _a === void 0 ? void 0 : _a.includes('zsh')) ||
|
|
19
|
+
((_b = this.shim.getEnv('ZSH_NAME')) === null || _b === void 0 ? void 0 : _b.includes('zsh')))) !== null && _c !== void 0 ? _c : false;
|
|
20
|
+
}
|
|
21
|
+
defaultCompletion(args, argv, current, done) {
|
|
22
|
+
const handlers = this.command.getCommandHandlers();
|
|
52
23
|
for (let i = 0, ii = args.length; i < ii; ++i) {
|
|
53
24
|
if (handlers[args[i]] && handlers[args[i]].builder) {
|
|
54
25
|
const builder = handlers[args[i]].builder;
|
|
55
26
|
if (isCommandBuilderCallback(builder)) {
|
|
56
|
-
|
|
57
|
-
|
|
27
|
+
this.indexAfterLastReset = i + 1;
|
|
28
|
+
const y = this.yargs.getInternalMethods().reset();
|
|
29
|
+
builder(y, true);
|
|
58
30
|
return y.argv;
|
|
59
31
|
}
|
|
60
32
|
}
|
|
61
33
|
}
|
|
34
|
+
const completions = [];
|
|
35
|
+
this.commandCompletions(completions, args, current);
|
|
36
|
+
this.optionCompletions(completions, args, argv, current);
|
|
37
|
+
this.choicesFromOptionsCompletions(completions, args, argv, current);
|
|
38
|
+
this.choicesFromPositionalsCompletions(completions, args, argv, current);
|
|
39
|
+
done(null, completions);
|
|
40
|
+
}
|
|
41
|
+
commandCompletions(completions, args, current) {
|
|
42
|
+
const parentCommands = this.yargs
|
|
43
|
+
.getInternalMethods()
|
|
44
|
+
.getContext().commands;
|
|
62
45
|
if (!current.match(/^-/) &&
|
|
63
|
-
parentCommands[parentCommands.length - 1] !== current
|
|
64
|
-
|
|
46
|
+
parentCommands[parentCommands.length - 1] !== current &&
|
|
47
|
+
!this.previousArgHasChoices(args)) {
|
|
48
|
+
this.usage.getCommands().forEach(usageCommand => {
|
|
65
49
|
const commandName = parseCommand(usageCommand[0]).cmd;
|
|
66
50
|
if (args.indexOf(commandName) === -1) {
|
|
67
|
-
if (!zshShell) {
|
|
51
|
+
if (!this.zshShell) {
|
|
68
52
|
completions.push(commandName);
|
|
69
53
|
}
|
|
70
54
|
else {
|
|
@@ -74,55 +58,186 @@ export function completion(yargs, usage, command, shim) {
|
|
|
74
58
|
}
|
|
75
59
|
});
|
|
76
60
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
61
|
+
}
|
|
62
|
+
optionCompletions(completions, args, argv, current) {
|
|
63
|
+
if ((current.match(/^-/) || (current === '' && completions.length === 0)) &&
|
|
64
|
+
!this.previousArgHasChoices(args)) {
|
|
65
|
+
const options = this.yargs.getOptions();
|
|
66
|
+
const positionalKeys = this.yargs.getGroups()[this.usage.getPositionalGroupName()] || [];
|
|
80
67
|
Object.keys(options.key).forEach(key => {
|
|
81
68
|
const negable = !!options.configuration['boolean-negation'] &&
|
|
82
69
|
options.boolean.includes(key);
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (notInArgs) {
|
|
89
|
-
const startsByTwoDashes = (s) => /^--/.test(s);
|
|
90
|
-
const isShortOption = (s) => /^[^0-9]$/.test(s);
|
|
91
|
-
const dashes = !startsByTwoDashes(current) && isShortOption(key) ? '-' : '--';
|
|
92
|
-
if (!zshShell) {
|
|
93
|
-
completions.push(dashes + key);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
const desc = descs[key] || '';
|
|
97
|
-
completions.push(dashes +
|
|
98
|
-
`${key.replace(/:/g, '\\:')}:${desc.replace('__yargsString__:', '')}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
70
|
+
const isPositionalKey = positionalKeys.includes(key);
|
|
71
|
+
if (!isPositionalKey &&
|
|
72
|
+
!options.hiddenOptions.includes(key) &&
|
|
73
|
+
!this.argsContainKey(args, key, negable)) {
|
|
74
|
+
this.completeOptionKey(key, completions, current, negable && !!options.default[key]);
|
|
101
75
|
}
|
|
102
|
-
completeOptionKey(key);
|
|
103
|
-
if (negable && !!options.default[key])
|
|
104
|
-
completeOptionKey(`no-${key}`);
|
|
105
76
|
});
|
|
106
77
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
78
|
+
}
|
|
79
|
+
choicesFromOptionsCompletions(completions, args, argv, current) {
|
|
80
|
+
if (this.previousArgHasChoices(args)) {
|
|
81
|
+
const choices = this.getPreviousArgChoices(args);
|
|
82
|
+
if (choices && choices.length > 0) {
|
|
83
|
+
completions.push(...choices.map(c => c.replace(/:/g, '\\:')));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
choicesFromPositionalsCompletions(completions, args, argv, current) {
|
|
88
|
+
if (current === '' &&
|
|
89
|
+
completions.length > 0 &&
|
|
90
|
+
this.previousArgHasChoices(args)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const positionalKeys = this.yargs.getGroups()[this.usage.getPositionalGroupName()] || [];
|
|
94
|
+
const offset = Math.max(this.indexAfterLastReset, this.yargs.getInternalMethods().getContext().commands.length +
|
|
95
|
+
1);
|
|
96
|
+
const positionalKey = positionalKeys[argv._.length - offset - 1];
|
|
97
|
+
if (!positionalKey) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const choices = this.yargs.getOptions().choices[positionalKey] || [];
|
|
101
|
+
for (const choice of choices) {
|
|
102
|
+
if (choice.startsWith(current)) {
|
|
103
|
+
completions.push(choice.replace(/:/g, '\\:'));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
getPreviousArgChoices(args) {
|
|
108
|
+
if (args.length < 1)
|
|
109
|
+
return;
|
|
110
|
+
let previousArg = args[args.length - 1];
|
|
111
|
+
let filter = '';
|
|
112
|
+
if (!previousArg.startsWith('-') && args.length > 1) {
|
|
113
|
+
filter = previousArg;
|
|
114
|
+
previousArg = args[args.length - 2];
|
|
115
|
+
}
|
|
116
|
+
if (!previousArg.startsWith('-'))
|
|
117
|
+
return;
|
|
118
|
+
const previousArgKey = previousArg.replace(/^-+/, '');
|
|
119
|
+
const options = this.yargs.getOptions();
|
|
120
|
+
const possibleAliases = [
|
|
121
|
+
previousArgKey,
|
|
122
|
+
...(this.yargs.getAliases()[previousArgKey] || []),
|
|
123
|
+
];
|
|
124
|
+
let choices;
|
|
125
|
+
for (const possibleAlias of possibleAliases) {
|
|
126
|
+
if (Object.prototype.hasOwnProperty.call(options.key, possibleAlias) &&
|
|
127
|
+
Array.isArray(options.choices[possibleAlias])) {
|
|
128
|
+
choices = options.choices[possibleAlias];
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (choices) {
|
|
133
|
+
return choices.filter(choice => !filter || choice.startsWith(filter));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
previousArgHasChoices(args) {
|
|
137
|
+
const choices = this.getPreviousArgChoices(args);
|
|
138
|
+
return choices !== undefined && choices.length > 0;
|
|
139
|
+
}
|
|
140
|
+
argsContainKey(args, key, negable) {
|
|
141
|
+
const argsContains = (s) => args.indexOf((/^[^0-9]$/.test(s) ? '-' : '--') + s) !== -1;
|
|
142
|
+
if (argsContains(key))
|
|
143
|
+
return true;
|
|
144
|
+
if (negable && argsContains(`no-${key}`))
|
|
145
|
+
return true;
|
|
146
|
+
if (this.aliases) {
|
|
147
|
+
for (const alias of this.aliases[key]) {
|
|
148
|
+
if (argsContains(alias))
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
completeOptionKey(key, completions, current, negable) {
|
|
155
|
+
var _a, _b, _c, _d;
|
|
156
|
+
let keyWithDesc = key;
|
|
157
|
+
if (this.zshShell) {
|
|
158
|
+
const descs = this.usage.getDescriptions();
|
|
159
|
+
const aliasKey = (_b = (_a = this === null || this === void 0 ? void 0 : this.aliases) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b.find(alias => {
|
|
160
|
+
const desc = descs[alias];
|
|
161
|
+
return typeof desc === 'string' && desc.length > 0;
|
|
162
|
+
});
|
|
163
|
+
const descFromAlias = aliasKey ? descs[aliasKey] : undefined;
|
|
164
|
+
const desc = (_d = (_c = descs[key]) !== null && _c !== void 0 ? _c : descFromAlias) !== null && _d !== void 0 ? _d : '';
|
|
165
|
+
keyWithDesc = `${key.replace(/:/g, '\\:')}:${desc
|
|
166
|
+
.replace('__yargsString__:', '')
|
|
167
|
+
.replace(/(\r\n|\n|\r)/gm, ' ')}`;
|
|
168
|
+
}
|
|
169
|
+
const startsByTwoDashes = (s) => /^--/.test(s);
|
|
170
|
+
const isShortOption = (s) => /^[^0-9]$/.test(s);
|
|
171
|
+
const dashes = !startsByTwoDashes(current) && isShortOption(key) ? '-' : '--';
|
|
172
|
+
completions.push(dashes + keyWithDesc);
|
|
173
|
+
if (negable) {
|
|
174
|
+
completions.push(dashes + 'no-' + keyWithDesc);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
customCompletion(args, argv, current, done) {
|
|
178
|
+
assertNotStrictEqual(this.customCompletionFunction, null, this.shim);
|
|
179
|
+
if (isSyncCompletionFunction(this.customCompletionFunction)) {
|
|
180
|
+
const result = this.customCompletionFunction(current, argv);
|
|
181
|
+
if (isPromise(result)) {
|
|
182
|
+
return result
|
|
183
|
+
.then(list => {
|
|
184
|
+
this.shim.process.nextTick(() => {
|
|
185
|
+
done(null, list);
|
|
186
|
+
});
|
|
187
|
+
})
|
|
188
|
+
.catch(err => {
|
|
189
|
+
this.shim.process.nextTick(() => {
|
|
190
|
+
done(err, undefined);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return done(null, result);
|
|
195
|
+
}
|
|
196
|
+
else if (isFallbackCompletionFunction(this.customCompletionFunction)) {
|
|
197
|
+
return this.customCompletionFunction(current, argv, (onCompleted = done) => this.defaultCompletion(args, argv, current, onCompleted), completions => {
|
|
198
|
+
done(null, completions);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
return this.customCompletionFunction(current, argv, completions => {
|
|
203
|
+
done(null, completions);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
getCompletion(args, done) {
|
|
208
|
+
const current = args.length ? args[args.length - 1] : '';
|
|
209
|
+
const argv = this.yargs.parse(args, true);
|
|
210
|
+
const completionFunction = this.customCompletionFunction
|
|
211
|
+
? (argv) => this.customCompletion(args, argv, current, done)
|
|
212
|
+
: (argv) => this.defaultCompletion(args, argv, current, done);
|
|
213
|
+
return isPromise(argv)
|
|
214
|
+
? argv.then(completionFunction)
|
|
215
|
+
: completionFunction(argv);
|
|
216
|
+
}
|
|
217
|
+
generateCompletionScript($0, cmd) {
|
|
218
|
+
let script = this.zshShell
|
|
111
219
|
? templates.completionZshTemplate
|
|
112
220
|
: templates.completionShTemplate;
|
|
113
|
-
const name = shim.path.basename($0);
|
|
221
|
+
const name = this.shim.path.basename($0);
|
|
114
222
|
if ($0.match(/\.js$/))
|
|
115
223
|
$0 = `./${$0}`;
|
|
116
224
|
script = script.replace(/{{app_name}}/g, name);
|
|
117
225
|
script = script.replace(/{{completion_command}}/g, cmd);
|
|
118
226
|
return script.replace(/{{app_path}}/g, $0);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
227
|
+
}
|
|
228
|
+
registerFunction(fn) {
|
|
229
|
+
this.customCompletionFunction = fn;
|
|
230
|
+
}
|
|
231
|
+
setParsed(parsed) {
|
|
232
|
+
this.aliases = parsed.aliases;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
export function completion(yargs, usage, command, shim) {
|
|
236
|
+
return new Completion(yargs, usage, command, shim);
|
|
125
237
|
}
|
|
126
238
|
function isSyncCompletionFunction(completionFunction) {
|
|
127
239
|
return completionFunction.length < 3;
|
|
128
240
|
}
|
|
241
|
+
function isFallbackCompletionFunction(completionFunction) {
|
|
242
|
+
return completionFunction.length > 3;
|
|
243
|
+
}
|
|
@@ -1,23 +1,59 @@
|
|
|
1
1
|
import { argsert } from './argsert.js';
|
|
2
2
|
import { isPromise } from './utils/is-promise.js';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export class GlobalMiddleware {
|
|
4
|
+
constructor(yargs) {
|
|
5
|
+
this.globalMiddleware = [];
|
|
6
|
+
this.frozens = [];
|
|
7
|
+
this.yargs = yargs;
|
|
8
|
+
}
|
|
9
|
+
addMiddleware(callback, applyBeforeValidation, global = true, mutates = false) {
|
|
10
|
+
argsert('<array|function> [boolean] [boolean] [boolean]', [callback, applyBeforeValidation, global], arguments.length);
|
|
6
11
|
if (Array.isArray(callback)) {
|
|
7
12
|
for (let i = 0; i < callback.length; i++) {
|
|
8
13
|
if (typeof callback[i] !== 'function') {
|
|
9
14
|
throw Error('middleware must be a function');
|
|
10
15
|
}
|
|
11
|
-
callback[i]
|
|
16
|
+
const m = callback[i];
|
|
17
|
+
m.applyBeforeValidation = applyBeforeValidation;
|
|
18
|
+
m.global = global;
|
|
12
19
|
}
|
|
13
|
-
Array.prototype.push.apply(globalMiddleware, callback);
|
|
20
|
+
Array.prototype.push.apply(this.globalMiddleware, callback);
|
|
14
21
|
}
|
|
15
22
|
else if (typeof callback === 'function') {
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
const m = callback;
|
|
24
|
+
m.applyBeforeValidation = applyBeforeValidation;
|
|
25
|
+
m.global = global;
|
|
26
|
+
m.mutates = mutates;
|
|
27
|
+
this.globalMiddleware.push(callback);
|
|
18
28
|
}
|
|
19
|
-
return
|
|
20
|
-
}
|
|
29
|
+
return this.yargs;
|
|
30
|
+
}
|
|
31
|
+
addCoerceMiddleware(callback, option) {
|
|
32
|
+
const aliases = this.yargs.getAliases();
|
|
33
|
+
this.globalMiddleware = this.globalMiddleware.filter(m => {
|
|
34
|
+
const toCheck = [...(aliases[option] || []), option];
|
|
35
|
+
if (!m.option)
|
|
36
|
+
return true;
|
|
37
|
+
else
|
|
38
|
+
return !toCheck.includes(m.option);
|
|
39
|
+
});
|
|
40
|
+
callback.option = option;
|
|
41
|
+
return this.addMiddleware(callback, true, true, true);
|
|
42
|
+
}
|
|
43
|
+
getMiddleware() {
|
|
44
|
+
return this.globalMiddleware;
|
|
45
|
+
}
|
|
46
|
+
freeze() {
|
|
47
|
+
this.frozens.push([...this.globalMiddleware]);
|
|
48
|
+
}
|
|
49
|
+
unfreeze() {
|
|
50
|
+
const frozen = this.frozens.pop();
|
|
51
|
+
if (frozen !== undefined)
|
|
52
|
+
this.globalMiddleware = frozen;
|
|
53
|
+
}
|
|
54
|
+
reset() {
|
|
55
|
+
this.globalMiddleware = this.globalMiddleware.filter(m => m.global);
|
|
56
|
+
}
|
|
21
57
|
}
|
|
22
58
|
export function commandMiddlewareFactory(commandMiddleware) {
|
|
23
59
|
if (!commandMiddleware)
|
|
@@ -28,23 +64,22 @@ export function commandMiddlewareFactory(commandMiddleware) {
|
|
|
28
64
|
});
|
|
29
65
|
}
|
|
30
66
|
export function applyMiddleware(argv, yargs, middlewares, beforeValidation) {
|
|
31
|
-
const beforeValidationError = new Error('middleware cannot return a promise when applyBeforeValidation is true');
|
|
32
67
|
return middlewares.reduce((acc, middleware) => {
|
|
33
68
|
if (middleware.applyBeforeValidation !== beforeValidation) {
|
|
34
69
|
return acc;
|
|
35
70
|
}
|
|
71
|
+
if (middleware.mutates) {
|
|
72
|
+
if (middleware.applied)
|
|
73
|
+
return acc;
|
|
74
|
+
middleware.applied = true;
|
|
75
|
+
}
|
|
36
76
|
if (isPromise(acc)) {
|
|
37
77
|
return acc
|
|
38
|
-
.then(initialObj => Promise.all([
|
|
39
|
-
initialObj,
|
|
40
|
-
middleware(initialObj, yargs),
|
|
41
|
-
]))
|
|
78
|
+
.then(initialObj => Promise.all([initialObj, middleware(initialObj, yargs)]))
|
|
42
79
|
.then(([initialObj, middlewareObj]) => Object.assign(initialObj, middlewareObj));
|
|
43
80
|
}
|
|
44
81
|
else {
|
|
45
82
|
const result = middleware(acc, yargs);
|
|
46
|
-
if (beforeValidation && isPromise(result))
|
|
47
|
-
throw beforeValidationError;
|
|
48
83
|
return isPromise(result)
|
|
49
84
|
? result.then(middlewareObj => Object.assign(acc, middlewareObj))
|
|
50
85
|
: Object.assign(acc, result);
|