Skip to content

Commit f14e46e

Browse files
rexxarsclaude
andcommitted
fix(create-sanity): improve help output and alias conflict detection
- Use helpLabel when defined (e.g. --[no-]git) - Show --[no-] prefix for allowNo boolean flags - Wrap long descriptions to terminal width - Show --help in the options list - Error when both a flag and its alias are passed (--project + --project-id) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0e16428 commit f14e46e

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

packages/create-sanity/src/parseArgs.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ function normalizeFlags(
7272
// Resolve aliases to canonical names
7373
for (const [alias, canonical] of aliasMap) {
7474
if (merged[alias] !== undefined) {
75+
if (merged[canonical] !== undefined) {
76+
console.error(`--${alias} cannot be used with --${canonical}`)
77+
process.exit(2)
78+
}
7579
merged[canonical] = merged[alias]
7680
delete merged[alias]
7781
}
@@ -115,17 +119,54 @@ function normalizeFlags(
115119

116120
function printHelp(): never {
117121
const cmd = getCreateCommand({withFlagSeparator: true})
122+
const width = process.stdout.columns || 80
123+
const labelWidth = 36
124+
const descWidth = Math.max(width - labelWidth - 2, 20)
125+
118126
console.log(`Usage: ${cmd} [options]`)
119127
console.log('')
120128
console.log('Initialize a new Sanity project')
121129
console.log('')
122130
console.log('Options:')
123131
for (const [name, def] of Object.entries<FlagDef>(initFlagDefs)) {
124132
if (def.hidden) continue
125-
const flag = def.short ? `-${def.short}, --${name}` : ` --${name}`
126-
const val = def.type === 'string' && def.helpValue ? ` ${def.helpValue}` : ''
127-
console.log(` ${(flag + val).padEnd(36)} ${def.description || ''}`)
133+
134+
let label: string
135+
if (def.helpLabel) {
136+
label = def.helpLabel
137+
} else {
138+
const prefix = def.allowNo ? '--[no-]' : '--'
139+
const flagName = def.short ? `-${def.short}, ${prefix}${name}` : ` ${prefix}${name}`
140+
const val = def.type === 'string' && def.helpValue ? ` ${def.helpValue}` : ''
141+
label = flagName + val
142+
}
143+
144+
const desc = def.description || ''
145+
const paddedLabel = ` ${label.padEnd(labelWidth)}`
146+
147+
if (desc.length <= descWidth) {
148+
console.log(`${paddedLabel}${desc}`)
149+
} else {
150+
// Wrap long descriptions
151+
const words = desc.split(' ')
152+
let line = ''
153+
let first = true
154+
for (const word of words) {
155+
if (line.length + word.length + 1 > descWidth && line) {
156+
console.log(first ? `${paddedLabel}${line}` : ` ${''.padEnd(labelWidth)}${line}`)
157+
line = word
158+
first = false
159+
} else {
160+
line = line ? `${line} ${word}` : word
161+
}
162+
}
163+
if (line) {
164+
console.log(first ? `${paddedLabel}${line}` : ` ${''.padEnd(labelWidth)}${line}`)
165+
}
166+
}
128167
}
168+
console.log('')
169+
console.log(` -h, --help${' '.padEnd(labelWidth - 12)}Show this help message`)
129170
process.exit(0)
130171
}
131172

0 commit comments

Comments
 (0)