@hasagi/cli 0.8.14 → 0.9.0

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.
Files changed (2) hide show
  1. package/bin/index.js +17 -15
  2. package/package.json +4 -4
package/bin/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import yargs from "yargs";
3
- import { HasagiClient, RequestError } from "@hasagi/core";
3
+ import { HasagiClient, LCUError, RequestError } from "@hasagi/core";
4
4
  import fs from "fs/promises";
5
5
  import _path from "path";
6
6
  import { getExtendedHelp, getSwagger, getTypeScript } from "@hasagi/schema";
@@ -36,13 +36,17 @@ if (cmd === "request") {
36
36
  await client.connect();
37
37
  const method = options.method.toUpperCase();
38
38
  const path = options.path;
39
+ const body = typeof options.body === "string" ? JSON.parse(options.body) : undefined;
40
+ const query = typeof options.query === "string" ? JSON.parse(options.query) : undefined;
39
41
  const out = (options.out === undefined ? undefined : options.out !== "" ? options.out : "./");
40
42
  const isDirectory = out !== undefined ? await fs.stat(out).then(stat => stat.isDirectory(), () => false) : false;
41
43
  log(`Sending '${method}' request to 'https://127.0.0.1:${client.getPort()}${path}'...`);
42
44
  const result = await client.request({
43
45
  method,
44
46
  url: path,
45
- returnAxiosResponse: true
47
+ returnAxiosResponse: true,
48
+ data: body,
49
+ params: query
46
50
  }).then(res => ({
47
51
  statusCode: res.status,
48
52
  body: res.data
@@ -50,21 +54,19 @@ if (cmd === "request") {
50
54
  if (out) {
51
55
  await fs.writeFile(isDirectory ? _path.join(out, `${method}-${path.substring(1).replaceAll("/", "_")}-${Date.now()}.json`) : out, JSON.stringify(result, null, 4));
52
56
  }
53
- if (result instanceof RequestError) {
54
- if (result.lcuError) {
55
- log(`Received response with non-success status code '${result.lcuError.httpStatus}'.`);
56
- log(`Error code: '${result.lcuError.errorCode}'.`);
57
- log(`Error message: '${result.lcuError.message}'`);
58
- if (result.lcuError.implementationDetails)
59
- log(`Additional details: ${JSON.stringify(result.lcuError.implementationDetails)}`);
60
- }
61
- else {
62
- log(result.message);
63
- }
57
+ if (result instanceof LCUError) {
58
+ log(`Received response with non-success status code '${result.statusCode}'.`);
59
+ log(`Error code: '${result.errorCode}'.`);
60
+ log(`Error message: '${result.message}'`);
61
+ if (result.implementationDetails)
62
+ log(`Additional details: ${JSON.stringify(result.implementationDetails)}`);
63
+ }
64
+ else if (result instanceof RequestError) {
65
+ log(`${result.errorCode ?? "RequestError"}: ${result.message ?? "An error occurred"}`);
64
66
  }
65
67
  else {
66
- log(`Received response with status code ${result.statusCode}`);
67
- log(`Response body: ${JSON.stringify(result.body, null, 4)}`);
68
+ log(`Received response with status code '${result.statusCode}'.`);
69
+ log(`Response: ${JSON.stringify(result.body, null, 4)}`);
68
70
  }
69
71
  }
70
72
  else if (cmd === "listen") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasagi/cli",
3
- "version": "0.8.14",
3
+ "version": "0.9.0",
4
4
  "description": "This package provides the 'hasagi' command-line interface",
5
5
  "bin": {
6
6
  "hasagi": "bin/index.js"
@@ -17,8 +17,8 @@
17
17
  "author": "dysolix",
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "@hasagi/core": "^0.4.10",
21
- "@hasagi/schema": "^0.5.9",
20
+ "@hasagi/core": "^0.5.1",
21
+ "@hasagi/schema": "^0.6.0",
22
22
  "yargs": "^17.7.2"
23
23
  },
24
24
  "type": "module",
@@ -30,4 +30,4 @@
30
30
  "type": "git",
31
31
  "url": "https://github.com/dysolix/hasagi-cli.git"
32
32
  }
33
- }
33
+ }