Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Have implementation for --no-* flags reflect documentation. #33

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function boolean<T = boolean>(options: Partial<IBooleanFlag<T>> = {}): IB
return {
parse: (b, _) => b,
...options,
allowNo: !!options.allowNo,
allowNo: options.allowNo !== false,
type: 'boolean',
} as IBooleanFlag<T>
}
Expand Down
19 changes: 19 additions & 0 deletions test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ describe('parse', () => {
expect(out).to.deep.include({flags: {bool: true}})
})

it('--no-bool works by default', () => {
const out = parse(['--no-bool'], {
flags: {
bool: flags.boolean(),
},
})
expect(out).to.deep.include({flags: {bool: false}})
})

it('--no-bool is disabled with allowNo', () => {
expect(() => {
parse(['--no-bool'], {
flags: {
bool: flags.boolean({allowNo: false}),
},
})
}).to.throw(/Unexpected argument: --no-bool/)
})

it('arg1', () => {
const out = parse(['arg1'], {
args: [{name: 'foo'}],
Expand Down