@nolto/cli 0.2.0 → 0.2.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/dist/index.js +23 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -275,6 +275,22 @@ import { createRequire } from "module";
|
|
|
275
275
|
import { fileURLToPath } from "url";
|
|
276
276
|
import path2 from "path";
|
|
277
277
|
import fs from "fs";
|
|
278
|
+
|
|
279
|
+
// src/unwrap.ts
|
|
280
|
+
function unwrapList(result, key) {
|
|
281
|
+
if (Array.isArray(result)) {
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
if (result != null && typeof result === "object") {
|
|
285
|
+
const inner = result[key];
|
|
286
|
+
if (Array.isArray(inner)) {
|
|
287
|
+
return inner;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return [];
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/commands/init.ts
|
|
278
294
|
var __dirname = path2.dirname(fileURLToPath(import.meta.url));
|
|
279
295
|
var _require = createRequire(import.meta.url);
|
|
280
296
|
function getCliVersion() {
|
|
@@ -330,9 +346,7 @@ function register(program, _deps) {
|
|
|
330
346
|
let projects = [];
|
|
331
347
|
try {
|
|
332
348
|
const result = await caller.call("list_projects", {});
|
|
333
|
-
|
|
334
|
-
projects = result;
|
|
335
|
-
}
|
|
349
|
+
projects = unwrapList(result, "projects");
|
|
336
350
|
} catch (err) {
|
|
337
351
|
if (err instanceof CliError && err.exitCode === 3) {
|
|
338
352
|
throw new CliError(`Token rejected by ${baseUrl}`, 3, "Check that your token is valid and has not been revoked.");
|
|
@@ -474,9 +488,7 @@ function register2(program, deps) {
|
|
|
474
488
|
if (settings.token != null) {
|
|
475
489
|
try {
|
|
476
490
|
const result = await deps.caller.call("list_projects", {});
|
|
477
|
-
|
|
478
|
-
projectCount = result.length;
|
|
479
|
-
}
|
|
491
|
+
projectCount = unwrapList(result, "projects").length;
|
|
480
492
|
} catch {
|
|
481
493
|
}
|
|
482
494
|
}
|
|
@@ -501,7 +513,7 @@ function register2(program, deps) {
|
|
|
501
513
|
["configPath", configPath],
|
|
502
514
|
["token", tokenDisplay],
|
|
503
515
|
["defaultProject", `${settings.defaultProjectId ?? "none"} (source: ${settings.source.project})`],
|
|
504
|
-
["projects", projectCount != null ? String(projectCount) : "(no token)"]
|
|
516
|
+
["projects", projectCount != null ? String(projectCount) : settings.token != null ? "(unavailable)" : "(no token)"]
|
|
505
517
|
];
|
|
506
518
|
const maxKey = lines.reduce((m, [k]) => Math.max(m, k.length), 0);
|
|
507
519
|
for (const [key, val] of lines) {
|
|
@@ -530,7 +542,7 @@ function register3(program, deps) {
|
|
|
530
542
|
printResult(result, "json");
|
|
531
543
|
return;
|
|
532
544
|
}
|
|
533
|
-
const rows =
|
|
545
|
+
const rows = unwrapList(result, "projects");
|
|
534
546
|
const defaultId = deps.settings.defaultProjectId;
|
|
535
547
|
const tableRows = rows.map((p) => ({
|
|
536
548
|
id: p.id ?? "",
|
|
@@ -848,12 +860,12 @@ function register4(program, deps) {
|
|
|
848
860
|
printResult(result, "json");
|
|
849
861
|
return;
|
|
850
862
|
}
|
|
851
|
-
const rows =
|
|
863
|
+
const rows = unwrapList(result, "plans");
|
|
852
864
|
const tableRows = rows.map((p) => ({
|
|
853
865
|
id: p.id ?? "",
|
|
854
|
-
title: p.title ?? "",
|
|
866
|
+
title: p.display_title ?? p.raw_title ?? p.title ?? "",
|
|
855
867
|
status: p.status ?? "",
|
|
856
|
-
createdAt: p.createdAt ?? ""
|
|
868
|
+
createdAt: p.created_at ?? p.createdAt ?? ""
|
|
857
869
|
}));
|
|
858
870
|
process.stdout.write(formatTable(tableRows, ["id", "title", "status", "createdAt"]) + "\n");
|
|
859
871
|
});
|