Skip to content

Commit 5e95db5

Browse files
committed
improve help
1 parent f7a3021 commit 5e95db5

5 files changed

Lines changed: 48 additions & 21 deletions

File tree

COMMANDS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ iterable campaigns list
148148

149149
| Option | Type | Required | Description |
150150
|--------|------|----------|-------------|
151-
| `--campaignState` | enum[] | no | Filter campaigns by state. Can specify multiple states. Valid states: Draft, Ready, Scheduled, Running, Finished, Starting, Aborted, Recurring, Archived |
151+
| `--campaignState` | `Draft` \| `Ready` \| `Scheduled` \| `Running` \| `Finished` \| `Starting` \| `Aborted` \| `Recurring` \| `Archived` | no | Filter campaigns by state |
152152
| `--order` | `asc` \| `desc` | no | Sort direction (asc or desc) |
153153
| `--page` | number | no | Page number (starting at 1) |
154154
| `--pageSize` | number | no | Number of results to return per page (defaults to 20, maximum of 1000) |
@@ -1005,7 +1005,7 @@ iterable subscriptions bulk-update --action <action> --subscriptionGroup <subscr
10051005

10061006
| Option | Type | Required | Description |
10071007
|--------|------|----------|-------------|
1008-
| `--action` | `subscribe` \| `unsubscribe` | **yes** | Action to perform: subscribe or unsubscribe |
1008+
| `--action` | `subscribe` \| `unsubscribe` | **yes** | Action to perform |
10091009
| `--subscriptionGroup` | `emailList` \| `messageType` \| `messageChannel` | **yes** | Type of subscription group |
10101010
| `--subscriptionGroupId` | number | **yes** | Subscription Group Id |
10111011
| `--users` | string[] | no | Users to subscribe/unsubscribe, identified by email |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"update-commands": "node scripts/update-commands.js"
6060
},
6161
"dependencies": {
62-
"@iterable/api": "0.10.0",
62+
"@iterable/api": "0.10.1",
6363
"@primno/dpapi": "2.0.1",
6464
"boxen": "8.0.1",
6565
"chalk": "5.6.2",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ function getZodTypeName(schema: z.ZodType): string {
109109
function getEnumValues(schema: z.ZodType): string[] | undefined {
110110
const inner = unwrapSchema(schema);
111111
if (inner instanceof z.ZodEnum) return inner.options as string[];
112+
if (inner instanceof z.ZodArray) {
113+
const element = unwrapSchema(inner.element as z.ZodType);
114+
if (element instanceof z.ZodEnum) return element.options as string[];
115+
}
112116
return undefined;
113117
}
114118

src/router.ts

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,24 @@ function flagLabel(def: FlagDef): string {
197197
return def.helpArg ? `${names} ${def.helpArg}` : names;
198198
}
199199

200-
function formatOptionLines(
201-
options: { label: string; desc: string }[]
202-
): string[] {
200+
interface OptionLine {
201+
label: string;
202+
desc: string;
203+
extra?: string | undefined;
204+
}
205+
206+
function formatOptionLines(options: OptionLine[]): string[] {
203207
if (options.length === 0) return [];
204208
const maxLen = Math.max(...options.map((o) => o.label.length));
205-
return options.map(
206-
(o) => ` ${theme.accent(o.label.padEnd(maxLen + 2))} ${o.desc}`
207-
);
209+
const pad = maxLen + 4;
210+
const lines: string[] = [];
211+
for (const o of options) {
212+
lines.push(` ${theme.accent(o.label.padEnd(maxLen + 2))} ${o.desc}`);
213+
if (o.extra) {
214+
lines.push(` ${"".padEnd(pad)}${theme.muted(o.extra)}`);
215+
}
216+
}
217+
return lines;
208218
}
209219

210220
const COMMAND_RELEVANT_FLAGS = new Set<string>(["output", "columns", "file"]);
@@ -222,19 +232,32 @@ export function showCommandHelp(
222232
command.description,
223233
];
224234

225-
const options: { label: string; desc: string }[] = [];
235+
const options: OptionLine[] = [];
226236

227237
for (const f of fields) {
228-
const label = f.isPositional
229-
? `<${f.name}>`
230-
: f.enumValues
231-
? `--${f.name} <${f.enumValues.join("|")}>`
232-
: `--${f.name} <${f.type}>`;
238+
const isArray = f.type.endsWith("[]");
239+
const enumInline = f.enumValues && f.enumValues.join("|").length <= 30;
240+
let label: string;
241+
if (f.isPositional) {
242+
label = `<${f.name}>`;
243+
} else if (f.enumValues && enumInline) {
244+
label = `--${f.name} <${f.enumValues.join("|")}>`;
245+
} else if (f.enumValues) {
246+
label = isArray ? `--${f.name} <value ...>` : `--${f.name} <value>`;
247+
} else if (isArray) {
248+
label = `--${f.name} <${f.name} ...>`;
249+
} else {
250+
label = `--${f.name} <${f.type}>`;
251+
}
233252
let desc = f.description;
234253
if (f.defaultValue !== undefined)
235254
desc += ` (default: ${JSON.stringify(f.defaultValue)})`;
236255
if (f.required) desc += theme.muted(" (required)");
237-
options.push({ label, desc });
256+
const extra =
257+
f.enumValues && !enumInline
258+
? `[values: ${f.enumValues.join(", ")}]`
259+
: undefined;
260+
options.push({ label, desc, extra });
238261
}
239262

240263
for (const def of FLAG_DEFS) {

0 commit comments

Comments
 (0)