@corigin/cli 0.1.2 → 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.
- package/dist/main.js +56 -24
- 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.
|
|
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(
|
|
@@ -1039,7 +1039,9 @@ function createCoriginProgram(deps = {}) {
|
|
|
1039
1039
|
).action(
|
|
1040
1040
|
async (options, command) => runCommand("login", command, deps, () => login(command, options, deps))
|
|
1041
1041
|
);
|
|
1042
|
-
const repos =
|
|
1042
|
+
const repos = addCliGlobalOptions(
|
|
1043
|
+
program.command("repos").description("Create, list, and delete hosted repos")
|
|
1044
|
+
);
|
|
1043
1045
|
addCliGlobalOptions(repos.command("list")).action(
|
|
1044
1046
|
async (_options, command) => runCommand("repos list", command, deps, () => reposList(command, deps))
|
|
1045
1047
|
);
|
|
@@ -1049,9 +1051,8 @@ function createCoriginProgram(deps = {}) {
|
|
|
1049
1051
|
addCliGlobalOptions(repos.command("delete")).requiredOption("--repo <repo-id>", "Repository id to delete").requiredOption("--yes", "Confirm deletion without an interactive prompt").action(
|
|
1050
1052
|
async (options, command) => runCommand("repos delete", command, deps, () => reposDelete(command, options, deps))
|
|
1051
1053
|
);
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
async (options, command) => runCommand("git-token create", command, deps, () => gitTokenCreate(command, options, deps))
|
|
1054
|
+
addCliGlobalOptions(repos.command("git-token").description("Mint scoped Git credentials")).requiredOption("--repo <repo-id>", "Repository id for the Git token").option("--actor-subject <label>", "Runtime or sandbox actor label", "cli").option("--access <read|write>", "Git operation scope", parseGitAccess, "write").option("--ttl-seconds <seconds>", "Requested token lifetime in seconds", parsePositiveInteger).action(
|
|
1055
|
+
async (options, command) => runCommand("repos git-token", command, deps, () => gitTokenCreate(command, options, deps))
|
|
1055
1056
|
);
|
|
1056
1057
|
const gitCredentials = program.command("git-credentials").description("Install and inspect the Git credential helper");
|
|
1057
1058
|
addCliGlobalOptions(gitCredentials.command("install")).option("--git-host <host>", "Git remote host for credential-helper config", defaultGitHost).option("--scope <global|local>", "Git config scope", "global").option("--force", "Replace existing Corigin credential-helper config").action(
|
|
@@ -1103,7 +1104,7 @@ async function runCommand(commandName, command, deps, action) {
|
|
|
1103
1104
|
throw new CliError("command_failed", "Corigin command did not return output data.");
|
|
1104
1105
|
}
|
|
1105
1106
|
stdout.write(
|
|
1106
|
-
commandOptions.json ? formatJsonSuccess(commandName, data) : formatHumanSuccess(commandName, data)
|
|
1107
|
+
commandOptions.json ? formatJsonSuccess(commandName, data) : formatHumanSuccess(commandName, data, { color: streamIsTty(stdout) })
|
|
1107
1108
|
);
|
|
1108
1109
|
}).catch((error) => {
|
|
1109
1110
|
const cliError = error instanceof CliError ? error : new CliError("command_failed", "Corigin command failed.");
|
|
@@ -1219,7 +1220,7 @@ async function reposDelete(command, options, deps) {
|
|
|
1219
1220
|
async function gitTokenCreate(command, options, deps) {
|
|
1220
1221
|
const { credential, client: client2 } = await authenticatedRepoClient(command, deps);
|
|
1221
1222
|
return apiData(
|
|
1222
|
-
"git-token
|
|
1223
|
+
"repos git-token",
|
|
1223
1224
|
credential,
|
|
1224
1225
|
await createGitToken({
|
|
1225
1226
|
client: client2,
|
|
@@ -1369,48 +1370,76 @@ async function rootCliOptions(command, profileOptions = {}) {
|
|
|
1369
1370
|
json: commandOptions.json
|
|
1370
1371
|
};
|
|
1371
1372
|
}
|
|
1372
|
-
function formatHumanSuccess(command, data) {
|
|
1373
|
+
function formatHumanSuccess(command, data, options = { color: false }) {
|
|
1374
|
+
const color = colorizer(options.color);
|
|
1373
1375
|
const value = objectData(data);
|
|
1374
1376
|
if (command === "repos list" && Array.isArray(value?.repos)) {
|
|
1375
|
-
if (value.repos.length === 0) return "No repos found
|
|
1377
|
+
if (value.repos.length === 0) return `${color.dim("No repos found.")}
|
|
1378
|
+
`;
|
|
1376
1379
|
return `${value.repos.map((repo) => {
|
|
1377
1380
|
const repoValue = objectData(repo);
|
|
1378
|
-
return `${stringField(repoValue, "name")} ${stringField(repoValue, "repo_id")
|
|
1381
|
+
return `${color.bold(stringField(repoValue, "name"))} ${color.dim(stringField(repoValue, "repo_id"))}`;
|
|
1379
1382
|
}).join("\n")}
|
|
1380
1383
|
`;
|
|
1381
1384
|
}
|
|
1382
1385
|
if (command === "repos create" && value && "repo" in value) {
|
|
1383
1386
|
const repo = objectData(value.repo);
|
|
1384
|
-
return
|
|
1385
|
-
Repo ID: ${stringField(repo, "repo_id")}
|
|
1386
|
-
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")}
|
|
1387
1390
|
`;
|
|
1388
1391
|
}
|
|
1389
1392
|
if (command === "repos delete" && value && "repo" in value) {
|
|
1390
1393
|
const repo = objectData(value.repo);
|
|
1391
|
-
return
|
|
1392
|
-
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")}
|
|
1393
1396
|
`;
|
|
1394
1397
|
}
|
|
1395
|
-
if (command === "git-token
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
+
if (command === "repos git-token" && value) {
|
|
1399
|
+
const token = stringField(value, "token");
|
|
1400
|
+
return `${color.cyan("Git URL:")} ${authenticatedGitUrl(stringField(value, "git_url"), token)}
|
|
1401
|
+
${color.cyan("Token:")} ${token}
|
|
1398
1402
|
`;
|
|
1399
1403
|
}
|
|
1400
1404
|
if (command === "git-credentials install") {
|
|
1401
|
-
return "Corigin Git credential helper installed
|
|
1405
|
+
return `${color.green("Corigin Git credential helper installed.")}
|
|
1406
|
+
`;
|
|
1402
1407
|
}
|
|
1403
1408
|
if (command === "git-credentials status" && value && "installed" in value) {
|
|
1404
|
-
return value.installed ? "Corigin Git credential helper is installed
|
|
1409
|
+
return value.installed ? `${color.green("Corigin Git credential helper is installed.")}
|
|
1410
|
+
` : `${color.dim("Corigin Git credential helper is not installed.")}
|
|
1411
|
+
`;
|
|
1405
1412
|
}
|
|
1406
1413
|
if (command === "git-credentials uninstall") {
|
|
1407
|
-
return "Corigin Git credential helper uninstalled
|
|
1414
|
+
return `${color.green("Corigin Git credential helper uninstalled.")}
|
|
1415
|
+
`;
|
|
1408
1416
|
}
|
|
1409
1417
|
if (command === "login" && value && "workspace_name" in value) {
|
|
1410
|
-
return
|
|
1418
|
+
return `${color.green("Logged in to")} ${color.bold(stringField(value, "workspace_name"))}.
|
|
1419
|
+
`;
|
|
1420
|
+
}
|
|
1421
|
+
return `${color.green("Done.")}
|
|
1411
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;
|
|
1412
1432
|
}
|
|
1413
|
-
|
|
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
|
+
};
|
|
1414
1443
|
}
|
|
1415
1444
|
function objectData(value) {
|
|
1416
1445
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
@@ -1448,7 +1477,10 @@ async function progress(command, deps, message, options = {}) {
|
|
|
1448
1477
|
`);
|
|
1449
1478
|
}
|
|
1450
1479
|
function stderrIsTty(stderr) {
|
|
1451
|
-
return
|
|
1480
|
+
return streamIsTty(stderr);
|
|
1481
|
+
}
|
|
1482
|
+
function streamIsTty(stream) {
|
|
1483
|
+
return "isTTY" in stream && stream.isTTY === true;
|
|
1452
1484
|
}
|
|
1453
1485
|
function parsePositiveInteger(value) {
|
|
1454
1486
|
const parsed = z3.coerce.number().int().positive().safeParse(value);
|