fix(cli): stop advertising multi-letter single-dash option aliases (#1395)
Incur's `alias` map registers one-letter short flags and already accepts kebab-case spellings of camelCase options. Twenty options registered their kebab-case long name as an "alias", so help and completions advertised flags such as `-case-sensitive` and `-relative-path` that the parser reads as stacked short flags and rejects with "Unknown flag: -c". Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5fc4d792ca
commit
498cec042a
@@ -123,7 +123,6 @@ const registerAssetCatalogCommand = (
|
||||
.default(1_000)
|
||||
.describe("Maximum records to return"),
|
||||
}),
|
||||
alias: {},
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.inspectAssetCatalog, () =>
|
||||
runProviderAnalysis(
|
||||
@@ -170,11 +169,6 @@ const registerInterfaceBuilderCommand = (
|
||||
.default(40_000)
|
||||
.describe("Maximum decoded connections"),
|
||||
}),
|
||||
alias: {
|
||||
maxDocuments: "max-documents",
|
||||
maxObjects: "max-objects",
|
||||
maxConnections: "max-connections",
|
||||
},
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "decode-interface-builder", () =>
|
||||
runProviderAnalysis(
|
||||
@@ -233,9 +227,6 @@ const registerInspectionCommand = (
|
||||
.default("fail")
|
||||
.describe("Behavior when declared artifact integrity does not match"),
|
||||
}),
|
||||
alias: {
|
||||
integrityPolicy: "integrity-policy",
|
||||
},
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "inspect-artifact", () =>
|
||||
runProviderAnalysis(
|
||||
|
||||
@@ -54,7 +54,6 @@ const registerOverviewCommands = (
|
||||
options: overviewOptions.extend({
|
||||
integrityPolicy: javascriptApplicationOptions.shape.integrityPolicy,
|
||||
}),
|
||||
alias: { integrityPolicy: "integrity-policy" },
|
||||
run: async ({ args, options }) => {
|
||||
// Route JavaScript targets exactly like analyze-javascript-application,
|
||||
// including typed cancellation; cancellation wraps logging so its exit
|
||||
@@ -274,9 +273,6 @@ const registerTraceCommand = (
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
alias: {
|
||||
caseSensitive: "case-sensitive",
|
||||
},
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "trace", () =>
|
||||
runDirectAnalysis(
|
||||
@@ -455,7 +451,6 @@ const registerSearchCommand = (
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
alias: { caseSensitive: "case-sensitive" },
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "search", () =>
|
||||
runDirectAnalysis(
|
||||
|
||||
@@ -157,13 +157,6 @@ export const registerCoreNativeCommands = (
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
alias: {
|
||||
maxDepth: "max-depth",
|
||||
maxFunctions: "max-functions",
|
||||
maxCallSites: "max-call-sites",
|
||||
maxNodes: "max-nodes",
|
||||
maxEdges: "max-edges",
|
||||
},
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.traceNativeValues, () =>
|
||||
runDirectAnalysis(
|
||||
@@ -283,7 +276,6 @@ const registerNativeDispatchMetadataCommand = (
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
alias: { maxRecords: "max-records" },
|
||||
run: async ({ args, options }) =>
|
||||
logCliCommand(logger, "inspect-native-dispatch-metadata", () =>
|
||||
runDirectAnalysis(
|
||||
@@ -343,11 +335,6 @@ const registerNativeUiActionCommand = (
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
alias: {
|
||||
maxDepth: "max-depth",
|
||||
maxNodes: "max-nodes",
|
||||
maxEdges: "max-edges",
|
||||
},
|
||||
run: async ({ args, options }) =>
|
||||
logCliCommand(logger, "trace-native-ui-action", () =>
|
||||
runDirectAnalysis(
|
||||
|
||||
@@ -190,7 +190,6 @@ const registerJavaScriptApplicationCommand = (
|
||||
path: z.string().describe("ASAR or extracted application path"),
|
||||
}),
|
||||
options: javascriptApplicationOptions,
|
||||
alias: { integrityPolicy: "integrity-policy" },
|
||||
run: ({ args, options }) =>
|
||||
withCommandCancellation((signal) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.analyzeJavaScriptApplication, () =>
|
||||
|
||||
@@ -148,7 +148,6 @@ const registerMaintenanceCommands = (
|
||||
.default(false)
|
||||
.describe("Also remove REA caches and state"),
|
||||
}),
|
||||
alias: { purgeData: "purge-data" },
|
||||
run: ({ options }) =>
|
||||
logCliCommand(
|
||||
logger,
|
||||
|
||||
@@ -65,10 +65,6 @@ export const registerUtilityCommands = (
|
||||
.default(500)
|
||||
.describe("Maximum accessibility nodes per capture"),
|
||||
}),
|
||||
alias: {
|
||||
windowId: "window-id",
|
||||
maxNodes: "max-nodes",
|
||||
},
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, command, async () => {
|
||||
const parameters = {
|
||||
@@ -172,7 +168,6 @@ const registerNativeCommands = (
|
||||
"Plist path relative to the app root (default: Contents/Info.plist)",
|
||||
),
|
||||
}),
|
||||
alias: { relativePath: "relative-path" },
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "inspect-plist", () =>
|
||||
runProviderAnalysis(
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import { Cli } from "incur";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createCli } from "../../../src/cli.js";
|
||||
import { createCliInventory } from "../../../scripts/lib/catalog-cli.mjs";
|
||||
|
||||
type CliInstance = ReturnType<typeof createCli>;
|
||||
type CommandMap = NonNullable<ReturnType<typeof Cli.toCommands.get>>;
|
||||
|
||||
const registeredCommands: WeakMap<object, CommandMap> = Cli.toCommands;
|
||||
|
||||
const serve = async (
|
||||
cli: CliInstance,
|
||||
argv: readonly string[],
|
||||
): Promise<{ readonly stdout: string; readonly exitCode: number }> => {
|
||||
let stdout = "";
|
||||
let exitCode = 0;
|
||||
await cli.serve([...argv], {
|
||||
env: {},
|
||||
exit: (code) => {
|
||||
exitCode = code;
|
||||
},
|
||||
stdout: (text) => {
|
||||
stdout += text;
|
||||
},
|
||||
});
|
||||
return { stdout, exitCode };
|
||||
};
|
||||
|
||||
const registeredAliases = (
|
||||
cli: CliInstance,
|
||||
command: string,
|
||||
): Record<string, unknown> => {
|
||||
const entry = registeredCommands.get(cli)?.get(command);
|
||||
const alias: unknown =
|
||||
entry === undefined ? undefined : Reflect.get(entry, "alias");
|
||||
return typeof alias === "object" && alias !== null ? { ...alias } : {};
|
||||
};
|
||||
|
||||
describe("CLI option aliases", () => {
|
||||
it("register only single-character short flags", async () => {
|
||||
const cli = createCli({});
|
||||
const invalid: string[] = [];
|
||||
for (const command of createCliInventory(cli).primary) {
|
||||
for (const [option, short] of Object.entries(
|
||||
registeredAliases(cli, command),
|
||||
))
|
||||
if (typeof short !== "string" || short.length !== 1)
|
||||
invalid.push(`${command} ${option}: ${String(short)}`);
|
||||
// Incur parses `-abc` as stacked one-letter flags, so help must never
|
||||
// advertise a multi-letter single-dash spelling.
|
||||
const help = await serve(cli, [command, "--help"]);
|
||||
for (const match of help.stdout.matchAll(/(?:^|[\s,])-([a-z][\w-]+)/gmu))
|
||||
invalid.push(`${command} help: -${match[1] ?? ""}`);
|
||||
}
|
||||
expect(invalid).toEqual([]);
|
||||
});
|
||||
|
||||
it("accepts kebab-case long options without registered aliases", async () => {
|
||||
const cli = createCli({});
|
||||
const result = await serve(cli, [
|
||||
"inspect-plist",
|
||||
"/nonexistent/REA.app",
|
||||
"--relative-path",
|
||||
"Contents/Info.plist",
|
||||
"--json",
|
||||
]);
|
||||
expect(result.stdout).not.toContain("Unknown flag");
|
||||
expect(result.stdout).toContain("/nonexistent/REA.app");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user