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 +1 -1
- package/src/commands/logs.js +36 -77
package/package.json
CHANGED
package/src/commands/logs.js
CHANGED
|
@@ -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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
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
|
-
|
|
83
|
-
|
|
47
|
+
const stdout = resp.stdout || "";
|
|
48
|
+
const stderr = resp.stderr || "";
|
|
84
49
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
|