Skip to content

Commit

Permalink
fix(access): only complete once
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored and fritzy committed Mar 2, 2023
1 parent b43961a commit fc46489
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/commands/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,22 @@ class Access extends BaseCommand {
return commands
}

switch (argv[2]) {
case 'grant':
return ['read-only', 'read-write']
case 'revoke':
return []
case 'list':
case 'ls':
return ['packages', 'collaborators']
case 'get':
return ['status']
case 'set':
return setCommands
default:
throw new Error(argv[2] + ' not recognized')
if (argv.length === 3) {
switch (argv[2]) {
case 'grant':
return ['read-only', 'read-write']
case 'revoke':
return []
case 'list':
case 'ls':
return ['packages', 'collaborators']
case 'get':
return ['status']
case 'set':
return setCommands
default:
throw new Error(argv[2] + ' not recognized')
}
}
}

Expand Down
1 change: 1 addition & 0 deletions test/lib/commands/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ t.test('completion', async t => {
])
testComp(['npm', 'access', 'grant'], ['read-only', 'read-write'])
testComp(['npm', 'access', 'revoke'], [])
testComp(['npm', 'access', 'grant', ''], [])

await t.rejects(
access.completion({ conf: { argv: { remain: ['npm', 'access', 'foobar'] } } }),
Expand Down

0 comments on commit fc46489

Please sign in to comment.