Skip to content

Commit

Permalink
fix: args forwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jan 18, 2023
1 parent ec62f2c commit 5a9d636
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/commands/readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {URL} from 'url'

import {castArray, compact, sortBy, template, uniqBy} from '../util'
import {HelpCompatibilityWrapper} from '../help-compatibility'
import {ArgInput} from '@oclif/core/lib/interfaces'

const normalize = require('normalize-package-data')
const columns = Number.parseInt(process.env.COLUMNS!, 10) || 120
Expand Down Expand Up @@ -254,11 +255,13 @@ USAGE
return `[${name}]`
}

// v2 commands have args as an object, so we need to normalize it to an array for forwards compatibility
const normalized = (Array.isArray(command.args) ? command.args ?? [] : Object.values(command.args ?? {})) as ArgInput
const id = toConfiguredId(command.id, config)
const defaultUsage = () => {
return compact([
id,
command.args.filter(a => !a.hidden).map(a => arg(a)).join(' '),
normalized.filter(a => !a.hidden).map(a => arg(a)).join(' '),
]).join(' ')
}

Expand Down

0 comments on commit 5a9d636

Please sign in to comment.