@asteroidai/cli 1.8.197 → 1.8.204
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/asteroid.js +16 -7
- package/dist/core.js +15 -6
- package/package.json +1 -1
- package/src/program.test.ts +37 -0
- package/src/program.ts +19 -8
package/dist/asteroid.js
CHANGED
|
@@ -4875,16 +4875,25 @@ function defineCommands(root, options, dotted = /* @__PURE__ */ new Map(), onInv
|
|
|
4875
4875
|
const defaults = command.args.map(
|
|
4876
4876
|
(arg) => options.defaultArg?.(command, arg)
|
|
4877
4877
|
);
|
|
4878
|
-
|
|
4878
|
+
const defaulted = defaults[0] !== void 0;
|
|
4879
|
+
command.args.forEach((arg) => {
|
|
4879
4880
|
leaf.argument(
|
|
4880
|
-
|
|
4881
|
+
defaulted ? `[${arg.flag}]` : `<${arg.flag}>`,
|
|
4881
4882
|
arg.description ?? ""
|
|
4882
4883
|
);
|
|
4883
4884
|
});
|
|
4884
|
-
if (
|
|
4885
|
-
|
|
4886
|
-
${
|
|
4885
|
+
if (defaulted) {
|
|
4886
|
+
const names = command.args.map(
|
|
4887
|
+
(arg, i) => i === 0 ? `[${arg.flag}]` : `<${arg.flag}>`
|
|
4888
|
+
);
|
|
4889
|
+
leaf.usage(`[options] ${names.join(" ")}`);
|
|
4887
4890
|
}
|
|
4891
|
+
const notes = [
|
|
4892
|
+
defaults.some((value2) => value2 !== void 0) ? options.defaultArgNote : void 0,
|
|
4893
|
+
options.helpNote?.(command)
|
|
4894
|
+
].filter(Boolean);
|
|
4895
|
+
if (notes.length > 0) leaf.addHelpText("after", `
|
|
4896
|
+
${notes.join("\n")}`);
|
|
4888
4897
|
leafOptions(leaf, command);
|
|
4889
4898
|
leaf.action((...args) => {
|
|
4890
4899
|
const cmd = args.at(-1);
|
|
@@ -4893,7 +4902,7 @@ ${options.defaultArgNote}`);
|
|
|
4893
4902
|
positionals = [defaults[0], ...positionals];
|
|
4894
4903
|
}
|
|
4895
4904
|
if (positionals.length !== command.args.length) {
|
|
4896
|
-
const expected = command.args.map((a) => `<${a.flag}>`).join(" ");
|
|
4905
|
+
const expected = command.args.map((a, i) => i === 0 && defaulted ? `[${a.flag}]` : `<${a.flag}>`).join(" ");
|
|
4897
4906
|
throw new UsageError(
|
|
4898
4907
|
`expected ${expected}, got ${cmd.args.length} argument(s)`
|
|
4899
4908
|
);
|
|
@@ -5303,7 +5312,7 @@ var ApiError = class extends Error {
|
|
|
5303
5312
|
status;
|
|
5304
5313
|
body;
|
|
5305
5314
|
};
|
|
5306
|
-
var VERSION = "1.8.
|
|
5315
|
+
var VERSION = "1.8.204";
|
|
5307
5316
|
function problem(status, body, fallback) {
|
|
5308
5317
|
if (body && typeof body === "object") {
|
|
5309
5318
|
const record2 = body;
|
package/dist/core.js
CHANGED
|
@@ -4808,16 +4808,25 @@ function defineCommands(root, options, dotted = /* @__PURE__ */ new Map(), onInv
|
|
|
4808
4808
|
const defaults = command.args.map(
|
|
4809
4809
|
(arg) => options.defaultArg?.(command, arg)
|
|
4810
4810
|
);
|
|
4811
|
-
|
|
4811
|
+
const defaulted = defaults[0] !== void 0;
|
|
4812
|
+
command.args.forEach((arg) => {
|
|
4812
4813
|
leaf.argument(
|
|
4813
|
-
|
|
4814
|
+
defaulted ? `[${arg.flag}]` : `<${arg.flag}>`,
|
|
4814
4815
|
arg.description ?? ""
|
|
4815
4816
|
);
|
|
4816
4817
|
});
|
|
4817
|
-
if (
|
|
4818
|
-
|
|
4819
|
-
${
|
|
4818
|
+
if (defaulted) {
|
|
4819
|
+
const names = command.args.map(
|
|
4820
|
+
(arg, i) => i === 0 ? `[${arg.flag}]` : `<${arg.flag}>`
|
|
4821
|
+
);
|
|
4822
|
+
leaf.usage(`[options] ${names.join(" ")}`);
|
|
4820
4823
|
}
|
|
4824
|
+
const notes = [
|
|
4825
|
+
defaults.some((value2) => value2 !== void 0) ? options.defaultArgNote : void 0,
|
|
4826
|
+
options.helpNote?.(command)
|
|
4827
|
+
].filter(Boolean);
|
|
4828
|
+
if (notes.length > 0) leaf.addHelpText("after", `
|
|
4829
|
+
${notes.join("\n")}`);
|
|
4821
4830
|
leafOptions(leaf, command);
|
|
4822
4831
|
leaf.action((...args) => {
|
|
4823
4832
|
const cmd = args.at(-1);
|
|
@@ -4826,7 +4835,7 @@ ${options.defaultArgNote}`);
|
|
|
4826
4835
|
positionals = [defaults[0], ...positionals];
|
|
4827
4836
|
}
|
|
4828
4837
|
if (positionals.length !== command.args.length) {
|
|
4829
|
-
const expected = command.args.map((a) => `<${a.flag}>`).join(" ");
|
|
4838
|
+
const expected = command.args.map((a, i) => i === 0 && defaulted ? `[${a.flag}]` : `<${a.flag}>`).join(" ");
|
|
4830
4839
|
throw new UsageError(
|
|
4831
4840
|
`expected ${expected}, got ${cmd.args.length} argument(s)`
|
|
4832
4841
|
);
|
package/package.json
CHANGED
package/src/program.test.ts
CHANGED
|
@@ -96,4 +96,41 @@ describe("parseInvocation", () => {
|
|
|
96
96
|
);
|
|
97
97
|
expect(got.parsed.positionals).toEqual(["chat-wf"]);
|
|
98
98
|
});
|
|
99
|
+
|
|
100
|
+
it("adds a per-command help note", async () => {
|
|
101
|
+
const help = await parseInvocation(["workflow", "get", "--help"], {
|
|
102
|
+
commands: COMMANDS,
|
|
103
|
+
helpNote: (command) =>
|
|
104
|
+
command.tool === "workflow_get" ? "Note for get." : undefined,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(help.kind === "exit" && help.stdout).toContain("Note for get.");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("fills a defaulted first argument ahead of a required one", async () => {
|
|
111
|
+
const options = {
|
|
112
|
+
commands: COMMANDS,
|
|
113
|
+
defaultArg: (_: unknown, arg: { name: string }) =>
|
|
114
|
+
arg.name === "workflowId" ? "chat-wf" : undefined,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const short = command(
|
|
118
|
+
await parseInvocation(["schedule", "get", "s-1"], options),
|
|
119
|
+
);
|
|
120
|
+
expect(short.parsed.positionals).toEqual(["chat-wf", "s-1"]);
|
|
121
|
+
|
|
122
|
+
const full = command(
|
|
123
|
+
await parseInvocation(["schedule", "get", "wf-2", "s-1"], options),
|
|
124
|
+
);
|
|
125
|
+
expect(full.parsed.positionals).toEqual(["wf-2", "s-1"]);
|
|
126
|
+
|
|
127
|
+
const help = await parseInvocation(["schedule", "get", "--help"], options);
|
|
128
|
+
expect(help.kind === "exit" && help.stdout).toContain(
|
|
129
|
+
"[workflow-id] <schedule-id>",
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
await expect(parseInvocation(["schedule", "get"], options)).rejects.toThrow(
|
|
133
|
+
"expected [workflow-id] <schedule-id>, got 0 argument(s)",
|
|
134
|
+
);
|
|
135
|
+
});
|
|
99
136
|
});
|
package/src/program.ts
CHANGED
|
@@ -16,6 +16,7 @@ export interface ProgramOptions {
|
|
|
16
16
|
description?: string;
|
|
17
17
|
defaultArg?: (command: CliCommand, arg: Option) => string | undefined;
|
|
18
18
|
defaultArgNote?: string;
|
|
19
|
+
helpNote?: (command: CliCommand) => string | undefined;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
const DOTTED = /^--([a-z0-9-]+\.[a-z0-9.-]+)(?:=(.*))?$/;
|
|
@@ -155,18 +156,26 @@ export function defineCommands(
|
|
|
155
156
|
const defaults = command.args.map((arg) =>
|
|
156
157
|
options.defaultArg?.(command, arg),
|
|
157
158
|
);
|
|
158
|
-
|
|
159
|
+
const defaulted = defaults[0] !== undefined;
|
|
160
|
+
command.args.forEach((arg) => {
|
|
159
161
|
leaf.argument(
|
|
160
|
-
|
|
162
|
+
defaulted ? `[${arg.flag}]` : `<${arg.flag}>`,
|
|
161
163
|
arg.description ?? "",
|
|
162
164
|
);
|
|
163
165
|
});
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
leaf.
|
|
166
|
+
if (defaulted) {
|
|
167
|
+
const names = command.args.map((arg, i) =>
|
|
168
|
+
i === 0 ? `[${arg.flag}]` : `<${arg.flag}>`,
|
|
169
|
+
);
|
|
170
|
+
leaf.usage(`[options] ${names.join(" ")}`);
|
|
169
171
|
}
|
|
172
|
+
const notes = [
|
|
173
|
+
defaults.some((value) => value !== undefined)
|
|
174
|
+
? options.defaultArgNote
|
|
175
|
+
: undefined,
|
|
176
|
+
options.helpNote?.(command),
|
|
177
|
+
].filter(Boolean);
|
|
178
|
+
if (notes.length > 0) leaf.addHelpText("after", `\n${notes.join("\n")}`);
|
|
170
179
|
leafOptions(leaf, command);
|
|
171
180
|
leaf.action((...args: unknown[]) => {
|
|
172
181
|
const cmd = args.at(-1) as Command;
|
|
@@ -178,7 +187,9 @@ export function defineCommands(
|
|
|
178
187
|
positionals = [defaults[0], ...positionals];
|
|
179
188
|
}
|
|
180
189
|
if (positionals.length !== command.args.length) {
|
|
181
|
-
const expected = command.args
|
|
190
|
+
const expected = command.args
|
|
191
|
+
.map((a, i) => (i === 0 && defaulted ? `[${a.flag}]` : `<${a.flag}>`))
|
|
192
|
+
.join(" ");
|
|
182
193
|
throw new UsageError(
|
|
183
194
|
`expected ${expected}, got ${cmd.args.length} argument(s)`,
|
|
184
195
|
);
|