@@ -3,10 +3,9 @@ const path = require('path')
33const libaccess = require ( 'libnpmaccess' )
44const readPackageJson = require ( 'read-package-json-fast' )
55
6- const output = require ( './utils/output.js' )
76const otplease = require ( './utils/otplease.js' )
8- const usageUtil = require ( './utils/usage.js' )
97const getIdentity = require ( './utils/get-identity.js' )
8+ const BaseCommand = require ( './base-command.js' )
109
1110const subcommands = [
1211 'public' ,
@@ -20,24 +19,23 @@ const subcommands = [
2019 '2fa-not-required' ,
2120]
2221
23- class Access {
24- constructor ( npm ) {
25- this . npm = npm
22+ class Access extends BaseCommand {
23+ static get name ( ) {
24+ return 'access'
2625 }
2726
28- get usage ( ) {
29- return usageUtil (
30- 'access' ,
31- 'npm access public [<package>]\n' +
32- 'npm access restricted [<package>]\n' +
33- 'npm access grant <read-only|read-write> <scope:team> [<package>]\n' +
34- 'npm access revoke <scope:team> [<package>]\n' +
35- 'npm access 2fa-required [<package>]\n' +
36- 'npm access 2fa-not-required [<package>]\n' +
37- 'npm access ls-packages [<user>|<scope>|<scope:team>]\n' +
38- 'npm access ls-collaborators [<package> [<user>]]\n' +
39- 'npm access edit [<package>]'
40- )
27+ static get usage ( ) {
28+ return [
29+ 'public [<package>]' ,
30+ 'restricted [<package>]' ,
31+ 'grant <read-only|read-write> <scope:team> [<package>]' ,
32+ 'revoke <scope:team> [<package>]' ,
33+ '2fa-required [<package>]' ,
34+ '2fa-not-required [<package>]' ,
35+ 'ls-packages [<user>|<scope>|<scope:team>]' ,
36+ 'ls-collaborators [<package> [<user>]]' ,
37+ 'edit [<package>]' ,
38+ ]
4139 }
4240
4341 async completion ( opts ) {
@@ -67,12 +65,7 @@ class Access {
6765 }
6866
6967 exec ( args , cb ) {
70- this . access ( args )
71- . then ( x => cb ( null , x ) )
72- . catch ( err => err . code === 'EUSAGE'
73- ? cb ( err . message )
74- : cb ( err )
75- )
68+ this . access ( args ) . then ( ( ) => cb ( ) ) . catch ( cb )
7669 }
7770
7871 async access ( [ cmd , ...args ] ) {
@@ -157,7 +150,7 @@ class Access {
157150 const pkgs = await libaccess . lsPackages ( owner , opts )
158151
159152 // TODO - print these out nicely (breaking change)
160- output ( JSON . stringify ( pkgs , null , 2 ) )
153+ this . npm . output ( JSON . stringify ( pkgs , null , 2 ) )
161154 }
162155
163156 get [ 'ls-collaborators' ] ( ) {
@@ -169,7 +162,7 @@ class Access {
169162 const collabs = await libaccess . lsCollaborators ( pkgName , usr , opts )
170163
171164 // TODO - print these out nicely (breaking change)
172- output ( JSON . stringify ( collabs , null , 2 ) )
165+ this . npm . output ( JSON . stringify ( collabs , null , 2 ) )
173166 }
174167
175168 async edit ( ) {
@@ -203,12 +196,6 @@ class Access {
203196 return name
204197 }
205198 }
206-
207- usageError ( msg ) {
208- return Object . assign ( new Error ( `\nUsage: ${ msg } \n\n` + this . usage ) , {
209- code : 'EUSAGE' ,
210- } )
211- }
212199}
213200
214201module . exports = Access
0 commit comments