diff --git a/lib/commands/access.js b/lib/commands/access.js index 23e51f071b112..c8ac83529e58d 100644 --- a/lib/commands/access.js +++ b/lib/commands/access.js @@ -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') + } } } diff --git a/test/lib/commands/access.js b/test/lib/commands/access.js index b0057545ba026..f0117098a5b55 100644 --- a/test/lib/commands/access.js +++ b/test/lib/commands/access.js @@ -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'] } } }),