Skip to content

Commit ede37be

Browse files
committed
fix: #113 clean up boolean flag help output
1 parent 04c87be commit ede37be

File tree

5 files changed

+62
-7
lines changed

5 files changed

+62
-7
lines changed

.changeset/odd-kids-wink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'incur': patch
3+
---
4+
5+
Fixed help output for boolean options so flags no longer showed `<boolean>` placeholders or redundant `(default: false)` text, including aliased flags.

src/Help.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,55 @@ describe('formatCommand', () => {
148148
expect(result).toContain('Verbosity level')
149149
})
150150

151+
test('omits value placeholders for boolean flag options', () => {
152+
const result = Help.formatCommand('tool deploy', {
153+
options: z.object({
154+
dryRun: z.boolean().optional().describe('Preview without submitting.'),
155+
}),
156+
})
157+
158+
const line = result.split('\n').find((line) => line.includes('--dry-run'))
159+
160+
expect(line).toBe(' --dry-run Preview without submitting.')
161+
})
162+
163+
test('omits value placeholders for aliased boolean flag options', () => {
164+
const result = Help.formatCommand('tool deploy', {
165+
options: z.object({
166+
dryRun: z.boolean().optional().describe('Preview without submitting.'),
167+
}),
168+
alias: { dryRun: 'd' },
169+
})
170+
171+
const line = result.split('\n').find((line) => line.includes('--dry-run'))
172+
173+
expect(line).toBe(' --dry-run, -d Preview without submitting.')
174+
})
175+
176+
test('omits default false for boolean flag options', () => {
177+
const result = Help.formatCommand('tool deploy', {
178+
options: z.object({
179+
dryRun: z.boolean().default(false).describe('Preview without submitting.'),
180+
}),
181+
})
182+
183+
const line = result.split('\n').find((line) => line.includes('--dry-run'))
184+
185+
expect(line).toBe(' --dry-run Preview without submitting.')
186+
})
187+
188+
test('shows default true for boolean flag options', () => {
189+
const result = Help.formatCommand('tool deploy', {
190+
options: z.object({
191+
watch: z.boolean().default(true).describe('Watch for changes.'),
192+
}),
193+
})
194+
195+
const line = result.split('\n').find((line) => line.includes('--watch'))
196+
197+
expect(line).toBe(' --watch Watch for changes. (default: true)')
198+
})
199+
151200
test('shows enum values for z.enum options', () => {
152201
const result = Help.formatCommand('tool deploy', {
153202
options: z.object({

src/Help.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,10 @@ function optionEntries(
275275
const type = resolveTypeName(field)
276276
const short = alias?.[key]
277277
const kebab = toKebab(key)
278-
const flag = short ? `--${kebab}, -${short} <${type}>` : `--${kebab} <${type}>`
279-
const defaultValue = extractDefault(field)
278+
const valueHint = type === 'boolean' ? '' : ` <${type}>`
279+
const flag = short ? `--${kebab}, -${short}${valueHint}` : `--${kebab}${valueHint}`
280+
let defaultValue = extractDefault(field)
281+
if (type === 'boolean' && defaultValue === false) defaultValue = undefined
280282
const deprecated = extractDeprecated(field)
281283
entries.push({ flag, description: (field as any).description ?? '', defaultValue, deprecated })
282284
}

src/Skill.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ function renderGroup(
130130
prefix?: string | undefined,
131131
): string {
132132
const groupDesc = prefix ? groups.get(prefix) : undefined
133-
const fallbackDesc =
134-
cmds.length === 1 && cmds[0]!.description ? cmds[0]!.description : undefined
133+
const fallbackDesc = cmds.length === 1 && cmds[0]!.description ? cmds[0]!.description : undefined
135134
const desc = groupDesc ?? fallbackDesc
136135
const description = desc
137136
? `${desc.replace(/\.$/, '')}. Run \`${title} --help\` for usage details.`

src/e2e.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ describe('help', () => {
10541054
Options:
10551055
--limit, -l <number> Max results (default: 20)
10561056
--sort, -s <name|created|updated> Sort field (default: name)
1057-
--archived <boolean> Include archived (default: false)
1057+
--archived Include archived
10581058
10591059
Global Options:
10601060
--filter-output <keys> Filter output by key paths (e.g. foo,bar.baz,a[0,3])
@@ -1082,7 +1082,7 @@ describe('help', () => {
10821082
10831083
Options:
10841084
--branch, -b <string> Branch to deploy (default: main)
1085-
--dry-run <boolean> Dry run mode (default: false)
1085+
--dry-run Dry run mode
10861086
10871087
Examples:
10881088
app project deploy create staging # Deploy staging from main
@@ -1918,7 +1918,7 @@ describe('env', () => {
19181918
19191919
Options:
19201920
--hostname, -h <string> API hostname (default: api.example.com)
1921-
--web, -w <boolean> Open browser (default: false)
1921+
--web, -w Open browser
19221922
--scopes <array> OAuth scopes
19231923
19241924
Global Options:

0 commit comments

Comments
 (0)