1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | exports.UnknownFlagException = exports.InvalidCommandException = exports.InvalidFlagException = exports.MissingArgumentException = void 0;
|
12 | const cliui_1 = require("@poppinss/cliui");
|
13 | const utils_1 = require("@poppinss/utils");
|
14 |
|
15 |
|
16 |
|
17 | class MissingArgumentException extends utils_1.Exception {
|
18 | |
19 |
|
20 |
|
21 | static invoke(name, command) {
|
22 | const exception = new this(`Missing required argument "${name}"`, 500, 'E_MISSING_ARGUMENT');
|
23 | exception.argumentName = name;
|
24 | exception.command = command;
|
25 | return exception;
|
26 | }
|
27 | |
28 |
|
29 |
|
30 | handle(error) {
|
31 | cliui_1.logger.error(cliui_1.logger.colors.red(`Missing required argument "${error.argumentName}"`));
|
32 | }
|
33 | }
|
34 | exports.MissingArgumentException = MissingArgumentException;
|
35 |
|
36 |
|
37 |
|
38 | class InvalidFlagException extends utils_1.Exception {
|
39 | |
40 |
|
41 |
|
42 | static invoke(prop, expected, command) {
|
43 | let article = 'a';
|
44 | if (expected === 'number') {
|
45 | expected = 'numeric';
|
46 | }
|
47 | if (expected === 'array') {
|
48 | article = 'an';
|
49 | expected = 'array of strings';
|
50 | }
|
51 | if (expected === 'numArray') {
|
52 | article = 'an';
|
53 | expected = 'array of numbers';
|
54 | }
|
55 | const exception = new this(`"${prop}" flag expects ${article} "${expected}" value`, 500, 'E_INVALID_FLAG');
|
56 | exception.flagName = prop;
|
57 | exception.command = command;
|
58 | exception.expectedType = expected;
|
59 | return exception;
|
60 | }
|
61 | |
62 |
|
63 |
|
64 | handle(error) {
|
65 | cliui_1.logger.error(cliui_1.logger.colors.red(`Expected "--${error.flagName}" to be a valid "${error.expectedType}"`));
|
66 | }
|
67 | }
|
68 | exports.InvalidFlagException = InvalidFlagException;
|
69 |
|
70 |
|
71 |
|
72 | class InvalidCommandException extends utils_1.Exception {
|
73 | constructor() {
|
74 | super(...arguments);
|
75 | this.suggestions = [];
|
76 | }
|
77 | static invoke(commandName, suggestions) {
|
78 | const exception = new this(`"${commandName}" is not a registered command`, 500, 'E_INVALID_COMMAND');
|
79 | exception.commandName = commandName;
|
80 | exception.suggestions = suggestions;
|
81 | return exception;
|
82 | }
|
83 | |
84 |
|
85 |
|
86 | handle(error) {
|
87 | cliui_1.logger.error(`"${error.commandName}" command not found`);
|
88 | if (!error.suggestions.length) {
|
89 | return;
|
90 | }
|
91 | cliui_1.logger.log('');
|
92 | const suggestionLog = (0, cliui_1.sticker)().heading('Did you mean one of these?');
|
93 | error.suggestions.forEach((commandName) => {
|
94 | suggestionLog.add(cliui_1.logger.colors.yellow(commandName));
|
95 | });
|
96 | suggestionLog.render();
|
97 | }
|
98 | }
|
99 | exports.InvalidCommandException = InvalidCommandException;
|
100 |
|
101 |
|
102 |
|
103 | class UnknownFlagException extends utils_1.Exception {
|
104 | |
105 |
|
106 |
|
107 | static invoke(prop) {
|
108 | const exception = new this(`Unknown flag "${prop}"`, 500, 'E_INVALID_FLAG');
|
109 | return exception;
|
110 | }
|
111 | |
112 |
|
113 |
|
114 | handle(error) {
|
115 | cliui_1.logger.error(cliui_1.logger.colors.red(error.message));
|
116 | }
|
117 | }
|
118 | exports.UnknownFlagException = UnknownFlagException;
|