@corigin/cli 0.1.3 → 0.1.4

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/dist/main.js +49 -18
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -1028,7 +1028,7 @@ function resolveGitCredentialRepo(input) {
1028
1028
  }
1029
1029
  function createCoriginProgram(deps = {}) {
1030
1030
  const program = addCliGlobalOptions(
1031
- new Command().name("corigin").description("Corigin command-line interface").version("0.1.3")
1031
+ new Command().name("corigin").description("Corigin command-line interface").version("0.1.4")
1032
1032
  );
1033
1033
  if (deps.exitOverride !== false) program.exitOverride();
1034
1034
  addCliGlobalOptions(program.command("login")).option("--no-open", "Print the verification URL without opening a browser").option(
@@ -1104,7 +1104,7 @@ async function runCommand(commandName, command, deps, action) {
1104
1104
  throw new CliError("command_failed", "Corigin command did not return output data.");
1105
1105
  }
1106
1106
  stdout.write(
1107
- commandOptions.json ? formatJsonSuccess(commandName, data) : formatHumanSuccess(commandName, data)
1107
+ commandOptions.json ? formatJsonSuccess(commandName, data) : formatHumanSuccess(commandName, data, { color: streamIsTty(stdout) })
1108
1108
  );
1109
1109
  }).catch((error) => {
1110
1110
  const cliError = error instanceof CliError ? error : new CliError("command_failed", "Corigin command failed.");
@@ -1370,48 +1370,76 @@ async function rootCliOptions(command, profileOptions = {}) {
1370
1370
  json: commandOptions.json
1371
1371
  };
1372
1372
  }
1373
- function formatHumanSuccess(command, data) {
1373
+ function formatHumanSuccess(command, data, options = { color: false }) {
1374
+ const color = colorizer(options.color);
1374
1375
  const value = objectData(data);
1375
1376
  if (command === "repos list" && Array.isArray(value?.repos)) {
1376
- if (value.repos.length === 0) return "No repos found.\n";
1377
+ if (value.repos.length === 0) return `${color.dim("No repos found.")}
1378
+ `;
1377
1379
  return `${value.repos.map((repo) => {
1378
1380
  const repoValue = objectData(repo);
1379
- return `${stringField(repoValue, "name")} ${stringField(repoValue, "repo_id")}`;
1381
+ return `${color.bold(stringField(repoValue, "name"))} ${color.dim(stringField(repoValue, "repo_id"))}`;
1380
1382
  }).join("\n")}
1381
1383
  `;
1382
1384
  }
1383
1385
  if (command === "repos create" && value && "repo" in value) {
1384
1386
  const repo = objectData(value.repo);
1385
- return `Created repo ${stringField(repo, "name")}.
1386
- Repo ID: ${stringField(repo, "repo_id")}
1387
- Git URL: ${stringField(repo, "git_url")}
1387
+ return `${color.green("Created repo")} ${color.bold(stringField(repo, "name"))}.
1388
+ ${color.cyan("Repo ID:")} ${stringField(repo, "repo_id")}
1389
+ ${color.cyan("Git URL:")} ${stringField(repo, "git_url")}
1388
1390
  `;
1389
1391
  }
1390
1392
  if (command === "repos delete" && value && "repo" in value) {
1391
1393
  const repo = objectData(value.repo);
1392
- return `Deleted repo ${stringField(repo, "name")}.
1393
- Repo ID: ${stringField(repo, "repo_id")}
1394
+ return `${color.green("Deleted repo")} ${color.bold(stringField(repo, "name"))}.
1395
+ ${color.cyan("Repo ID:")} ${stringField(repo, "repo_id")}
1394
1396
  `;
1395
1397
  }
1396
1398
  if (command === "repos git-token" && value) {
1397
- return `Git URL: ${stringField(value, "git_url")}
1398
- Token: ${stringField(value, "token")}
1399
+ const token = stringField(value, "token");
1400
+ return `${color.cyan("Git URL:")} ${authenticatedGitUrl(stringField(value, "git_url"), token)}
1401
+ ${color.cyan("Token:")} ${token}
1399
1402
  `;
1400
1403
  }
1401
1404
  if (command === "git-credentials install") {
1402
- return "Corigin Git credential helper installed.\n";
1405
+ return `${color.green("Corigin Git credential helper installed.")}
1406
+ `;
1403
1407
  }
1404
1408
  if (command === "git-credentials status" && value && "installed" in value) {
1405
- return value.installed ? "Corigin Git credential helper is installed.\n" : "Corigin Git credential helper is not installed.\n";
1409
+ return value.installed ? `${color.green("Corigin Git credential helper is installed.")}
1410
+ ` : `${color.dim("Corigin Git credential helper is not installed.")}
1411
+ `;
1406
1412
  }
1407
1413
  if (command === "git-credentials uninstall") {
1408
- return "Corigin Git credential helper uninstalled.\n";
1414
+ return `${color.green("Corigin Git credential helper uninstalled.")}
1415
+ `;
1409
1416
  }
1410
1417
  if (command === "login" && value && "workspace_name" in value) {
1411
- return `Logged in to ${stringField(value, "workspace_name")}.
1418
+ return `${color.green("Logged in to")} ${color.bold(stringField(value, "workspace_name"))}.
1412
1419
  `;
1413
1420
  }
1414
- return "Done.\n";
1421
+ return `${color.green("Done.")}
1422
+ `;
1423
+ }
1424
+ function authenticatedGitUrl(gitUrl, token) {
1425
+ try {
1426
+ const url = new URL(gitUrl);
1427
+ url.username = "agent";
1428
+ url.password = token;
1429
+ return url.toString();
1430
+ } catch {
1431
+ return gitUrl;
1432
+ }
1433
+ }
1434
+ function colorizer(enabled) {
1435
+ const useColor = enabled && process.env.NO_COLOR === void 0;
1436
+ const paint = (open, close) => (text) => useColor ? `${open}${text}${close}` : text;
1437
+ return {
1438
+ bold: paint("\x1B[1m", "\x1B[22m"),
1439
+ cyan: paint("\x1B[36m", "\x1B[39m"),
1440
+ dim: paint("\x1B[2m", "\x1B[22m"),
1441
+ green: paint("\x1B[32m", "\x1B[39m")
1442
+ };
1415
1443
  }
1416
1444
  function objectData(value) {
1417
1445
  if (!value || typeof value !== "object" || Array.isArray(value)) {
@@ -1449,7 +1477,10 @@ async function progress(command, deps, message, options = {}) {
1449
1477
  `);
1450
1478
  }
1451
1479
  function stderrIsTty(stderr) {
1452
- return "isTTY" in stderr && stderr.isTTY === true;
1480
+ return streamIsTty(stderr);
1481
+ }
1482
+ function streamIsTty(stream) {
1483
+ return "isTTY" in stream && stream.isTTY === true;
1453
1484
  }
1454
1485
  function parsePositiveInteger(value) {
1455
1486
  const parsed = z3.coerce.number().int().positive().safeParse(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corigin/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "bin": {
5
5
  "corigin": "./dist/main.js"
6
6
  },