This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ignore defaulted flags for exclusivity
- Loading branch information
Showing
5 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type Metadata = { | ||
flags: { [key: string]: MetadataFlag } | ||
} | ||
|
||
type MetadataFlag = { | ||
setFromDefault?: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import {expect} from 'chai' | ||
|
||
import {validate} from '../src/validate' | ||
|
||
describe('validate', () => { | ||
const input = { | ||
argv: [], | ||
flags: { | ||
dinner: { | ||
description: 'what you want to eat for dinner', | ||
input: [], | ||
name: 'dinner', | ||
exclusive: ['dessert'], | ||
}, | ||
dessert: { | ||
description: 'what you want to eat for dessert', | ||
default: 'cheesecake', | ||
input: [], | ||
name: 'dessert', | ||
exclusive: [], | ||
} | ||
}, | ||
args: [], | ||
strict: true, | ||
context: {}, | ||
'--': true | ||
} | ||
|
||
it('enforces exclusivity for flags', () => { | ||
const output = { | ||
args: {}, | ||
argv: [], | ||
flags: { | ||
dinner: 'pizza', | ||
dessert: 'cheesecake' | ||
}, | ||
raw: [{ | ||
type: 'flag', | ||
flag: 'dinner', | ||
input: 'pizza' | ||
}], | ||
metadata: { | ||
flags: { | ||
dessert: { | ||
setFromDefault: false | ||
} | ||
} | ||
} | ||
} | ||
|
||
// @ts-ignore | ||
expect(validate.bind({input, output})).to.throw() | ||
}) | ||
|
||
it('ignores exclusivity for defaulted flags', () => { | ||
const output = { | ||
args: {}, | ||
argv: [], | ||
flags: { | ||
dinner: 'pizza', | ||
dessert: 'cheesecake' | ||
}, | ||
raw: [{ | ||
type: 'flag', | ||
flag: 'dinner', | ||
input: 'pizza' | ||
}], | ||
metadata: { | ||
flags: { | ||
dessert: { | ||
setFromDefault: true | ||
} | ||
} | ||
} | ||
} | ||
|
||
// @ts-ignore | ||
validate({input, output}) | ||
}) | ||
}) |