@@ -6,15 +6,13 @@ help.completion = function (opts, cb) {
66 getSections ( cb )
77}
88
9+ const npmUsage = require ( './utils/npm-usage.js' )
910var path = require ( 'path' )
1011var spawn = require ( './utils/spawn' )
1112var npm = require ( './npm.js' )
1213var log = require ( 'npmlog' )
1314var openUrl = require ( './utils/open-url' )
1415var glob = require ( 'glob' )
15- var didYouMean = require ( './utils/did-you-mean' )
16- var cmdList = require ( './utils/cmd-list' ) . cmdList
17- var commands = cmdList
1816var output = require ( './utils/output.js' )
1917
2018const usage = require ( './utils/usage.js' )
@@ -42,7 +40,8 @@ function help (args, cb) {
4240 // npm help <noargs>: show basic usage
4341 if ( ! section ) {
4442 var valid = argv [ 0 ] === 'help' ? 0 : 1
45- return npmUsage ( valid , cb )
43+ npmUsage ( argv [ 0 ] === 'help' )
44+ return cb ( )
4645 }
4746
4847 // npm <command> -h: show command usage
@@ -161,83 +160,6 @@ function htmlMan (man) {
161160 return 'file://' + path . resolve ( __dirname , '..' , 'docs' , 'public' , sect , f , 'index.html' )
162161}
163162
164- function npmUsage ( valid , cb ) {
165- npm . config . set ( 'loglevel' , 'silent' )
166- log . level = 'silent'
167- output ( `
168- Usage: npm <command>
169-
170- npm install install all the dependencies in your project
171- npm install <foo> add the <foo> dependency to your project
172- npm test run this project's tests
173- npm run <foo> run the script named <foo>
174- npm <command> -h quick help on <command>
175- npm -l display usage info for all commands
176- npm help <term> search for help on <term>
177- npm help npm more involved overview
178-
179- All commands:
180- ${ npm . config . get ( 'long' ) ? usages ( ) : ( '\n ' + wrap ( commands ) ) }
181-
182- Specify configs in the ini-formatted file:
183- ${ npm . config . get ( 'userconfig' ) }
184- or on the command line via: npm <command> --key=value
185-
186- More configuration info: npm help config
187- Configuration fields: npm help 7 config
188-
189- npm@${ npm . version } ${ path . dirname ( __dirname ) }
190- ` )
191-
192- if ( npm . argv . length > 1 ) {
193- output ( didYouMean ( npm . argv [ 1 ] , commands ) )
194- }
195-
196- cb ( valid )
197- }
198-
199- function usages ( ) {
200- // return a string of <command>: <usage>
201- var maxLen = 0
202- return commands . reduce ( function ( set , c ) {
203- set . push ( [ c , require ( `./${ npm . deref ( c ) } .js` ) . usage || '' ] )
204- maxLen = Math . max ( maxLen , c . length )
205- return set
206- } , [ ] ) . sort ( ( a , b ) => {
207- return a [ 0 ] . localeCompare ( b [ 0 ] )
208- } ) . map ( function ( item ) {
209- var c = item [ 0 ]
210- var usage = item [ 1 ]
211- return '\n ' +
212- c + ( new Array ( maxLen - c . length + 2 ) . join ( ' ' ) ) +
213- ( usage . split ( '\n' ) . join ( '\n' + ( new Array ( maxLen + 6 ) . join ( ' ' ) ) ) )
214- } ) . join ( '\n' )
215- }
216-
217- function wrap ( arr ) {
218- var out = [ '' ]
219- var l = 0
220- var line
221-
222- line = process . stdout . columns
223- if ( ! line ) {
224- line = 60
225- } else {
226- line = Math . min ( 60 , Math . max ( line - 16 , 24 ) )
227- }
228-
229- arr . sort ( function ( a , b ) { return a < b ? - 1 : 1 } )
230- . forEach ( function ( c ) {
231- if ( out [ l ] . length + c . length + 2 < line ) {
232- out [ l ] += ', ' + c
233- } else {
234- out [ l ++ ] += ','
235- out [ l ] = c
236- }
237- } )
238- return out . join ( '\n ' ) . substr ( 2 )
239- }
240-
241163function getSections ( cb ) {
242164 var g = path . resolve ( __dirname , '../man/man[0-9]/*.[0-9]' )
243165 glob ( g , function ( er , files ) {
0 commit comments