@travetto/cli 4.0.2 → 4.0.3
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/LICENSE +1 -1
- package/package.json +1 -1
- package/src/execute.ts +11 -3
package/LICENSE
CHANGED
package/package.json
CHANGED
package/src/execute.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { CliCommandSchemaUtil } from './schema';
|
|
|
6
6
|
import { CliUnknownCommandError, CliValidationResultError } from './error';
|
|
7
7
|
import { CliParseUtil } from './parse';
|
|
8
8
|
import { CliUtil } from './util';
|
|
9
|
+
import { CliCommandShape } from './types';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Execution manager
|
|
@@ -31,8 +32,8 @@ export class ExecutionManager {
|
|
|
31
32
|
console.error!();
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
/**
|
|
35
|
-
static async #
|
|
35
|
+
/** Bind command */
|
|
36
|
+
static async #bindCommand(cmd: string, args: string[]): Promise<{ command: CliCommandShape, boundArgs: unknown[] }> {
|
|
36
37
|
const command = await CliCommandRegistry.getInstance(cmd, true);
|
|
37
38
|
const schema = await CliCommandSchemaUtil.getSchema(command);
|
|
38
39
|
const fullArgs = await CliParseUtil.expandArgs(schema, args);
|
|
@@ -40,6 +41,12 @@ export class ExecutionManager {
|
|
|
40
41
|
|
|
41
42
|
await command.preBind?.();
|
|
42
43
|
const boundArgs = await CliCommandSchemaUtil.bindInput(command, state);
|
|
44
|
+
return { command, boundArgs };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Run command */
|
|
48
|
+
static async #runCommand(cmd: string, args: string[]): Promise<void> {
|
|
49
|
+
const { command, boundArgs } = await this.#bindCommand(cmd, args);
|
|
43
50
|
|
|
44
51
|
await command.preValidate?.();
|
|
45
52
|
await CliCommandSchemaUtil.validate(command, boundArgs);
|
|
@@ -62,7 +69,8 @@ export class ExecutionManager {
|
|
|
62
69
|
if (!cmd) {
|
|
63
70
|
console.info!(await HelpUtil.renderAllHelp());
|
|
64
71
|
} else if (help) {
|
|
65
|
-
|
|
72
|
+
const { command } = await this.#bindCommand(cmd, args)
|
|
73
|
+
console.log!(await HelpUtil.renderCommandHelp(command));
|
|
66
74
|
} else {
|
|
67
75
|
await this.#runCommand(cmd, args);
|
|
68
76
|
}
|