projen 0.71.37 → 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,14 +3,41 @@ import { isPromise } from './utils/is-promise.js';
|
|
|
3
3
|
import { applyMiddleware, commandMiddlewareFactory, } from './middleware.js';
|
|
4
4
|
import { parseCommand } from './parse-command.js';
|
|
5
5
|
import { isYargsInstance, } from './yargs-factory.js';
|
|
6
|
+
import { maybeAsyncResult } from './utils/maybe-async-result.js';
|
|
6
7
|
import whichModule from './utils/which-module.js';
|
|
7
8
|
const DEFAULT_MARKER = /(^\*)|(^\$0)/;
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
export class CommandInstance {
|
|
10
|
+
constructor(usage, validation, globalMiddleware, shim) {
|
|
11
|
+
this.requireCache = new Set();
|
|
12
|
+
this.handlers = {};
|
|
13
|
+
this.aliasMap = {};
|
|
14
|
+
this.frozens = [];
|
|
15
|
+
this.shim = shim;
|
|
16
|
+
this.usage = usage;
|
|
17
|
+
this.globalMiddleware = globalMiddleware;
|
|
18
|
+
this.validation = validation;
|
|
19
|
+
}
|
|
20
|
+
addDirectory(dir, req, callerFile, opts) {
|
|
21
|
+
opts = opts || {};
|
|
22
|
+
if (typeof opts.recurse !== 'boolean')
|
|
23
|
+
opts.recurse = false;
|
|
24
|
+
if (!Array.isArray(opts.extensions))
|
|
25
|
+
opts.extensions = ['js'];
|
|
26
|
+
const parentVisit = typeof opts.visit === 'function' ? opts.visit : (o) => o;
|
|
27
|
+
opts.visit = (obj, joined, filename) => {
|
|
28
|
+
const visited = parentVisit(obj, joined, filename);
|
|
29
|
+
if (visited) {
|
|
30
|
+
if (this.requireCache.has(joined))
|
|
31
|
+
return visited;
|
|
32
|
+
else
|
|
33
|
+
this.requireCache.add(joined);
|
|
34
|
+
this.addHandler(visited);
|
|
35
|
+
}
|
|
36
|
+
return visited;
|
|
37
|
+
};
|
|
38
|
+
this.shim.requireDirectory({ require: req, filename: callerFile }, dir, opts);
|
|
39
|
+
}
|
|
40
|
+
addHandler(cmd, description, builder, handler, commandMiddleware, deprecated) {
|
|
14
41
|
let aliases = [];
|
|
15
42
|
const middlewares = commandMiddlewareFactory(commandMiddleware);
|
|
16
43
|
handler = handler || (() => { });
|
|
@@ -20,21 +47,21 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
20
47
|
}
|
|
21
48
|
else {
|
|
22
49
|
for (const command of cmd) {
|
|
23
|
-
|
|
50
|
+
this.addHandler(command);
|
|
24
51
|
}
|
|
25
52
|
}
|
|
26
53
|
}
|
|
27
54
|
else if (isCommandHandlerDefinition(cmd)) {
|
|
28
55
|
let command = Array.isArray(cmd.command) || typeof cmd.command === 'string'
|
|
29
56
|
? cmd.command
|
|
30
|
-
: moduleName(cmd);
|
|
57
|
+
: this.moduleName(cmd);
|
|
31
58
|
if (cmd.aliases)
|
|
32
59
|
command = [].concat(command).concat(cmd.aliases);
|
|
33
|
-
|
|
60
|
+
this.addHandler(command, this.extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares, cmd.deprecated);
|
|
34
61
|
return;
|
|
35
62
|
}
|
|
36
63
|
else if (isCommandBuilderDefinition(builder)) {
|
|
37
|
-
|
|
64
|
+
this.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler, builder.middlewares, builder.deprecated);
|
|
38
65
|
return;
|
|
39
66
|
}
|
|
40
67
|
if (typeof cmd === 'string') {
|
|
@@ -56,12 +83,12 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
56
83
|
cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd);
|
|
57
84
|
}
|
|
58
85
|
aliases.forEach(alias => {
|
|
59
|
-
aliasMap[alias] = parsedCommand.cmd;
|
|
86
|
+
this.aliasMap[alias] = parsedCommand.cmd;
|
|
60
87
|
});
|
|
61
88
|
if (description !== false) {
|
|
62
|
-
usage.command(cmd, description, isDefault, aliases, deprecated);
|
|
89
|
+
this.usage.command(cmd, description, isDefault, aliases, deprecated);
|
|
63
90
|
}
|
|
64
|
-
handlers[parsedCommand.cmd] = {
|
|
91
|
+
this.handlers[parsedCommand.cmd] = {
|
|
65
92
|
original: cmd,
|
|
66
93
|
description,
|
|
67
94
|
handler,
|
|
@@ -72,193 +99,170 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
72
99
|
optional: parsedCommand.optional,
|
|
73
100
|
};
|
|
74
101
|
if (isDefault)
|
|
75
|
-
defaultCommand = handlers[parsedCommand.cmd];
|
|
102
|
+
this.defaultCommand = this.handlers[parsedCommand.cmd];
|
|
76
103
|
}
|
|
77
|
-
};
|
|
78
|
-
self.addDirectory = function addDirectory(dir, context, req, callerFile, opts) {
|
|
79
|
-
opts = opts || {};
|
|
80
|
-
if (typeof opts.recurse !== 'boolean')
|
|
81
|
-
opts.recurse = false;
|
|
82
|
-
if (!Array.isArray(opts.extensions))
|
|
83
|
-
opts.extensions = ['js'];
|
|
84
|
-
const parentVisit = typeof opts.visit === 'function' ? opts.visit : (o) => o;
|
|
85
|
-
opts.visit = function visit(obj, joined, filename) {
|
|
86
|
-
const visited = parentVisit(obj, joined, filename);
|
|
87
|
-
if (visited) {
|
|
88
|
-
if (~context.files.indexOf(joined))
|
|
89
|
-
return visited;
|
|
90
|
-
context.files.push(joined);
|
|
91
|
-
self.addHandler(visited);
|
|
92
|
-
}
|
|
93
|
-
return visited;
|
|
94
|
-
};
|
|
95
|
-
shim.requireDirectory({ require: req, filename: callerFile }, dir, opts);
|
|
96
|
-
};
|
|
97
|
-
function moduleName(obj) {
|
|
98
|
-
const mod = whichModule(obj);
|
|
99
|
-
if (!mod)
|
|
100
|
-
throw new Error(`No command name given for module: ${shim.inspect(obj)}`);
|
|
101
|
-
return commandFromFilename(mod.filename);
|
|
102
104
|
}
|
|
103
|
-
|
|
104
|
-
return
|
|
105
|
+
getCommandHandlers() {
|
|
106
|
+
return this.handlers;
|
|
105
107
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
return false;
|
|
108
|
+
getCommands() {
|
|
109
|
+
return Object.keys(this.handlers).concat(Object.keys(this.aliasMap));
|
|
110
|
+
}
|
|
111
|
+
hasDefaultCommand() {
|
|
112
|
+
return !!this.defaultCommand;
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const commandHandler = handlers[command] || handlers[aliasMap[command]] || defaultCommand;
|
|
120
|
-
const currentContext = yargs.getContext();
|
|
121
|
-
let numFiles = currentContext.files.length;
|
|
114
|
+
runCommand(command, yargs, parsed, commandIndex, helpOnly, helpOrVersionSet) {
|
|
115
|
+
const commandHandler = this.handlers[command] ||
|
|
116
|
+
this.handlers[this.aliasMap[command]] ||
|
|
117
|
+
this.defaultCommand;
|
|
118
|
+
const currentContext = yargs.getInternalMethods().getContext();
|
|
122
119
|
const parentCommands = currentContext.commands.slice();
|
|
123
|
-
|
|
124
|
-
let positionalMap = {};
|
|
120
|
+
const isDefaultCommand = !command;
|
|
125
121
|
if (command) {
|
|
126
122
|
currentContext.commands.push(command);
|
|
127
123
|
currentContext.fullCommands.push(commandHandler.original);
|
|
128
124
|
}
|
|
125
|
+
const builderResult = this.applyBuilderUpdateUsageAndParse(isDefaultCommand, commandHandler, yargs, parsed.aliases, parentCommands, commandIndex, helpOnly, helpOrVersionSet);
|
|
126
|
+
return isPromise(builderResult)
|
|
127
|
+
? builderResult.then(result => this.applyMiddlewareAndGetResult(isDefaultCommand, commandHandler, result.innerArgv, currentContext, helpOnly, result.aliases, yargs))
|
|
128
|
+
: this.applyMiddlewareAndGetResult(isDefaultCommand, commandHandler, builderResult.innerArgv, currentContext, helpOnly, builderResult.aliases, yargs);
|
|
129
|
+
}
|
|
130
|
+
applyBuilderUpdateUsageAndParse(isDefaultCommand, commandHandler, yargs, aliases, parentCommands, commandIndex, helpOnly, helpOrVersionSet) {
|
|
129
131
|
const builder = commandHandler.builder;
|
|
132
|
+
let innerYargs = yargs;
|
|
130
133
|
if (isCommandBuilderCallback(builder)) {
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
.
|
|
134
|
+
yargs.getInternalMethods().getUsageInstance().freeze();
|
|
135
|
+
const builderOutput = builder(yargs.getInternalMethods().reset(aliases), helpOrVersionSet);
|
|
136
|
+
if (isPromise(builderOutput)) {
|
|
137
|
+
return builderOutput.then(output => {
|
|
138
|
+
innerYargs = isYargsInstance(output) ? output : yargs;
|
|
139
|
+
return this.parseAndUpdateUsage(isDefaultCommand, commandHandler, innerYargs, parentCommands, commandIndex, helpOnly);
|
|
140
|
+
});
|
|
137
141
|
}
|
|
138
|
-
innerArgv = innerYargs._parseArgs(null, null, true, commandIndex);
|
|
139
|
-
aliases = innerYargs.parsed.aliases;
|
|
140
142
|
}
|
|
141
143
|
else if (isCommandBuilderOptionDefinitions(builder)) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
innerYargs
|
|
145
|
-
.getUsageInstance()
|
|
146
|
-
.usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description);
|
|
147
|
-
}
|
|
144
|
+
yargs.getInternalMethods().getUsageInstance().freeze();
|
|
145
|
+
innerYargs = yargs.getInternalMethods().reset(aliases);
|
|
148
146
|
Object.keys(commandHandler.builder).forEach(key => {
|
|
149
147
|
innerYargs.option(key, builder[key]);
|
|
150
148
|
});
|
|
151
|
-
innerArgv = innerYargs._parseArgs(null, null, true, commandIndex);
|
|
152
|
-
aliases = innerYargs.parsed.aliases;
|
|
153
149
|
}
|
|
154
|
-
|
|
155
|
-
|
|
150
|
+
return this.parseAndUpdateUsage(isDefaultCommand, commandHandler, innerYargs, parentCommands, commandIndex, helpOnly);
|
|
151
|
+
}
|
|
152
|
+
parseAndUpdateUsage(isDefaultCommand, commandHandler, innerYargs, parentCommands, commandIndex, helpOnly) {
|
|
153
|
+
if (isDefaultCommand)
|
|
154
|
+
innerYargs.getInternalMethods().getUsageInstance().unfreeze(true);
|
|
155
|
+
if (this.shouldUpdateUsage(innerYargs)) {
|
|
156
|
+
innerYargs
|
|
157
|
+
.getInternalMethods()
|
|
158
|
+
.getUsageInstance()
|
|
159
|
+
.usage(this.usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description);
|
|
156
160
|
}
|
|
157
|
-
const
|
|
158
|
-
.
|
|
159
|
-
.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
const innerArgv = innerYargs
|
|
162
|
+
.getInternalMethods()
|
|
163
|
+
.runYargsParserAndExecuteCommands(null, undefined, true, commandIndex, helpOnly);
|
|
164
|
+
return isPromise(innerArgv)
|
|
165
|
+
? innerArgv.then(argv => ({
|
|
166
|
+
aliases: innerYargs.parsed.aliases,
|
|
167
|
+
innerArgv: argv,
|
|
168
|
+
}))
|
|
169
|
+
: {
|
|
170
|
+
aliases: innerYargs.parsed.aliases,
|
|
171
|
+
innerArgv: innerArgv,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
shouldUpdateUsage(yargs) {
|
|
175
|
+
return (!yargs.getInternalMethods().getUsageInstance().getUsageDisabled() &&
|
|
176
|
+
yargs.getInternalMethods().getUsageInstance().getUsage().length === 0);
|
|
177
|
+
}
|
|
178
|
+
usageFromParentCommandsCommandHandler(parentCommands, commandHandler) {
|
|
179
|
+
const c = DEFAULT_MARKER.test(commandHandler.original)
|
|
180
|
+
? commandHandler.original.replace(DEFAULT_MARKER, '').trim()
|
|
181
|
+
: commandHandler.original;
|
|
182
|
+
const pc = parentCommands.filter(c => {
|
|
183
|
+
return !DEFAULT_MARKER.test(c);
|
|
184
|
+
});
|
|
185
|
+
pc.push(c);
|
|
186
|
+
return `$0 ${pc.join(' ')}`;
|
|
187
|
+
}
|
|
188
|
+
handleValidationAndGetResult(isDefaultCommand, commandHandler, innerArgv, currentContext, aliases, yargs, middlewares, positionalMap) {
|
|
189
|
+
if (!yargs.getInternalMethods().getHasOutput()) {
|
|
190
|
+
const validation = yargs
|
|
191
|
+
.getInternalMethods()
|
|
192
|
+
.runValidation(aliases, positionalMap, yargs.parsed.error, isDefaultCommand);
|
|
193
|
+
innerArgv = maybeAsyncResult(innerArgv, result => {
|
|
194
|
+
validation(result);
|
|
195
|
+
return result;
|
|
196
|
+
});
|
|
163
197
|
}
|
|
164
|
-
if (commandHandler.handler && !yargs.
|
|
165
|
-
yargs.
|
|
198
|
+
if (commandHandler.handler && !yargs.getInternalMethods().getHasOutput()) {
|
|
199
|
+
yargs.getInternalMethods().setHasOutput();
|
|
166
200
|
const populateDoubleDash = !!yargs.getOptions().configuration['populate--'];
|
|
167
|
-
yargs
|
|
201
|
+
yargs
|
|
202
|
+
.getInternalMethods()
|
|
203
|
+
.postProcess(innerArgv, populateDoubleDash, false, false);
|
|
168
204
|
innerArgv = applyMiddleware(innerArgv, yargs, middlewares, false);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
205
|
+
innerArgv = maybeAsyncResult(innerArgv, result => {
|
|
206
|
+
const handlerResult = commandHandler.handler(result);
|
|
207
|
+
return isPromise(handlerResult)
|
|
208
|
+
? handlerResult.then(() => result)
|
|
209
|
+
: result;
|
|
210
|
+
});
|
|
211
|
+
if (!isDefaultCommand) {
|
|
212
|
+
yargs.getInternalMethods().getUsageInstance().cacheHelpMessage();
|
|
175
213
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
handlerResult
|
|
180
|
-
.then(value => {
|
|
181
|
-
if (handlerFinishCommand) {
|
|
182
|
-
handlerFinishCommand(value);
|
|
183
|
-
}
|
|
184
|
-
})
|
|
185
|
-
.catch(error => {
|
|
214
|
+
if (isPromise(innerArgv) &&
|
|
215
|
+
!yargs.getInternalMethods().hasParseCallback()) {
|
|
216
|
+
innerArgv.catch(error => {
|
|
186
217
|
try {
|
|
187
|
-
yargs.getUsageInstance().fail(null, error);
|
|
218
|
+
yargs.getInternalMethods().getUsageInstance().fail(null, error);
|
|
188
219
|
}
|
|
189
|
-
catch (
|
|
220
|
+
catch (_err) {
|
|
190
221
|
}
|
|
191
|
-
})
|
|
192
|
-
.then(() => {
|
|
193
|
-
yargs.getUsageInstance().clearCachedHelpMessage();
|
|
194
222
|
});
|
|
195
223
|
}
|
|
196
|
-
else {
|
|
197
|
-
if (handlerFinishCommand) {
|
|
198
|
-
handlerFinishCommand(handlerResult);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
224
|
}
|
|
202
|
-
if (
|
|
225
|
+
if (!isDefaultCommand) {
|
|
203
226
|
currentContext.commands.pop();
|
|
204
227
|
currentContext.fullCommands.pop();
|
|
205
228
|
}
|
|
206
|
-
numFiles = currentContext.files.length - numFiles;
|
|
207
|
-
if (numFiles > 0)
|
|
208
|
-
currentContext.files.splice(numFiles * -1, numFiles);
|
|
209
229
|
return innerArgv;
|
|
210
|
-
};
|
|
211
|
-
function shouldUpdateUsage(yargs) {
|
|
212
|
-
return (!yargs.getUsageInstance().getUsageDisabled() &&
|
|
213
|
-
yargs.getUsageInstance().getUsage().length === 0);
|
|
214
230
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
222
|
-
pc.push(c);
|
|
223
|
-
return `$0 ${pc.join(' ')}`;
|
|
224
|
-
}
|
|
225
|
-
self.runDefaultBuilderOn = function (yargs) {
|
|
226
|
-
assertNotStrictEqual(defaultCommand, undefined, shim);
|
|
227
|
-
if (shouldUpdateUsage(yargs)) {
|
|
228
|
-
const commandString = DEFAULT_MARKER.test(defaultCommand.original)
|
|
229
|
-
? defaultCommand.original
|
|
230
|
-
: defaultCommand.original.replace(/^[^[\]<>]*/, '$0 ');
|
|
231
|
-
yargs.getUsageInstance().usage(commandString, defaultCommand.description);
|
|
232
|
-
}
|
|
233
|
-
const builder = defaultCommand.builder;
|
|
234
|
-
if (isCommandBuilderCallback(builder)) {
|
|
235
|
-
builder(yargs);
|
|
236
|
-
}
|
|
237
|
-
else if (!isCommandBuilderDefinition(builder)) {
|
|
238
|
-
Object.keys(builder).forEach(key => {
|
|
239
|
-
yargs.option(key, builder[key]);
|
|
240
|
-
});
|
|
231
|
+
applyMiddlewareAndGetResult(isDefaultCommand, commandHandler, innerArgv, currentContext, helpOnly, aliases, yargs) {
|
|
232
|
+
let positionalMap = {};
|
|
233
|
+
if (helpOnly)
|
|
234
|
+
return innerArgv;
|
|
235
|
+
if (!yargs.getInternalMethods().getHasOutput()) {
|
|
236
|
+
positionalMap = this.populatePositionals(commandHandler, innerArgv, currentContext, yargs);
|
|
241
237
|
}
|
|
242
|
-
|
|
243
|
-
|
|
238
|
+
const middlewares = this.globalMiddleware
|
|
239
|
+
.getMiddleware()
|
|
240
|
+
.slice(0)
|
|
241
|
+
.concat(commandHandler.middlewares);
|
|
242
|
+
const maybePromiseArgv = applyMiddleware(innerArgv, yargs, middlewares, true);
|
|
243
|
+
return isPromise(maybePromiseArgv)
|
|
244
|
+
? maybePromiseArgv.then(resolvedInnerArgv => this.handleValidationAndGetResult(isDefaultCommand, commandHandler, resolvedInnerArgv, currentContext, aliases, yargs, middlewares, positionalMap))
|
|
245
|
+
: this.handleValidationAndGetResult(isDefaultCommand, commandHandler, maybePromiseArgv, currentContext, aliases, yargs, middlewares, positionalMap);
|
|
246
|
+
}
|
|
247
|
+
populatePositionals(commandHandler, argv, context, yargs) {
|
|
244
248
|
argv._ = argv._.slice(context.commands.length);
|
|
245
249
|
const demanded = commandHandler.demanded.slice(0);
|
|
246
250
|
const optional = commandHandler.optional.slice(0);
|
|
247
251
|
const positionalMap = {};
|
|
248
|
-
validation.positionalCount(demanded.length, argv._.length);
|
|
252
|
+
this.validation.positionalCount(demanded.length, argv._.length);
|
|
249
253
|
while (demanded.length) {
|
|
250
254
|
const demand = demanded.shift();
|
|
251
|
-
populatePositional(demand, argv, positionalMap);
|
|
255
|
+
this.populatePositional(demand, argv, positionalMap);
|
|
252
256
|
}
|
|
253
257
|
while (optional.length) {
|
|
254
258
|
const maybe = optional.shift();
|
|
255
|
-
populatePositional(maybe, argv, positionalMap);
|
|
259
|
+
this.populatePositional(maybe, argv, positionalMap);
|
|
256
260
|
}
|
|
257
261
|
argv._ = context.commands.concat(argv._.map(a => '' + a));
|
|
258
|
-
postProcessPositionals(argv, positionalMap,
|
|
262
|
+
this.postProcessPositionals(argv, positionalMap, this.cmdToParseOptions(commandHandler.original), yargs);
|
|
259
263
|
return positionalMap;
|
|
260
264
|
}
|
|
261
|
-
|
|
265
|
+
populatePositional(positional, argv, positionalMap) {
|
|
262
266
|
const cmd = positional.cmd[0];
|
|
263
267
|
if (positional.variadic) {
|
|
264
268
|
positionalMap[cmd] = argv._.splice(0).map(String);
|
|
@@ -268,7 +272,34 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
268
272
|
positionalMap[cmd] = [String(argv._.shift())];
|
|
269
273
|
}
|
|
270
274
|
}
|
|
271
|
-
|
|
275
|
+
cmdToParseOptions(cmdString) {
|
|
276
|
+
const parseOptions = {
|
|
277
|
+
array: [],
|
|
278
|
+
default: {},
|
|
279
|
+
alias: {},
|
|
280
|
+
demand: {},
|
|
281
|
+
};
|
|
282
|
+
const parsed = parseCommand(cmdString);
|
|
283
|
+
parsed.demanded.forEach(d => {
|
|
284
|
+
const [cmd, ...aliases] = d.cmd;
|
|
285
|
+
if (d.variadic) {
|
|
286
|
+
parseOptions.array.push(cmd);
|
|
287
|
+
parseOptions.default[cmd] = [];
|
|
288
|
+
}
|
|
289
|
+
parseOptions.alias[cmd] = aliases;
|
|
290
|
+
parseOptions.demand[cmd] = true;
|
|
291
|
+
});
|
|
292
|
+
parsed.optional.forEach(o => {
|
|
293
|
+
const [cmd, ...aliases] = o.cmd;
|
|
294
|
+
if (o.variadic) {
|
|
295
|
+
parseOptions.array.push(cmd);
|
|
296
|
+
parseOptions.default[cmd] = [];
|
|
297
|
+
}
|
|
298
|
+
parseOptions.alias[cmd] = aliases;
|
|
299
|
+
});
|
|
300
|
+
return parseOptions;
|
|
301
|
+
}
|
|
302
|
+
postProcessPositionals(argv, positionalMap, parseOptions, yargs) {
|
|
272
303
|
const options = Object.assign({}, yargs.getOptions());
|
|
273
304
|
options.default = Object.assign(parseOptions.default, options.default);
|
|
274
305
|
for (const key of Object.keys(parseOptions.alias)) {
|
|
@@ -288,13 +319,16 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
288
319
|
if (!unparsed.length)
|
|
289
320
|
return;
|
|
290
321
|
const config = Object.assign({}, options.configuration, {
|
|
291
|
-
'populate--':
|
|
322
|
+
'populate--': false,
|
|
292
323
|
});
|
|
293
|
-
const parsed = shim.Parser.detailed(unparsed, Object.assign({}, options, {
|
|
324
|
+
const parsed = this.shim.Parser.detailed(unparsed, Object.assign({}, options, {
|
|
294
325
|
configuration: config,
|
|
295
326
|
}));
|
|
296
327
|
if (parsed.error) {
|
|
297
|
-
yargs
|
|
328
|
+
yargs
|
|
329
|
+
.getInternalMethods()
|
|
330
|
+
.getUsageInstance()
|
|
331
|
+
.fail(parsed.error.message, parsed.error);
|
|
298
332
|
}
|
|
299
333
|
else {
|
|
300
334
|
const positionalKeys = Object.keys(positionalMap);
|
|
@@ -302,61 +336,99 @@ export function command(yargs, usage, validation, globalMiddleware = [], shim) {
|
|
|
302
336
|
positionalKeys.push(...parsed.aliases[key]);
|
|
303
337
|
});
|
|
304
338
|
Object.keys(parsed.argv).forEach(key => {
|
|
305
|
-
if (positionalKeys.
|
|
339
|
+
if (positionalKeys.includes(key)) {
|
|
306
340
|
if (!positionalMap[key])
|
|
307
341
|
positionalMap[key] = parsed.argv[key];
|
|
308
|
-
|
|
342
|
+
if (!this.isInConfigs(yargs, key) &&
|
|
343
|
+
!this.isDefaulted(yargs, key) &&
|
|
344
|
+
Object.prototype.hasOwnProperty.call(argv, key) &&
|
|
345
|
+
Object.prototype.hasOwnProperty.call(parsed.argv, key) &&
|
|
346
|
+
(Array.isArray(argv[key]) || Array.isArray(parsed.argv[key]))) {
|
|
347
|
+
argv[key] = [].concat(argv[key], parsed.argv[key]);
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
argv[key] = parsed.argv[key];
|
|
351
|
+
}
|
|
309
352
|
}
|
|
310
353
|
});
|
|
311
354
|
}
|
|
312
355
|
}
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
return
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
356
|
+
isDefaulted(yargs, key) {
|
|
357
|
+
const { default: defaults } = yargs.getOptions();
|
|
358
|
+
return (Object.prototype.hasOwnProperty.call(defaults, key) ||
|
|
359
|
+
Object.prototype.hasOwnProperty.call(defaults, this.shim.Parser.camelCase(key)));
|
|
360
|
+
}
|
|
361
|
+
isInConfigs(yargs, key) {
|
|
362
|
+
const { configObjects } = yargs.getOptions();
|
|
363
|
+
return (configObjects.some(c => Object.prototype.hasOwnProperty.call(c, key)) ||
|
|
364
|
+
configObjects.some(c => Object.prototype.hasOwnProperty.call(c, this.shim.Parser.camelCase(key))));
|
|
365
|
+
}
|
|
366
|
+
runDefaultBuilderOn(yargs) {
|
|
367
|
+
if (!this.defaultCommand)
|
|
368
|
+
return;
|
|
369
|
+
if (this.shouldUpdateUsage(yargs)) {
|
|
370
|
+
const commandString = DEFAULT_MARKER.test(this.defaultCommand.original)
|
|
371
|
+
? this.defaultCommand.original
|
|
372
|
+
: this.defaultCommand.original.replace(/^[^[\]<>]*/, '$0 ');
|
|
373
|
+
yargs
|
|
374
|
+
.getInternalMethods()
|
|
375
|
+
.getUsageInstance()
|
|
376
|
+
.usage(commandString, this.defaultCommand.description);
|
|
377
|
+
}
|
|
378
|
+
const builder = this.defaultCommand.builder;
|
|
379
|
+
if (isCommandBuilderCallback(builder)) {
|
|
380
|
+
return builder(yargs, true);
|
|
381
|
+
}
|
|
382
|
+
else if (!isCommandBuilderDefinition(builder)) {
|
|
383
|
+
Object.keys(builder).forEach(key => {
|
|
384
|
+
yargs.option(key, builder[key]);
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
return undefined;
|
|
388
|
+
}
|
|
389
|
+
moduleName(obj) {
|
|
390
|
+
const mod = whichModule(obj);
|
|
391
|
+
if (!mod)
|
|
392
|
+
throw new Error(`No command name given for module: ${this.shim.inspect(obj)}`);
|
|
393
|
+
return this.commandFromFilename(mod.filename);
|
|
394
|
+
}
|
|
395
|
+
commandFromFilename(filename) {
|
|
396
|
+
return this.shim.path.basename(filename, this.shim.path.extname(filename));
|
|
397
|
+
}
|
|
398
|
+
extractDesc({ describe, description, desc }) {
|
|
399
|
+
for (const test of [describe, description, desc]) {
|
|
400
|
+
if (typeof test === 'string' || test === false)
|
|
401
|
+
return test;
|
|
402
|
+
assertNotStrictEqual(test, true, this.shim);
|
|
403
|
+
}
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
freeze() {
|
|
407
|
+
this.frozens.push({
|
|
408
|
+
handlers: this.handlers,
|
|
409
|
+
aliasMap: this.aliasMap,
|
|
410
|
+
defaultCommand: this.defaultCommand,
|
|
352
411
|
});
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
const frozen = frozens.pop();
|
|
356
|
-
assertNotStrictEqual(frozen, undefined, shim);
|
|
357
|
-
({
|
|
358
|
-
|
|
359
|
-
|
|
412
|
+
}
|
|
413
|
+
unfreeze() {
|
|
414
|
+
const frozen = this.frozens.pop();
|
|
415
|
+
assertNotStrictEqual(frozen, undefined, this.shim);
|
|
416
|
+
({
|
|
417
|
+
handlers: this.handlers,
|
|
418
|
+
aliasMap: this.aliasMap,
|
|
419
|
+
defaultCommand: this.defaultCommand,
|
|
420
|
+
} = frozen);
|
|
421
|
+
}
|
|
422
|
+
reset() {
|
|
423
|
+
this.handlers = {};
|
|
424
|
+
this.aliasMap = {};
|
|
425
|
+
this.defaultCommand = undefined;
|
|
426
|
+
this.requireCache = new Set();
|
|
427
|
+
return this;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
export function command(usage, validation, globalMiddleware, shim) {
|
|
431
|
+
return new CommandInstance(usage, validation, globalMiddleware, shim);
|
|
360
432
|
}
|
|
361
433
|
export function isCommandBuilderDefinition(builder) {
|
|
362
434
|
return (typeof builder === 'object' &&
|
|
@@ -364,12 +436,7 @@ export function isCommandBuilderDefinition(builder) {
|
|
|
364
436
|
typeof builder.handler === 'function');
|
|
365
437
|
}
|
|
366
438
|
function isCommandAndAliases(cmd) {
|
|
367
|
-
|
|
368
|
-
return true;
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
return false;
|
|
372
|
-
}
|
|
439
|
+
return cmd.every(c => typeof c === 'string');
|
|
373
440
|
}
|
|
374
441
|
export function isCommandBuilderCallback(builder) {
|
|
375
442
|
return typeof builder === 'function';
|
|
@@ -5,7 +5,7 @@ export const completionShTemplate = `###-begin-{{app_name}}-completions-###
|
|
|
5
5
|
# Installation: {{app_path}} {{completion_command}} >> ~/.bashrc
|
|
6
6
|
# or {{app_path}} {{completion_command}} >> ~/.bash_profile on OSX.
|
|
7
7
|
#
|
|
8
|
-
_yargs_completions()
|
|
8
|
+
_{{app_name}}_yargs_completions()
|
|
9
9
|
{
|
|
10
10
|
local cur_word args type_list
|
|
11
11
|
|
|
@@ -24,15 +24,16 @@ _yargs_completions()
|
|
|
24
24
|
|
|
25
25
|
return 0
|
|
26
26
|
}
|
|
27
|
-
complete -o default -F _yargs_completions {{app_name}}
|
|
27
|
+
complete -o bashdefault -o default -F _{{app_name}}_yargs_completions {{app_name}}
|
|
28
28
|
###-end-{{app_name}}-completions-###
|
|
29
29
|
`;
|
|
30
|
-
export const completionZshTemplate =
|
|
30
|
+
export const completionZshTemplate = `#compdef {{app_name}}
|
|
31
|
+
###-begin-{{app_name}}-completions-###
|
|
31
32
|
#
|
|
32
33
|
# yargs command completion script
|
|
33
34
|
#
|
|
34
35
|
# Installation: {{app_path}} {{completion_command}} >> ~/.zshrc
|
|
35
|
-
# or {{app_path}} {{completion_command}} >> ~/.
|
|
36
|
+
# or {{app_path}} {{completion_command}} >> ~/.zprofile on OSX.
|
|
36
37
|
#
|
|
37
38
|
_{{app_name}}_yargs_completions()
|
|
38
39
|
{
|