xp-command 1.0.0 → 1.0.1
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/bin/index.js +5 -5
- package/package.json +1 -1
- package/src/error.js +7 -0
package/bin/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { getDatarefValue, initAPI, setDatarefValue } from "../src/api.js";
|
|
|
16
16
|
import { copyToClipboard } from "../src/clipboard.js";
|
|
17
17
|
import { getConfig } from "../src/config.js";
|
|
18
18
|
import { clearLine, hideCursor, showCursor } from "../src/console.js";
|
|
19
|
-
import { isEconnRefused } from "../src/error.js";
|
|
19
|
+
import { isAPIError, isEconnRefused } from "../src/error.js";
|
|
20
20
|
import history from "../src/history.js";
|
|
21
21
|
import { sleep } from "../src/sleep.js";
|
|
22
22
|
|
|
@@ -31,7 +31,7 @@ program
|
|
|
31
31
|
* @param {string} command
|
|
32
32
|
*/
|
|
33
33
|
const processCommand = async (command) => {
|
|
34
|
-
const spinner = ora(`${PREFIX} ${chalk.cyan(command)}`).start();
|
|
34
|
+
const spinner = ora(`${PREFIX} ${chalk.cyan(command ?? "")}`).start();
|
|
35
35
|
hideCursor();
|
|
36
36
|
|
|
37
37
|
/** @type {import('../src/config.js').CommandConfig} */
|
|
@@ -39,7 +39,7 @@ const processCommand = async (command) => {
|
|
|
39
39
|
try {
|
|
40
40
|
config = await getConfig();
|
|
41
41
|
} catch (error) {
|
|
42
|
-
if (isEconnRefused(error)) {
|
|
42
|
+
if (isEconnRefused(error) || isAPIError(error)) {
|
|
43
43
|
spinner.fail(chalk.red(`${PREFIX} No connection - in aircraft?`));
|
|
44
44
|
hideCursor();
|
|
45
45
|
await sleep(1500);
|
|
@@ -148,7 +148,7 @@ const processCommand = async (command) => {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
spinner.fail(chalk.red(`${PREFIX} ${command}`));
|
|
151
|
+
spinner.fail(chalk.red(`${PREFIX} ${command ?? ""}`));
|
|
152
152
|
hideCursor();
|
|
153
153
|
|
|
154
154
|
await sleep(1500);
|
|
@@ -204,7 +204,7 @@ const askForCommand = async () => {
|
|
|
204
204
|
{ clearPromptOnDone: true },
|
|
205
205
|
);
|
|
206
206
|
|
|
207
|
-
if (command
|
|
207
|
+
if (command?.toLowerCase() === "exit") {
|
|
208
208
|
sayBye();
|
|
209
209
|
return;
|
|
210
210
|
}
|
package/package.json
CHANGED
package/src/error.js
CHANGED
|
@@ -10,3 +10,10 @@ export const isEconnRefused = (error) => {
|
|
|
10
10
|
error.cause.code === "ECONNREFUSED",
|
|
11
11
|
);
|
|
12
12
|
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {unknown} error
|
|
16
|
+
*/
|
|
17
|
+
export const isAPIError = (error) => {
|
|
18
|
+
return Boolean(error instanceof Error && error.name === "APIError");
|
|
19
|
+
};
|