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

Commit

Permalink
fix: fixed case when not calling dependsOn flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Apr 9, 2018
1 parent 7dbde11 commit 76c1c5a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ export function validate(parse: { input: ParserInput; output: ParserOutput<any,

function validateFlags() {
for (let [name, flag] of Object.entries(parse.input.flags)) {
if (flag.required && !parse.output.flags[name]) {
throw new RequiredFlagError({parse, flag})
}
for (let also of flag.dependsOn || []) {
if (!parse.output.flags[also]) {
throw new CLIError(`--${also}= must also be provided when using --${name}=`)
if (parse.output.flags[name]) {
for (let also of flag.dependsOn || []) {
if (!parse.output.flags[also]) {
throw new CLIError(`--${also}= must also be provided when using --${name}=`)
}
}
} else {
if (flag.required) throw new RequiredFlagError({parse, flag})
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,15 @@ See more help with --help`)
})

describe('dependsOn', () => {
it('ignores', () => {
parse([], {
flags: {
foo: flags.string({dependsOn: ['bar']}),
bar: flags.string({char: 'b'}),
},
})
})

it('succeeds', () => {
const out = parse(['--foo', 'a', '-bb'], {
flags: {
Expand Down

0 comments on commit 76c1c5a

Please sign in to comment.