kubiy-paas-cli 0.1.8 → 0.1.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kubiy-paas-cli",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "CLI para la plataforma PaaS de Kubiy",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -3,56 +3,25 @@ const { apiGet } = require("../api");
3
3
  const { logError, logInfo, logSuccess } = require("../logger");
4
4
  const { getCliToken } = require("../config");
5
5
 
6
- function parseLogsArgs(args) {
7
- let serviceId = null;
8
- let kind = "app";
9
- let lines = 100;
10
-
11
- if (!args || args.length === 0) {
12
- return { serviceId, kind, lines };
6
+ async function run(args) {
7
+ const serviceId = args[0];
8
+ if (!serviceId) {
9
+ logError("Uso: kubiy logs <serviceId> --kind=app|deploy --lines=N");
10
+ process.exit(1);
13
11
  }
14
12
 
15
- serviceId = args[0];
16
-
17
- for (let i = 1; i < args.length; i++) {
18
- const a = args[i];
19
-
20
- // --kind deploy | --kind app
21
- if (a === "--kind" && args[i + 1]) {
22
- kind = args[i + 1];
23
- i++;
24
- continue;
25
- }
26
- if (a.startsWith("--kind=")) {
27
- kind = a.split("=")[1];
28
- continue;
29
- }
13
+ let kind = "app";
14
+ let lines = 100;
30
15
 
31
- // --lines 200 | --lines=200
32
- if (a === "--lines" && args[i + 1]) {
33
- const n = parseInt(args[i + 1], 10);
34
- if (!isNaN(n)) lines = n;
35
- i++;
36
- continue;
37
- }
38
- if (a.startsWith("--lines=")) {
39
- const n = parseInt(a.split("=")[1], 10);
40
- if (!isNaN(n)) lines = n;
41
- continue;
16
+ for (const arg of args.slice(1)) {
17
+ if (arg.startsWith("--kind=")) {
18
+ kind = arg.split("=")[1] || "app";
19
+ } else if (arg.startsWith("--lines=")) {
20
+ const v = parseInt(arg.split("=")[1], 10);
21
+ if (!isNaN(v)) lines = v;
42
22
  }
43
23
  }
44
24
 
45
- return { serviceId, kind, lines };
46
- }
47
-
48
- async function run(args) {
49
- const { serviceId, kind, lines } = parseLogsArgs(args);
50
-
51
- if (!serviceId) {
52
- logError("Uso: kubiy logs <serviceId> [--kind app|deploy] [--lines N]");
53
- process.exit(1);
54
- }
55
-
56
25
  const token = getCliToken();
57
26
  if (!token) {
58
27
  logError("No hay CLI token. Ejecuta: kubiy login <cliToken>");
@@ -63,43 +32,33 @@ async function run(args) {
63
32
  `Obteniendo logs (${kind}) del servicio ${serviceId} (últimas ${lines} líneas)...`
64
33
  );
65
34
 
66
- try {
67
- const qs = `kind=${encodeURIComponent(kind)}&lines=${lines}`;
68
- const data = await apiGet(`/services/${serviceId}/logs?${qs}`);
69
-
70
- // Esperamos algo tipo:
71
- // { serviceId, kind, lines, status, output, errorOutput?, error? }
72
- if (data.error) {
73
- logError("Error al obtener logs:", data.error);
74
- if (data.hint) {
75
- console.log("Hint:", data.hint);
76
- }
77
- process.exit(1);
78
- }
35
+ const resp = await apiGet(
36
+ `/services/${serviceId}/logs?kind=${encodeURIComponent(
37
+ kind
38
+ )}&lines=${lines}`
39
+ );
79
40
 
80
- logSuccess("Logs recibidos:\n");
41
+ if (resp.error) {
42
+ logError(`Error desde API: ${resp.error}`);
43
+ if (resp.detail) console.error(resp.detail);
44
+ process.exit(1);
45
+ }
81
46
 
82
- const output = data.output || "";
83
- const errorOutput = data.errorOutput || "";
47
+ const stdout = resp.stdout || "";
48
+ const stderr = resp.stderr || "";
84
49
 
85
- if (!output && !errorOutput) {
86
- console.log("<sin salida de logs>");
87
- } else {
88
- if (output) {
89
- console.log(output.trimEnd());
90
- }
91
- if (errorOutput) {
92
- console.log("\n[STDERR]");
93
- console.log(errorOutput.trimEnd());
94
- }
95
- }
50
+ logSuccess("Logs recibidos:\n");
51
+ if (stdout.trim().length === 0 && stderr.trim().length === 0) {
52
+ console.log("(sin contenido)");
53
+ return;
54
+ }
96
55
 
97
- if (data.status && data.status !== "Success") {
98
- console.log(`\n[Estado SSM: ${data.status}]`);
99
- }
100
- } catch (err) {
101
- logError("Error llamando a la API de logs:", err.message || err);
102
- process.exit(1);
56
+ if (stdout) {
57
+ console.log(stdout);
58
+ }
59
+ if (stderr) {
60
+ console.log("\n[stderr]:");
61
+ console.log(stderr);
103
62
  }
104
63
  }
105
64