apcore-cli 0.3.2 → 0.4.0
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/CHANGELOG.md +12 -0
- package/README.md +7 -4
- package/dist/bin/apcore-cli.js +10 -4
- package/dist/bin/apcore-cli.js.map +1 -1
- package/dist/index.d.ts +30 -3
- package/dist/index.js +163 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -494,7 +494,7 @@ init_errors();
|
|
|
494
494
|
import { readFileSync } from "fs";
|
|
495
495
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
496
496
|
import * as path5 from "path";
|
|
497
|
-
import { Command, CommanderError } from "commander";
|
|
497
|
+
import { Command, CommanderError, Option } from "commander";
|
|
498
498
|
|
|
499
499
|
// src/ref-resolver.ts
|
|
500
500
|
init_esm_shims();
|
|
@@ -1220,17 +1220,29 @@ function getCliDisplayFields(descriptor) {
|
|
|
1220
1220
|
|
|
1221
1221
|
// src/main.ts
|
|
1222
1222
|
var __dirname2 = path5.dirname(fileURLToPath2(import.meta.url));
|
|
1223
|
+
var verboseHelp = false;
|
|
1224
|
+
function setVerboseHelp(verbose) {
|
|
1225
|
+
verboseHelp = verbose;
|
|
1226
|
+
}
|
|
1227
|
+
var docsUrl = null;
|
|
1228
|
+
function setDocsUrl(url) {
|
|
1229
|
+
docsUrl = url;
|
|
1230
|
+
}
|
|
1231
|
+
function hasVerboseFlag() {
|
|
1232
|
+
return process.argv.includes("--verbose");
|
|
1233
|
+
}
|
|
1223
1234
|
var VERSION = "0.0.0";
|
|
1224
1235
|
try {
|
|
1225
1236
|
const pkg = JSON.parse(readFileSync(path5.resolve(__dirname2, "../package.json"), "utf-8"));
|
|
1226
1237
|
VERSION = pkg.version;
|
|
1227
1238
|
} catch {
|
|
1228
1239
|
}
|
|
1229
|
-
function createCli(extensionsDir, progName) {
|
|
1240
|
+
function createCli(extensionsDir, progName, verbose = false) {
|
|
1241
|
+
verboseHelp = verbose;
|
|
1230
1242
|
const resolvedProgName = progName ?? path5.basename(process.argv[1] ?? "apcore-cli") ?? "apcore-cli";
|
|
1231
1243
|
const cliLogLevel = process.env.APCORE_CLI_LOGGING_LEVEL ?? process.env.APCORE_LOGGING_LEVEL ?? "WARNING";
|
|
1232
1244
|
setLogLevel(cliLogLevel);
|
|
1233
|
-
const program = new Command(resolvedProgName).exitOverride().version(VERSION, "--version", `Show ${resolvedProgName} version`).description("apcore CLI \u2014 execute apcore modules from the command line").option("--extensions-dir <path>", "Path to extensions directory").option("--commands-dir <path>", "Path to convention-based commands directory").option("--binding <path>", "Path to binding.yaml for display overlay").option("--log-level <level>", "Logging level (DEBUG|INFO|WARNING|ERROR)", "WARNING");
|
|
1245
|
+
const program = new Command(resolvedProgName).exitOverride().version(VERSION, "--version", `Show ${resolvedProgName} version`).description("apcore CLI \u2014 execute apcore modules from the command line").option("--extensions-dir <path>", "Path to extensions directory").option("--commands-dir <path>", "Path to convention-based commands directory").option("--binding <path>", "Path to binding.yaml for display overlay").option("--log-level <level>", "Logging level (DEBUG|INFO|WARNING|ERROR)", "WARNING").option("--verbose", "Show all options in help output (including built-in apcore options)");
|
|
1234
1246
|
const resolvedExtDir = extensionsDir ?? process.env.APCORE_EXTENSIONS_ROOT ?? "./extensions";
|
|
1235
1247
|
void resolvedExtDir;
|
|
1236
1248
|
registerInitCommand(program);
|
|
@@ -1264,7 +1276,8 @@ async function applyToolkitIntegration(commandsDir, bindingPath) {
|
|
|
1264
1276
|
}
|
|
1265
1277
|
}
|
|
1266
1278
|
function main(progName) {
|
|
1267
|
-
|
|
1279
|
+
verboseHelp = hasVerboseFlag();
|
|
1280
|
+
const program = createCli(void 0, progName, verboseHelp);
|
|
1268
1281
|
try {
|
|
1269
1282
|
program.parse(process.argv);
|
|
1270
1283
|
} catch (error2) {
|
|
@@ -1279,7 +1292,7 @@ function main(progName) {
|
|
|
1279
1292
|
process.exit(code);
|
|
1280
1293
|
}
|
|
1281
1294
|
}
|
|
1282
|
-
function buildModuleCommand(moduleDef, executor, helpTextMaxLength = 1e3, cmdName) {
|
|
1295
|
+
function buildModuleCommand(moduleDef, executor, helpTextMaxLength = 1e3, cmdName, verbose = verboseHelp) {
|
|
1283
1296
|
const moduleId = moduleDef.id;
|
|
1284
1297
|
let resolvedSchema = {};
|
|
1285
1298
|
let schemaOptions = [];
|
|
@@ -1297,11 +1310,32 @@ function buildModuleCommand(moduleDef, executor, helpTextMaxLength = 1e3, cmdNam
|
|
|
1297
1310
|
schemaOptions = schemaToCliOptions(resolvedSchema, helpTextMaxLength);
|
|
1298
1311
|
}
|
|
1299
1312
|
const cmd = new Command(effectiveCmdName).description(cmdHelp);
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1313
|
+
const inputOpt = new Option("--input <source>", "Read JSON input from a file path, or use '-' to read from stdin pipe");
|
|
1314
|
+
const yesOpt = new Option("-y, --yes", "Skip interactive approval prompts (for scripts and CI)").default(false);
|
|
1315
|
+
const largeInputOpt = new Option("--large-input", "Allow stdin input larger than 10MB (default limit protects against accidental pipes)").default(false);
|
|
1316
|
+
const formatOpt = new Option("--format <format>", "Set output format: 'json' for machine-readable, 'table' for human-readable");
|
|
1317
|
+
const sandboxOpt = new Option("--sandbox", "Run module in an isolated subprocess with restricted filesystem and env access").default(false).hideHelp();
|
|
1318
|
+
if (!verbose) {
|
|
1319
|
+
inputOpt.hideHelp();
|
|
1320
|
+
yesOpt.hideHelp();
|
|
1321
|
+
largeInputOpt.hideHelp();
|
|
1322
|
+
formatOpt.hideHelp();
|
|
1323
|
+
}
|
|
1324
|
+
cmd.addOption(inputOpt);
|
|
1325
|
+
cmd.addOption(yesOpt);
|
|
1326
|
+
cmd.addOption(largeInputOpt);
|
|
1327
|
+
cmd.addOption(formatOpt);
|
|
1328
|
+
cmd.addOption(sandboxOpt);
|
|
1329
|
+
const footerParts = [];
|
|
1330
|
+
if (!verbose) {
|
|
1331
|
+
footerParts.push("Use --verbose to show all options (including built-in apcore options).");
|
|
1332
|
+
}
|
|
1333
|
+
if (docsUrl) {
|
|
1334
|
+
footerParts.push(`Docs: ${docsUrl}/commands/${effectiveCmdName}`);
|
|
1335
|
+
}
|
|
1336
|
+
if (footerParts.length > 0) {
|
|
1337
|
+
cmd.addHelpText("after", "\n" + footerParts.join("\n") + "\n");
|
|
1338
|
+
}
|
|
1305
1339
|
for (const opt of schemaOptions) {
|
|
1306
1340
|
if (opt.parseArg) {
|
|
1307
1341
|
cmd.option(opt.flags, opt.description, opt.parseArg, opt.defaultValue);
|
|
@@ -1316,7 +1350,7 @@ function buildModuleCommand(moduleDef, executor, helpTextMaxLength = 1e3, cmdNam
|
|
|
1316
1350
|
const outputFormat = options.format;
|
|
1317
1351
|
const sandboxEnabled = options.sandbox;
|
|
1318
1352
|
const schemaKwargs = {};
|
|
1319
|
-
const builtinKeys = /* @__PURE__ */ new Set(["input", "yes", "largeInput", "format", "sandbox"]);
|
|
1353
|
+
const builtinKeys = /* @__PURE__ */ new Set(["input", "yes", "largeInput", "format", "sandbox", "verbose"]);
|
|
1320
1354
|
for (const [k, v] of Object.entries(options)) {
|
|
1321
1355
|
if (!builtinKeys.has(k)) {
|
|
1322
1356
|
schemaKwargs[k] = v;
|
|
@@ -1880,7 +1914,7 @@ init_errors();
|
|
|
1880
1914
|
import { readFileSync as readFileSync3 } from "fs";
|
|
1881
1915
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1882
1916
|
import * as path6 from "path";
|
|
1883
|
-
import { Command as Command4 } from "commander";
|
|
1917
|
+
import { Command as Command4, Help, Option as Option2 } from "commander";
|
|
1884
1918
|
var __dirname3 = path6.dirname(fileURLToPath3(import.meta.url));
|
|
1885
1919
|
var SHELL_VERSION = "0.0.0";
|
|
1886
1920
|
try {
|
|
@@ -2151,6 +2185,117 @@ ${meaning}`);
|
|
|
2151
2185
|
);
|
|
2152
2186
|
return sections.join("\n");
|
|
2153
2187
|
}
|
|
2188
|
+
function roffEscape(s) {
|
|
2189
|
+
return s.replace(/\\/g, "\\\\").replace(/-/g, "\\-").replace(/'/g, "\\(aq");
|
|
2190
|
+
}
|
|
2191
|
+
function buildProgramManPage(program, progName, version, description, docsUrl2) {
|
|
2192
|
+
const help = new Help();
|
|
2193
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
2194
|
+
const s = [];
|
|
2195
|
+
const resolvedDesc = description ?? program.description() ?? `${progName} CLI`;
|
|
2196
|
+
s.push(`.TH "${progName.toUpperCase()}" "1" "${today}" "${progName} ${version}" "${progName} Manual"`);
|
|
2197
|
+
s.push(".SH NAME");
|
|
2198
|
+
s.push(`${progName} \\- ${roffEscape(resolvedDesc)}`);
|
|
2199
|
+
s.push(".SH SYNOPSIS");
|
|
2200
|
+
s.push(`\\fB${progName}\\fR [\\fIglobal\\-options\\fR] \\fIcommand\\fR [\\fIcommand\\-options\\fR]`);
|
|
2201
|
+
if (resolvedDesc) {
|
|
2202
|
+
s.push(".SH DESCRIPTION");
|
|
2203
|
+
s.push(roffEscape(resolvedDesc));
|
|
2204
|
+
}
|
|
2205
|
+
const globalOpts = help.visibleOptions(program).filter((o) => !["help", "version", "all", "man"].includes(o.long?.replace("--", "") ?? ""));
|
|
2206
|
+
if (globalOpts.length > 0) {
|
|
2207
|
+
s.push(".SH GLOBAL OPTIONS");
|
|
2208
|
+
for (const opt of globalOpts) {
|
|
2209
|
+
const flag = [opt.short, opt.long].filter(Boolean).join(", ");
|
|
2210
|
+
s.push(".TP");
|
|
2211
|
+
s.push(`\\fB${roffEscape(flag)}\\fR`);
|
|
2212
|
+
if (opt.description) s.push(roffEscape(opt.description));
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
const allCommands = help.visibleCommands(program);
|
|
2216
|
+
if (allCommands.length > 0) {
|
|
2217
|
+
s.push(".SH COMMANDS");
|
|
2218
|
+
for (const cmd of allCommands) {
|
|
2219
|
+
if (cmd.name() === "help") continue;
|
|
2220
|
+
const desc = help.subcommandDescription(cmd);
|
|
2221
|
+
s.push(".TP");
|
|
2222
|
+
s.push(`\\fB${progName} ${roffEscape(cmd.name())}\\fR`);
|
|
2223
|
+
if (desc) s.push(roffEscape(desc));
|
|
2224
|
+
const cmdHelp = new Help();
|
|
2225
|
+
const opts = cmdHelp.visibleOptions(cmd).filter((o) => !["help", "version"].includes(o.long?.replace("--", "") ?? ""));
|
|
2226
|
+
for (const opt of opts) {
|
|
2227
|
+
const flag = [opt.short, opt.long].filter(Boolean).join(", ");
|
|
2228
|
+
s.push(".RS");
|
|
2229
|
+
s.push(".TP");
|
|
2230
|
+
s.push(`\\fB${roffEscape(flag)}\\fR`);
|
|
2231
|
+
if (opt.description) s.push(roffEscape(opt.description));
|
|
2232
|
+
s.push(".RE");
|
|
2233
|
+
}
|
|
2234
|
+
const subCmds = cmdHelp.visibleCommands(cmd).filter((c) => c.name() !== "help");
|
|
2235
|
+
for (const sub of subCmds) {
|
|
2236
|
+
const subDesc = help.subcommandDescription(sub);
|
|
2237
|
+
s.push(".TP");
|
|
2238
|
+
s.push(`\\fB${progName} ${roffEscape(cmd.name())} ${roffEscape(sub.name())}\\fR`);
|
|
2239
|
+
if (subDesc) s.push(roffEscape(subDesc));
|
|
2240
|
+
const subOpts = cmdHelp.visibleOptions(sub).filter((o) => !["help", "version"].includes(o.long?.replace("--", "") ?? ""));
|
|
2241
|
+
for (const opt of subOpts) {
|
|
2242
|
+
const flag = [opt.short, opt.long].filter(Boolean).join(", ");
|
|
2243
|
+
s.push(".RS");
|
|
2244
|
+
s.push(".TP");
|
|
2245
|
+
s.push(`\\fB${roffEscape(flag)}\\fR`);
|
|
2246
|
+
if (opt.description) s.push(roffEscape(opt.description));
|
|
2247
|
+
s.push(".RE");
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
s.push(".SH ENVIRONMENT");
|
|
2253
|
+
s.push(".TP");
|
|
2254
|
+
s.push("\\fBAPCORE_EXTENSIONS_ROOT\\fR");
|
|
2255
|
+
s.push("Path to the apcore extensions directory.");
|
|
2256
|
+
s.push(".TP");
|
|
2257
|
+
s.push("\\fBAPCORE_CLI_AUTO_APPROVE\\fR");
|
|
2258
|
+
s.push("Set to \\fB1\\fR to bypass approval prompts.");
|
|
2259
|
+
s.push(".TP");
|
|
2260
|
+
s.push("\\fBAPCORE_CLI_LOGGING_LEVEL\\fR");
|
|
2261
|
+
s.push("CLI\\-specific logging verbosity (DEBUG|INFO|WARNING|ERROR).");
|
|
2262
|
+
s.push(".SH EXIT CODES");
|
|
2263
|
+
const exitCodes = [
|
|
2264
|
+
["0", "Success."],
|
|
2265
|
+
["1", "Module execution error."],
|
|
2266
|
+
["2", "Invalid CLI input or missing argument."],
|
|
2267
|
+
["44", "Module not found, disabled, or failed to load."],
|
|
2268
|
+
["45", "Input failed JSON Schema validation."],
|
|
2269
|
+
["46", "Approval denied or timed out."],
|
|
2270
|
+
["47", "Configuration error."],
|
|
2271
|
+
["77", "ACL denied."],
|
|
2272
|
+
["130", "Cancelled by user (SIGINT)."]
|
|
2273
|
+
];
|
|
2274
|
+
for (const [code, meaning] of exitCodes) {
|
|
2275
|
+
s.push(`.TP
|
|
2276
|
+
\\fB${code}\\fR
|
|
2277
|
+
${meaning}`);
|
|
2278
|
+
}
|
|
2279
|
+
s.push(".SH SEE ALSO");
|
|
2280
|
+
s.push(`\\fB${progName} \\-\\-help \\-\\-verbose\\fR for full option list.`);
|
|
2281
|
+
if (docsUrl2) {
|
|
2282
|
+
s.push(`.PP
|
|
2283
|
+
Full documentation at \\fI${roffEscape(docsUrl2)}\\fR`);
|
|
2284
|
+
}
|
|
2285
|
+
return s.join("\n");
|
|
2286
|
+
}
|
|
2287
|
+
function configureManHelp(program, progName, version, description, docsUrl2) {
|
|
2288
|
+
const manOpt = new Option2("--man", "Output man page in roff format (use with --help)").hideHelp();
|
|
2289
|
+
program.addOption(manOpt);
|
|
2290
|
+
program.addHelpText("beforeAll", () => {
|
|
2291
|
+
if (program.opts().man) {
|
|
2292
|
+
process.stdout.write(buildProgramManPage(program, progName, version, description, docsUrl2));
|
|
2293
|
+
process.stdout.write("\n");
|
|
2294
|
+
process.exit(0);
|
|
2295
|
+
}
|
|
2296
|
+
return "";
|
|
2297
|
+
});
|
|
2298
|
+
}
|
|
2154
2299
|
function registerShellCommands(cli, progName = "apcore-cli") {
|
|
2155
2300
|
const completionCmd = new Command4("completion").description(
|
|
2156
2301
|
"Generate a shell completion script and print it to stdout."
|
|
@@ -2213,10 +2358,13 @@ export {
|
|
|
2213
2358
|
SchemaValidationError,
|
|
2214
2359
|
applyToolkitIntegration,
|
|
2215
2360
|
buildModuleCommand,
|
|
2361
|
+
buildProgramManPage,
|
|
2216
2362
|
checkApproval,
|
|
2217
2363
|
collectInput,
|
|
2364
|
+
configureManHelp,
|
|
2218
2365
|
createCli,
|
|
2219
2366
|
debug,
|
|
2367
|
+
docsUrl,
|
|
2220
2368
|
error,
|
|
2221
2369
|
exitCodeForError,
|
|
2222
2370
|
extractHelp,
|
|
@@ -2238,9 +2386,12 @@ export {
|
|
|
2238
2386
|
resolveRefs,
|
|
2239
2387
|
schemaToCliOptions,
|
|
2240
2388
|
setAuditLogger,
|
|
2389
|
+
setDocsUrl,
|
|
2241
2390
|
setLogLevel,
|
|
2391
|
+
setVerboseHelp,
|
|
2242
2392
|
truncate,
|
|
2243
2393
|
validateModuleId,
|
|
2394
|
+
verboseHelp,
|
|
2244
2395
|
warn
|
|
2245
2396
|
};
|
|
2246
2397
|
//# sourceMappingURL=index.js.map
|