@travetto/cli 4.0.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 ArcSine Technologies
3
+ Copyright (c) 2020 ArcSine Technologies
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/cli",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "CLI infrastructure for Travetto framework",
5
5
  "keywords": [
6
6
  "cli",
@@ -29,7 +29,7 @@
29
29
  "directory": "module/cli"
30
30
  },
31
31
  "dependencies": {
32
- "@travetto/schema": "^4.0.1",
32
+ "@travetto/schema": "^4.0.2",
33
33
  "@travetto/terminal": "^4.0.1"
34
34
  },
35
35
  "travetto": {
package/src/error.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { AppError } from '@travetto/base';
1
2
  import { PackageUtil, RuntimeContext } from '@travetto/manifest';
2
3
  import { cliTpl } from './color';
3
4
  import { CliValidationError, CliCommandShape } from './types';
@@ -48,13 +49,11 @@ ${{ identifier: install }}
48
49
  /**
49
50
  * Provides a basic error wrapper for cli validation issues
50
51
  */
51
- export class CliValidationResultError extends Error {
52
- errors: CliValidationError[];
52
+ export class CliValidationResultError extends AppError<{ errors: CliValidationError[] }> {
53
53
  command: CliCommandShape;
54
54
 
55
55
  constructor(command: CliCommandShape, errors: CliValidationError[]) {
56
- super('');
56
+ super('', undefined, { errors });
57
57
  this.command = command;
58
- this.errors = errors;
59
58
  }
60
59
  }
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
- /** Run command */
35
- static async #runCommand(cmd: string, args: string[]): Promise<void> {
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
- console.log!(await HelpUtil.renderCommandHelp(cmd));
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
  }
package/src/help.ts CHANGED
@@ -134,7 +134,7 @@ export class HelpUtil {
134
134
  static renderValidationError(err: CliValidationResultError): string {
135
135
  return [
136
136
  cliTpl`${{ failure: 'Execution failed' }}:`,
137
- ...err.errors.map(e => e.source && e.source !== 'custom' ?
137
+ ...err.details.errors.map(e => e.source && e.source !== 'custom' ?
138
138
  cliTpl` * ${{ identifier: validationSourceMap[e.source] }} ${{ subtitle: e.message }}` :
139
139
  cliTpl` * ${{ failure: e.message }}`),
140
140
  '',
package/src/schema.ts CHANGED
@@ -182,7 +182,7 @@ export class CliCommandSchemaUtil {
182
182
  if (!(err instanceof CliValidationResultError) && !(err instanceof ValidationResultError)) {
183
183
  throw err;
184
184
  }
185
- return err.errors.map(v => ({ source: SOURCES[i], ...v }));
185
+ return err.details.errors.map(v => ({ source: SOURCES[i], ...v }));
186
186
  }));
187
187
 
188
188
  const errors = (await Promise.all(results)).flatMap(x => (x ?? []));