craft-native 0.0.75 → 0.0.76
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/cli.js +151 -108
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2124,90 +2124,6 @@ class Telemetry {
|
|
|
2124
2124
|
}
|
|
2125
2125
|
}
|
|
2126
2126
|
var telemetry = new Telemetry;
|
|
2127
|
-
function parseArgv(argv, opts = {}) {
|
|
2128
|
-
const result = { _: [] };
|
|
2129
|
-
const alias = opts.alias || {};
|
|
2130
|
-
const booleans = new Set(opts.boolean || []);
|
|
2131
|
-
const aliasOf = {};
|
|
2132
|
-
for (const key of Object.keys(alias)) {
|
|
2133
|
-
for (const a of alias[key]) {
|
|
2134
|
-
aliasOf[a] = key;
|
|
2135
|
-
}
|
|
2136
|
-
}
|
|
2137
|
-
for (const b of booleans) {
|
|
2138
|
-
if (alias[b]) {
|
|
2139
|
-
for (const a of alias[b])
|
|
2140
|
-
booleans.add(a);
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
function setKey(key, value) {
|
|
2144
|
-
const canonical = aliasOf[key] || key;
|
|
2145
|
-
result[canonical] = value;
|
|
2146
|
-
if (alias[canonical]) {
|
|
2147
|
-
for (const a of alias[canonical])
|
|
2148
|
-
result[a] = value;
|
|
2149
|
-
}
|
|
2150
|
-
if (aliasOf[key] && alias[aliasOf[key]]) {
|
|
2151
|
-
for (const a of alias[aliasOf[key]])
|
|
2152
|
-
result[a] = value;
|
|
2153
|
-
}
|
|
2154
|
-
result[key] = value;
|
|
2155
|
-
}
|
|
2156
|
-
for (let i = 0;i < argv.length; i++) {
|
|
2157
|
-
const arg = argv[i];
|
|
2158
|
-
if (arg === "--") {
|
|
2159
|
-
result._.push(...argv.slice(i + 1));
|
|
2160
|
-
break;
|
|
2161
|
-
}
|
|
2162
|
-
if (arg.startsWith("--")) {
|
|
2163
|
-
const eqIdx = arg.indexOf("=");
|
|
2164
|
-
if (eqIdx !== -1) {
|
|
2165
|
-
const key = arg.slice(2, eqIdx);
|
|
2166
|
-
const value = arg.slice(eqIdx + 1);
|
|
2167
|
-
setKey(key, value);
|
|
2168
|
-
} else {
|
|
2169
|
-
const key = arg.slice(2);
|
|
2170
|
-
if (key.startsWith("no-")) {
|
|
2171
|
-
const actualKey = key.slice(3);
|
|
2172
|
-
setKey(actualKey, false);
|
|
2173
|
-
continue;
|
|
2174
|
-
}
|
|
2175
|
-
const canonical = aliasOf[key] || key;
|
|
2176
|
-
if (booleans.has(canonical) || booleans.has(key)) {
|
|
2177
|
-
setKey(key, true);
|
|
2178
|
-
} else {
|
|
2179
|
-
const next = argv[i + 1];
|
|
2180
|
-
if (next !== undefined && !next.startsWith("-")) {
|
|
2181
|
-
setKey(key, next);
|
|
2182
|
-
i++;
|
|
2183
|
-
} else {
|
|
2184
|
-
setKey(key, true);
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2187
|
-
}
|
|
2188
|
-
} else if (arg.startsWith("-") && arg.length > 1) {
|
|
2189
|
-
const chars = arg.slice(1);
|
|
2190
|
-
for (let j = 0;j < chars.length; j++) {
|
|
2191
|
-
const ch = chars[j];
|
|
2192
|
-
const canonical = aliasOf[ch] || ch;
|
|
2193
|
-
if (j === chars.length - 1 && !booleans.has(canonical) && !booleans.has(ch)) {
|
|
2194
|
-
const next = argv[i + 1];
|
|
2195
|
-
if (next !== undefined && !next.startsWith("-")) {
|
|
2196
|
-
setKey(ch, next);
|
|
2197
|
-
i++;
|
|
2198
|
-
} else {
|
|
2199
|
-
setKey(ch, true);
|
|
2200
|
-
}
|
|
2201
|
-
} else {
|
|
2202
|
-
setKey(ch, true);
|
|
2203
|
-
}
|
|
2204
|
-
}
|
|
2205
|
-
} else {
|
|
2206
|
-
result._.push(arg);
|
|
2207
|
-
}
|
|
2208
|
-
}
|
|
2209
|
-
return result;
|
|
2210
|
-
}
|
|
2211
2127
|
function removeBrackets(v) {
|
|
2212
2128
|
return v.replace(/[<[].+/, "").trim();
|
|
2213
2129
|
}
|
|
@@ -2304,9 +2220,13 @@ function camelcaseOptionName(name) {
|
|
|
2304
2220
|
class ClappError extends Error {
|
|
2305
2221
|
exitCode = 2;
|
|
2306
2222
|
isUsageError = true;
|
|
2307
|
-
|
|
2223
|
+
usage;
|
|
2224
|
+
constructor(message, usage) {
|
|
2308
2225
|
super(message);
|
|
2309
2226
|
this.name = this.constructor.name;
|
|
2227
|
+
if (usage !== undefined) {
|
|
2228
|
+
this.usage = usage;
|
|
2229
|
+
}
|
|
2310
2230
|
if (typeof Error.captureStackTrace === "function") {
|
|
2311
2231
|
Error.captureStackTrace(this, this.constructor);
|
|
2312
2232
|
} else {
|
|
@@ -2323,6 +2243,12 @@ ${this.stack}`;
|
|
|
2323
2243
|
return this.message;
|
|
2324
2244
|
}
|
|
2325
2245
|
}
|
|
2246
|
+
function isClappError(err) {
|
|
2247
|
+
if (err instanceof ClappError) {
|
|
2248
|
+
return true;
|
|
2249
|
+
}
|
|
2250
|
+
return !!err && typeof err === "object" && err.name === "ClappError" && typeof err.message === "string";
|
|
2251
|
+
}
|
|
2326
2252
|
function isUnicodeSupported() {
|
|
2327
2253
|
const { env } = process22;
|
|
2328
2254
|
const { TERM, TERM_PROGRAM } = env;
|
|
@@ -2404,6 +2330,99 @@ function levenshteinDistance(a, b) {
|
|
|
2404
2330
|
function findSimilarCommands(input, commands, maxDistance = 2, maxSuggestions = 3) {
|
|
2405
2331
|
return commands.map((cmd) => ({ cmd, distance: levenshteinDistance(input, cmd) })).filter(({ distance }) => distance <= maxDistance).sort((a, b) => a.distance - b.distance).slice(0, maxSuggestions).map(({ cmd }) => cmd);
|
|
2406
2332
|
}
|
|
2333
|
+
function parseArgv(argv, opts = {}) {
|
|
2334
|
+
const result = { _: [] };
|
|
2335
|
+
const alias = opts.alias || {};
|
|
2336
|
+
const booleans = new Set(opts.boolean || []);
|
|
2337
|
+
const aliasOf = {};
|
|
2338
|
+
for (const key of Object.keys(alias)) {
|
|
2339
|
+
for (const a of alias[key]) {
|
|
2340
|
+
aliasOf[a] = key;
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
for (const b of booleans) {
|
|
2344
|
+
if (alias[b]) {
|
|
2345
|
+
for (const a of alias[b])
|
|
2346
|
+
booleans.add(a);
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
function merge(existing, value) {
|
|
2350
|
+
if (existing === undefined)
|
|
2351
|
+
return value;
|
|
2352
|
+
if (typeof value === "boolean")
|
|
2353
|
+
return value;
|
|
2354
|
+
return Array.isArray(existing) ? [...existing, value] : [existing, value];
|
|
2355
|
+
}
|
|
2356
|
+
function setKey(key, value) {
|
|
2357
|
+
const canonical = aliasOf[key] || key;
|
|
2358
|
+
const merged = merge(result[canonical], value);
|
|
2359
|
+
result[canonical] = merged;
|
|
2360
|
+
if (alias[canonical]) {
|
|
2361
|
+
for (const a of alias[canonical])
|
|
2362
|
+
result[a] = merged;
|
|
2363
|
+
}
|
|
2364
|
+
if (aliasOf[key] && alias[aliasOf[key]]) {
|
|
2365
|
+
for (const a of alias[aliasOf[key]])
|
|
2366
|
+
result[a] = merged;
|
|
2367
|
+
}
|
|
2368
|
+
result[key] = merged;
|
|
2369
|
+
}
|
|
2370
|
+
for (let i = 0;i < argv.length; i++) {
|
|
2371
|
+
const arg = argv[i];
|
|
2372
|
+
if (arg === "--") {
|
|
2373
|
+
result._.push(...argv.slice(i + 1));
|
|
2374
|
+
break;
|
|
2375
|
+
}
|
|
2376
|
+
if (arg.startsWith("--")) {
|
|
2377
|
+
const eqIdx = arg.indexOf("=");
|
|
2378
|
+
if (eqIdx !== -1) {
|
|
2379
|
+
const key = camelcase(arg.slice(2, eqIdx));
|
|
2380
|
+
const value = arg.slice(eqIdx + 1);
|
|
2381
|
+
setKey(key, value);
|
|
2382
|
+
} else {
|
|
2383
|
+
const rawKey = arg.slice(2);
|
|
2384
|
+
if (rawKey.startsWith("no-")) {
|
|
2385
|
+
const actualKey = camelcase(rawKey.slice(3));
|
|
2386
|
+
setKey(actualKey, false);
|
|
2387
|
+
continue;
|
|
2388
|
+
}
|
|
2389
|
+
const key = camelcase(rawKey);
|
|
2390
|
+
const canonical = aliasOf[key] || key;
|
|
2391
|
+
if (booleans.has(canonical) || booleans.has(key)) {
|
|
2392
|
+
setKey(key, true);
|
|
2393
|
+
} else {
|
|
2394
|
+
const next = argv[i + 1];
|
|
2395
|
+
if (next !== undefined && !next.startsWith("-")) {
|
|
2396
|
+
setKey(key, next);
|
|
2397
|
+
i++;
|
|
2398
|
+
} else {
|
|
2399
|
+
setKey(key, true);
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
} else if (arg.startsWith("-") && arg.length > 1) {
|
|
2404
|
+
const chars = arg.slice(1);
|
|
2405
|
+
for (let j = 0;j < chars.length; j++) {
|
|
2406
|
+
const ch = chars[j];
|
|
2407
|
+
const canonical = aliasOf[ch] || ch;
|
|
2408
|
+
if (j === chars.length - 1 && !booleans.has(canonical) && !booleans.has(ch)) {
|
|
2409
|
+
const next = argv[i + 1];
|
|
2410
|
+
if (next !== undefined && !next.startsWith("-")) {
|
|
2411
|
+
setKey(ch, next);
|
|
2412
|
+
i++;
|
|
2413
|
+
} else {
|
|
2414
|
+
setKey(ch, true);
|
|
2415
|
+
}
|
|
2416
|
+
} else {
|
|
2417
|
+
setKey(ch, true);
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
} else {
|
|
2421
|
+
result._.push(arg);
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
return result;
|
|
2425
|
+
}
|
|
2407
2426
|
|
|
2408
2427
|
class Option {
|
|
2409
2428
|
rawName;
|
|
@@ -2551,9 +2570,9 @@ class Command {
|
|
|
2551
2570
|
return this.namespace ? `${this.namespace}:${this.name}` : this.name;
|
|
2552
2571
|
}
|
|
2553
2572
|
hasOption(name) {
|
|
2554
|
-
|
|
2573
|
+
const normalized = camelcaseOptionName(name.split(".")[0]);
|
|
2555
2574
|
return !!this.options.find((option) => {
|
|
2556
|
-
return option.names.
|
|
2575
|
+
return option.names.some((optionName) => camelcaseOptionName(optionName) === normalized);
|
|
2557
2576
|
});
|
|
2558
2577
|
}
|
|
2559
2578
|
outputHelp() {
|
|
@@ -2588,6 +2607,7 @@ class Command {
|
|
|
2588
2607
|
}
|
|
2589
2608
|
}
|
|
2590
2609
|
let commandBody = "";
|
|
2610
|
+
noNamespaceCommands.sort((a, b) => a.rawName < b.rawName ? -1 : a.rawName > b.rawName ? 1 : 0);
|
|
2591
2611
|
if (noNamespaceCommands.length > 0) {
|
|
2592
2612
|
commandBody += noNamespaceCommands.map((command) => {
|
|
2593
2613
|
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
|
@@ -2614,12 +2634,14 @@ class Command {
|
|
|
2614
2634
|
body: commandBody
|
|
2615
2635
|
});
|
|
2616
2636
|
sections.push({
|
|
2617
|
-
|
|
2618
|
-
body: commands.map((command) => ` $ ${name}${command.displayName === "" ? "" : ` ${command.displayName}`} --help`).join(`
|
|
2619
|
-
`)
|
|
2637
|
+
body: `Run \`${name} <command> --help\` for command details.`
|
|
2620
2638
|
});
|
|
2621
2639
|
}
|
|
2622
|
-
|
|
2640
|
+
const localOptionNames = new Set(this.options.flatMap((option) => option.names));
|
|
2641
|
+
let options = this.isGlobalCommand ? globalOptions : [
|
|
2642
|
+
...this.options,
|
|
2643
|
+
...(globalOptions || []).filter((option) => !option.names.some((name2) => localOptionNames.has(name2)))
|
|
2644
|
+
];
|
|
2623
2645
|
if (!this.isGlobalCommand && !this.isDefaultCommand) {
|
|
2624
2646
|
options = options.filter((option) => option.name !== "version");
|
|
2625
2647
|
}
|
|
@@ -2663,6 +2685,9 @@ ${section.body}` : section.body;
|
|
|
2663
2685
|
console.log(`${name}/${versionNumber} ${platformInfo3}`);
|
|
2664
2686
|
}
|
|
2665
2687
|
}
|
|
2688
|
+
get usageLine() {
|
|
2689
|
+
return `$ ${this.cli.name} ${this.usageText || this.rawName}`;
|
|
2690
|
+
}
|
|
2666
2691
|
checkRequiredArgs() {
|
|
2667
2692
|
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
|
2668
2693
|
if (this.cli.args.length < minimalArgsCount) {
|
|
@@ -2671,7 +2696,7 @@ ${section.body}` : section.body;
|
|
|
2671
2696
|
const argNames = missingArgs.map((arg) => `<${arg.value}>`).join(" ");
|
|
2672
2697
|
throw new ClappError(`Missing required argument${missingArgs.length > 1 ? "s" : ""}: ${argNames}
|
|
2673
2698
|
|
|
2674
|
-
` + `Run \`${this.cli.name} ${this.rawName} --help\` for usage information
|
|
2699
|
+
` + `Run \`${this.cli.name} ${this.rawName} --help\` for usage information.`, this.usageLine);
|
|
2675
2700
|
}
|
|
2676
2701
|
}
|
|
2677
2702
|
checkUnknownOptions() {
|
|
@@ -2681,8 +2706,9 @@ ${section.body}` : section.body;
|
|
|
2681
2706
|
if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {
|
|
2682
2707
|
const allOptions = [...globalCommand.options, ...this.options];
|
|
2683
2708
|
const allOptionNames = allOptions.flatMap((opt) => opt.names);
|
|
2709
|
+
const normalizedName = camelcaseOptionName(name.split(".")[0]);
|
|
2684
2710
|
const optionFlag = name.length > 1 ? `--${name}` : `-${name}`;
|
|
2685
|
-
const suggestions = findSimilarCommands(
|
|
2711
|
+
const suggestions = findSimilarCommands(normalizedName, allOptionNames);
|
|
2686
2712
|
let errorMsg = `Unknown option \`${optionFlag}\``;
|
|
2687
2713
|
if (suggestions.length > 0) {
|
|
2688
2714
|
errorMsg += `
|
|
@@ -2697,7 +2723,7 @@ Did you mean one of these?`;
|
|
|
2697
2723
|
errorMsg += `
|
|
2698
2724
|
|
|
2699
2725
|
Run \`${this.cli.name} ${this.rawName} --help\` to see available options.`;
|
|
2700
|
-
throw new ClappError(errorMsg);
|
|
2726
|
+
throw new ClappError(errorMsg, this.usageLine);
|
|
2701
2727
|
}
|
|
2702
2728
|
}
|
|
2703
2729
|
}
|
|
@@ -2712,7 +2738,7 @@ Run \`${this.cli.name} ${this.rawName} --help\` to see available options.`;
|
|
|
2712
2738
|
if (value === true || value === false && !hasNegated) {
|
|
2713
2739
|
throw new ClappError(`Option \`${option.rawName}\` requires a value.
|
|
2714
2740
|
|
|
2715
|
-
` + `Example: ${this.cli.name} ${this.rawName} ${option.rawName} <value
|
|
2741
|
+
` + `Example: ${this.cli.name} ${this.rawName} ${option.rawName} <value>`, this.usageLine);
|
|
2716
2742
|
}
|
|
2717
2743
|
}
|
|
2718
2744
|
}
|
|
@@ -3018,6 +3044,25 @@ Received ${signal}, cleaning up...`);
|
|
|
3018
3044
|
break;
|
|
3019
3045
|
}
|
|
3020
3046
|
}
|
|
3047
|
+
if (shouldParse) {
|
|
3048
|
+
const nextToken = slicedArgv[1];
|
|
3049
|
+
if (nextToken && !nextToken.startsWith("-")) {
|
|
3050
|
+
const joinedName = `${candidateName}:${nextToken}`;
|
|
3051
|
+
for (const command of this.commands) {
|
|
3052
|
+
if (command.isMatched(joinedName)) {
|
|
3053
|
+
const parsed = this.mri(slicedArgv, command);
|
|
3054
|
+
shouldParse = false;
|
|
3055
|
+
const parsedInfo = {
|
|
3056
|
+
...parsed,
|
|
3057
|
+
args: parsed.args.slice(2)
|
|
3058
|
+
};
|
|
3059
|
+
this.setParsedInfo(parsedInfo, command, joinedName);
|
|
3060
|
+
this.emit(`command:${joinedName}`, command);
|
|
3061
|
+
break;
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
3065
|
+
}
|
|
3021
3066
|
}
|
|
3022
3067
|
if (shouldParse) {
|
|
3023
3068
|
for (const command of this.commands) {
|
|
@@ -3043,7 +3088,7 @@ Received ${signal}, cleaning up...`);
|
|
|
3043
3088
|
if (this.options.debug) {
|
|
3044
3089
|
this.isDebug = true;
|
|
3045
3090
|
}
|
|
3046
|
-
if (this.options.noInteraction) {
|
|
3091
|
+
if (this.options.noInteraction || this.options.interaction === false) {
|
|
3047
3092
|
this.isNoInteraction = true;
|
|
3048
3093
|
}
|
|
3049
3094
|
if (this.options.env) {
|
|
@@ -3055,14 +3100,14 @@ Received ${signal}, cleaning up...`);
|
|
|
3055
3100
|
if (this.options.force) {
|
|
3056
3101
|
this.isForce = true;
|
|
3057
3102
|
}
|
|
3058
|
-
if (this.options.noEmoji
|
|
3059
|
-
this.useEmoji =
|
|
3103
|
+
if (this.options.noEmoji || this.options.emoji === false) {
|
|
3104
|
+
this.useEmoji = false;
|
|
3060
3105
|
}
|
|
3061
3106
|
if (this.options.theme) {
|
|
3062
3107
|
this.theme = String(this.options.theme);
|
|
3063
3108
|
}
|
|
3064
|
-
if (this.options.noCache
|
|
3065
|
-
this.isNoCache =
|
|
3109
|
+
if (this.options.noCache || this.options.cache === false) {
|
|
3110
|
+
this.isNoCache = true;
|
|
3066
3111
|
}
|
|
3067
3112
|
if (this.options.help && this.showHelpOnExit) {
|
|
3068
3113
|
this.outputHelp();
|
|
@@ -3143,18 +3188,16 @@ Received ${signal}, cleaning up...`);
|
|
|
3143
3188
|
return this.parse(argv, { run: true, exitOnError: true });
|
|
3144
3189
|
}
|
|
3145
3190
|
handleUsageError(err) {
|
|
3146
|
-
|
|
3147
|
-
const isUsage = isClappError && err.isUsageError !== false;
|
|
3148
|
-
if (!isUsage)
|
|
3191
|
+
if (!isClappError(err) || err.isUsageError === false)
|
|
3149
3192
|
return;
|
|
3150
|
-
const
|
|
3151
|
-
const raw = e.message ?? "command-line error";
|
|
3193
|
+
const raw = err.message || "command-line error";
|
|
3152
3194
|
const label = this.name ? `${this.name}: ` : "";
|
|
3153
|
-
const suffix = /--help/.test(raw) ? "" : `
|
|
3195
|
+
const suffix = /--help/.test(raw) ? "" : err.usage ? `
|
|
3196
|
+
Usage: ${err.usage}` : `
|
|
3154
3197
|
Run \`${this.name ?? "cli"} --help\` for usage.`;
|
|
3155
3198
|
process5.stderr.write(`${label}${raw}${suffix}
|
|
3156
3199
|
`);
|
|
3157
|
-
process5.exit(
|
|
3200
|
+
process5.exit(err.exitCode ?? 2);
|
|
3158
3201
|
}
|
|
3159
3202
|
async runMatchedCommand() {
|
|
3160
3203
|
const { args, options, matchedCommand: command } = this;
|
|
@@ -4072,7 +4115,7 @@ function craftBinaryNotFoundMessage(triedPath) {
|
|
|
4072
4115
|
`);
|
|
4073
4116
|
}
|
|
4074
4117
|
// package.json
|
|
4075
|
-
var version = "0.0.
|
|
4118
|
+
var version = "0.0.76";
|
|
4076
4119
|
|
|
4077
4120
|
// bin/cli.ts
|
|
4078
4121
|
var spawnedFrom = process6.env[CRAFT_CLI_SPAWN_MARKER];
|