Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/__test__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test('negated option', () => {

cli.option('--foo [foo]', 'Set foo').option('--no-foo', 'Disable foo')

cli.option('--bar [bar]', 'Set bar').option('--no-bar', 'Disable bar')
cli.option('--bar', 'Set bar').option('--no-bar', 'Disable bar')

const { options } = cli.parse(['node', 'bin', '--foo', 'foo', '--bar'])
expect(options).toEqual({
Expand Down Expand Up @@ -115,7 +115,7 @@ test('array types without transformFunction', () => {
type: [],
}
)
.option('--scale [level]', 'Scaling level')
.option('--scale', 'Scaling level')

const { options: options1 } = cli.parse(
`node bin --externals.env.prod production --scale`.split(' ')
Expand All @@ -142,7 +142,7 @@ test('array types with transformFunction', () => {
.option('--config <configFlie>', 'Use config file for building', {
type: [String],
})
.option('--scale [level]', 'Scaling level')
.option('--scale', 'Scaling level')

const { options } = cli.parse(
`node bin build app.js --config config.js --scale`.split(' ')
Expand Down
9 changes: 6 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const findAllBrackets = (v: string) => {
return {
required: match[0].startsWith('<'),
value,
variadic
variadic,
}
}

Expand All @@ -40,10 +40,11 @@ interface MriOptions {
[k: string]: string[]
}
boolean: string[]
string: string[]
}

export const getMriOptions = (options: Option[]) => {
const result: MriOptions = { alias: {}, boolean: [] }
const result: MriOptions = { alias: {}, boolean: [], string: [] }

for (const [index, option] of options.entries()) {
// We do not set default values in mri options
Expand All @@ -62,7 +63,7 @@ export const getMriOptions = (options: Option[]) => {
const hasStringTypeOption = options.some((o, i) => {
return (
i !== index &&
o.names.some(name => option.names.includes(name)) &&
o.names.some((name) => option.names.includes(name)) &&
typeof o.required === 'boolean'
)
})
Expand All @@ -72,6 +73,8 @@ export const getMriOptions = (options: Option[]) => {
} else {
result.boolean.push(option.names[0])
}
} else {
result.string.push(option.names[0])
}
}

Expand Down