@koda-sl/baker-cli 0.203.0 → 0.204.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/README.md +12 -0
- package/dist/cli.js +167 -0
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,8 +86,20 @@ All commands return a JSON envelope:
|
|
|
86
86
|
|
|
87
87
|
// Dry-run
|
|
88
88
|
{ "ok": true, "dryRun": true, "operation": "images.delete", "params": { "id": "abc123" } }
|
|
89
|
+
|
|
90
|
+
// Unknown option — the command stops instead of running without it
|
|
91
|
+
{ "ok": false, "error": { "code": "UNKNOWN_ARGUMENT", "message": "--dimension-filter is not an option of `baker ga4 query`.", "fix": { "action": "check_schema", "explanation": "Did you mean --dimensions? Run `baker schema ga4 query` ..." }, "retryable": false } }
|
|
89
92
|
```
|
|
90
93
|
|
|
94
|
+
### Unknown options are refused
|
|
95
|
+
|
|
96
|
+
An option a command does not declare stops the run with `UNKNOWN_ARGUMENT`, naming the
|
|
97
|
+
closest real one. Previously such an option was accepted and ignored, so a call that
|
|
98
|
+
looked like it had filtered or narrowed a result was in fact answering the unfiltered
|
|
99
|
+
question — and nothing in the output said so. Both spellings of an option work
|
|
100
|
+
(`--run-id` and `--runId`), as they always did. Run `baker schema <command>` to see
|
|
101
|
+
every option a command takes.
|
|
102
|
+
|
|
91
103
|
Use `--output` to change format:
|
|
92
104
|
|
|
93
105
|
| Format | Description | Best for | Available on |
|
package/dist/cli.js
CHANGED
|
@@ -44042,6 +44042,172 @@ Full guide: __tooling__/docs/tools/baker/winning-ads.md`
|
|
|
44042
44042
|
}
|
|
44043
44043
|
});
|
|
44044
44044
|
|
|
44045
|
+
// src/unknown-flags.ts
|
|
44046
|
+
var ALWAYS_ACCEPTED = /* @__PURE__ */ new Set(["help", "h", "version"]);
|
|
44047
|
+
function subCommandsOf(command) {
|
|
44048
|
+
const sub = command.subCommands;
|
|
44049
|
+
return sub && typeof sub === "object" ? sub : null;
|
|
44050
|
+
}
|
|
44051
|
+
function argsOf(command) {
|
|
44052
|
+
const args = command.args;
|
|
44053
|
+
return args && typeof args === "object" ? args : null;
|
|
44054
|
+
}
|
|
44055
|
+
function resolveCommand2(root, argv) {
|
|
44056
|
+
let command = root;
|
|
44057
|
+
for (const token of argv) {
|
|
44058
|
+
if (token === "--" || token.startsWith("-")) {
|
|
44059
|
+
break;
|
|
44060
|
+
}
|
|
44061
|
+
const subCommands = subCommandsOf(command);
|
|
44062
|
+
if (!subCommands) {
|
|
44063
|
+
break;
|
|
44064
|
+
}
|
|
44065
|
+
const next = subCommands[token];
|
|
44066
|
+
if (next === void 0) {
|
|
44067
|
+
break;
|
|
44068
|
+
}
|
|
44069
|
+
if (typeof next !== "object") {
|
|
44070
|
+
return { command, resolved: false };
|
|
44071
|
+
}
|
|
44072
|
+
command = next;
|
|
44073
|
+
}
|
|
44074
|
+
return { command, resolved: true };
|
|
44075
|
+
}
|
|
44076
|
+
function typeOf(def) {
|
|
44077
|
+
return def && typeof def === "object" ? def.type : void 0;
|
|
44078
|
+
}
|
|
44079
|
+
function acceptedNames(command) {
|
|
44080
|
+
const args = argsOf(command);
|
|
44081
|
+
if (!args) {
|
|
44082
|
+
return null;
|
|
44083
|
+
}
|
|
44084
|
+
const names = new Set(ALWAYS_ACCEPTED);
|
|
44085
|
+
for (const [name, def] of Object.entries(args)) {
|
|
44086
|
+
if (typeOf(def) === "positional") {
|
|
44087
|
+
continue;
|
|
44088
|
+
}
|
|
44089
|
+
for (const spelling of [name, kebab(name), camel(name)]) {
|
|
44090
|
+
names.add(spelling);
|
|
44091
|
+
if (typeOf(def) === "boolean") {
|
|
44092
|
+
names.add(`no-${spelling}`);
|
|
44093
|
+
}
|
|
44094
|
+
}
|
|
44095
|
+
}
|
|
44096
|
+
return names;
|
|
44097
|
+
}
|
|
44098
|
+
function kebab(name) {
|
|
44099
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
44100
|
+
}
|
|
44101
|
+
function camel(name) {
|
|
44102
|
+
return name.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
44103
|
+
}
|
|
44104
|
+
function findUnknownFlags(root, argv) {
|
|
44105
|
+
const { command, resolved } = resolveCommand2(root, argv);
|
|
44106
|
+
if (!resolved) {
|
|
44107
|
+
return [];
|
|
44108
|
+
}
|
|
44109
|
+
const accepted = acceptedNames(command);
|
|
44110
|
+
if (!accepted) {
|
|
44111
|
+
return [];
|
|
44112
|
+
}
|
|
44113
|
+
const unknown = [];
|
|
44114
|
+
for (const token of argv) {
|
|
44115
|
+
if (token === "--") {
|
|
44116
|
+
break;
|
|
44117
|
+
}
|
|
44118
|
+
if (!token.startsWith("--")) {
|
|
44119
|
+
continue;
|
|
44120
|
+
}
|
|
44121
|
+
const name = token.slice(2).split("=")[0] ?? "";
|
|
44122
|
+
if (name.length > 0 && !accepted.has(name) && !unknown.includes(token)) {
|
|
44123
|
+
unknown.push(token);
|
|
44124
|
+
}
|
|
44125
|
+
}
|
|
44126
|
+
return unknown;
|
|
44127
|
+
}
|
|
44128
|
+
function closestFlag(unknown, command) {
|
|
44129
|
+
const accepted = acceptedNames(command);
|
|
44130
|
+
if (!accepted) {
|
|
44131
|
+
return null;
|
|
44132
|
+
}
|
|
44133
|
+
const name = unknown.replace(/^--/, "").split("=")[0] ?? "";
|
|
44134
|
+
const scored = [...accepted].filter((candidate) => !ALWAYS_ACCEPTED.has(candidate)).map((candidate) => ({
|
|
44135
|
+
candidate,
|
|
44136
|
+
prefix: sharedPrefix(name, candidate),
|
|
44137
|
+
distance: editDistance(name, candidate)
|
|
44138
|
+
})).filter(({ prefix, distance }) => prefix >= 4 || distance <= 3).sort((a, b) => b.prefix - a.prefix || a.distance - b.distance);
|
|
44139
|
+
return scored[0] ? `--${scored[0].candidate}` : null;
|
|
44140
|
+
}
|
|
44141
|
+
function sharedPrefix(a, b) {
|
|
44142
|
+
let i = 0;
|
|
44143
|
+
while (i < a.length && i < b.length && a[i] === b[i]) {
|
|
44144
|
+
i++;
|
|
44145
|
+
}
|
|
44146
|
+
return i;
|
|
44147
|
+
}
|
|
44148
|
+
function editDistance(a, b) {
|
|
44149
|
+
let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
44150
|
+
for (let i = 1; i <= a.length; i++) {
|
|
44151
|
+
const current = [i];
|
|
44152
|
+
for (let j = 1; j <= b.length; j++) {
|
|
44153
|
+
const substitution = (previous[j - 1] ?? 0) + (a[i - 1] === b[j - 1] ? 0 : 1);
|
|
44154
|
+
current.push(Math.min((previous[j] ?? 0) + 1, (current[j - 1] ?? 0) + 1, substitution));
|
|
44155
|
+
}
|
|
44156
|
+
previous = current;
|
|
44157
|
+
}
|
|
44158
|
+
return previous[b.length] ?? 0;
|
|
44159
|
+
}
|
|
44160
|
+
function commandFor(root, argv) {
|
|
44161
|
+
const { command, resolved } = resolveCommand2(root, argv);
|
|
44162
|
+
return resolved ? command : null;
|
|
44163
|
+
}
|
|
44164
|
+
function unknownFlagEnvelope(unknown, commandPath, suggestion) {
|
|
44165
|
+
const list = unknown.join(", ");
|
|
44166
|
+
return {
|
|
44167
|
+
ok: false,
|
|
44168
|
+
error: {
|
|
44169
|
+
code: "UNKNOWN_ARGUMENT",
|
|
44170
|
+
message: `${list} ${unknown.length > 1 ? "are not options" : "is not an option"} of \`baker ${commandPath}\`.`,
|
|
44171
|
+
fix: {
|
|
44172
|
+
action: "check_schema",
|
|
44173
|
+
explanation: (suggestion ? `Did you mean ${suggestion}? ` : "") + `Run \`baker schema ${commandPath}\` to see every option this command takes. Do not re-run the same call: until this version an unrecognised option was accepted and ignored, so a command that looked like it had filtered or narrowed the result was in fact answering the unfiltered question.`
|
|
44174
|
+
},
|
|
44175
|
+
retryable: false
|
|
44176
|
+
}
|
|
44177
|
+
};
|
|
44178
|
+
}
|
|
44179
|
+
function commandPathOf(root, argv) {
|
|
44180
|
+
const path37 = [];
|
|
44181
|
+
let command = root;
|
|
44182
|
+
for (const token of argv) {
|
|
44183
|
+
if (token === "--" || token.startsWith("-")) {
|
|
44184
|
+
break;
|
|
44185
|
+
}
|
|
44186
|
+
const subCommands = subCommandsOf(command);
|
|
44187
|
+
const next = subCommands?.[token];
|
|
44188
|
+
if (next === void 0 || typeof next !== "object") {
|
|
44189
|
+
break;
|
|
44190
|
+
}
|
|
44191
|
+
path37.push(token);
|
|
44192
|
+
command = next;
|
|
44193
|
+
}
|
|
44194
|
+
return path37.join(" ");
|
|
44195
|
+
}
|
|
44196
|
+
function refuseUnknownFlags(root, argv) {
|
|
44197
|
+
const unknown = findUnknownFlags(root, argv);
|
|
44198
|
+
if (unknown.length === 0) {
|
|
44199
|
+
return;
|
|
44200
|
+
}
|
|
44201
|
+
const command = commandFor(root, argv);
|
|
44202
|
+
const first = unknown[0];
|
|
44203
|
+
const suggestion = command && first ? closestFlag(first, command) : null;
|
|
44204
|
+
process.stdout.write(
|
|
44205
|
+
`${JSON.stringify(unknownFlagEnvelope(unknown, commandPathOf(root, argv), suggestion), null, 2)}
|
|
44206
|
+
`
|
|
44207
|
+
);
|
|
44208
|
+
process.exit(1);
|
|
44209
|
+
}
|
|
44210
|
+
|
|
44045
44211
|
// src/version.ts
|
|
44046
44212
|
import { readFileSync as readFileSync14 } from "fs";
|
|
44047
44213
|
function packageJsonUrl() {
|
|
@@ -44101,5 +44267,6 @@ Introspection: Run 'baker schema <command>' to inspect argument schemas.`
|
|
|
44101
44267
|
});
|
|
44102
44268
|
installStreamTaps();
|
|
44103
44269
|
logInvocation(process.argv.slice(2));
|
|
44270
|
+
refuseUnknownFlags(main, process.argv.slice(2));
|
|
44104
44271
|
runMain(main);
|
|
44105
44272
|
//# sourceMappingURL=cli.js.map
|