Skip to content

Commit bcc1369

Browse files
committed
[skip ci] Update help text generator for CLI
1 parent b10a494 commit bcc1369

File tree

4 files changed

+55
-19
lines changed

4 files changed

+55
-19
lines changed

products/jbrowse-cli/src/commands/add-assembly/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function run(args?: string[]) {
1515
type: {
1616
type: 'string',
1717
short: 't',
18-
description: `type of sequence, by default inferred from sequence file\n\nindexedFasta An index FASTA (e.g. .fa or .fasta) file;\n can optionally specify --faiLocation\n\nbgzipFasta A block-gzipped and indexed FASTA (e.g. .fa.gz or .fasta.gz) file;\n can optionally specify --faiLocation and/or --gziLocation\n\ntwoBit A twoBit (e.g. .2bit) file\n\nchromSizes A chromosome sizes (e.g. .chrom.sizes) file\n\ncustom Either a JSON file location or inline JSON that defines a custom\n sequence adapter; must provide --name if using inline JSON`,
18+
description: `type of sequence, by default inferred from sequence file\n\nindexedFasta - An index FASTA (e.g. .fa or .fasta) file; can optionally specify --faiLocation\n\nbgzipFasta - A block-gzipped and indexed FASTA (e.g. .fa.gz or .fasta.gz) file; can optionally specify --faiLocation and/or --gziLocation\n\ntwoBit - A twoBit (e.g. .2bit) file\n\nchromSizes - A chromosome sizes (e.g. .chrom.sizes) file\n\ncustom - Either a JSON file location or inline JSON that defines a custom sequence adapter; must provide --name if using inline JSON`,
1919
choices: ['indexedFasta', 'bgzipFasta', 'twoBit', 'chromSizes', 'custom'],
2020
},
2121
name: {
@@ -28,7 +28,7 @@ export async function run(args?: string[]) {
2828
type: 'string',
2929
short: 'a',
3030
description:
31-
'An alias for the assembly name (e.g. "hg38" if the name of the assembly is "GRCh38");\ncan be specified multiple times',
31+
'An alias for the assembly name (e.g. "hg38" if the name of the assembly is "GRCh38"); can be specified multiple times',
3232
multiple: true,
3333
},
3434
displayName: {
@@ -48,24 +48,24 @@ export async function run(args?: string[]) {
4848
refNameAliases: {
4949
type: 'string',
5050
description:
51-
'Reference sequence name aliases file or URL; assumed to be a tab-separated aliases\nfile unless --refNameAliasesType is specified',
51+
'Reference sequence name aliases file or URL; assumed to be a tab-separated aliases file unless --refNameAliasesType is specified',
5252
},
5353
refNameAliasesType: {
5454
type: 'string',
5555
description:
56-
'Type of aliases defined by --refNameAliases; if "custom", --refNameAliases is either\na JSON file location or inline JSON that defines a custom sequence adapter',
56+
'Type of aliases defined by --refNameAliases; if "custom", --refNameAliases is either a JSON file location or inline JSON that defines a custom sequence adapter',
5757
choices: ['aliases', 'custom'],
5858
dependsOn: ['refNameAliases'],
5959
},
6060
refNameColors: {
6161
type: 'string',
6262
description:
63-
'A comma-separated list of color strings for the reference sequence names; will cycle\nthrough colors if there are fewer colors than sequences',
63+
'A comma-separated list of color strings for the reference sequence names; will cycle through colors if there are fewer colors than sequences',
6464
},
6565
target: {
6666
type: 'string',
6767
description:
68-
'path to config file in JB2 installation directory to write out to.\nCreates ./config.json if nonexistent',
68+
'path to config file in JB2 installation directory to write out to. Creates ./config.json if nonexistent',
6969
},
7070
out: {
7171
type: 'string',

products/jbrowse-cli/src/commands/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const options = {
6767
type: 'string',
6868
short: 't',
6969
description:
70-
'Version of JBrowse 2 to install. Format is v1.0.0.\nDefaults to latest',
70+
'Version of JBrowse 2 to install. Format is v1.0.0. Defaults to latest',
7171
},
7272
} as const
7373

products/jbrowse-cli/src/commands/upgrade.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const options = {
5151
type: 'string',
5252
short: 't',
5353
description:
54-
'Version of JBrowse 2 to install. Format is v1.0.0.\nDefaults to latest',
54+
'Version of JBrowse 2 to install. Format is v1.0.0. Defaults to latest',
5555
},
5656
branch: {
5757
type: 'string',

products/jbrowse-cli/src/utils.ts

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,34 @@ export async function getBranch(branch: string) {
170170
return `https://s3.amazonaws.com/jbrowse.org/code/jb2/${branch}/jbrowse-web-${branch}.zip`
171171
}
172172

173+
function wrapText(text: string, width: number, indent: string) {
174+
// Normalize: join single \n into spaces, preserve \n\n as paragraph breaks
175+
const normalized = text.replace(/\n\n/g, '\0').replace(/\n/g, ' ').replace(/\0/g, '\n\n')
176+
const lines = []
177+
for (const line of normalized.split('\n')) {
178+
if (line.length <= width) {
179+
lines.push(line)
180+
} else {
181+
const words = line.split(' ')
182+
let current = ''
183+
for (const word of words) {
184+
if (current.length + word.length + 1 <= width) {
185+
current += (current ? ' ' : '') + word
186+
} else {
187+
if (current) {
188+
lines.push(current)
189+
}
190+
current = word
191+
}
192+
}
193+
if (current) {
194+
lines.push(current)
195+
}
196+
}
197+
}
198+
return lines.join('\n' + indent)
199+
}
200+
173201
export function printHelp({
174202
description,
175203
options,
@@ -181,20 +209,28 @@ export function printHelp({
181209
examples: string[]
182210
usage?: string
183211
}) {
212+
const termWidth = process.stdout.columns || 80
184213
console.log(description)
185214
console.log(`\nUsage: ${usage || 'jbrowse <command> [options]'}`)
186215
console.log('\nOptions:')
187216
for (const [name, option] of Object.entries(options)) {
188-
const short =
189-
'short' in (option as any) && (option as any).short
190-
? `-${(option as any).short}`
191-
: ' '
192-
const namePadded = `--${name}`.padEnd(25, ' ')
193-
const desc = (option as any).description?.replace(
194-
/\n/g,
195-
`\n${' '.repeat(29)}`,
196-
)
197-
console.log(` ${short}, ${namePadded} ${desc}`)
217+
const opt = option as Record<string, unknown>
218+
const shortFlag = opt.short
219+
const prefix = shortFlag ? ` -${shortFlag}, ` : ' '
220+
const namePadded = `--${name}`.padEnd(22, ' ')
221+
const indent = ' '.repeat(prefix.length + namePadded.length + 1)
222+
const descWidth = termWidth - indent.length
223+
224+
let desc = (opt.description as string) || ''
225+
if (opt.choices) {
226+
desc += ` [choices: ${(opt.choices as string[]).join(', ')}]`
227+
}
228+
if (opt.default !== undefined) {
229+
desc += ` [default: ${opt.default}]`
230+
}
231+
232+
const wrapped = desc ? wrapText(desc, descWidth, indent) : ''
233+
console.log(`${prefix}${namePadded} ${wrapped}\n`)
198234
}
199-
console.log(`\n${examples.join('\n')}`)
235+
console.log(examples.join('\n'))
200236
}

0 commit comments

Comments
 (0)