Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/node_mod.../npm/lib
File: help.js
[0] Fix | Delete
module.exports = help
[1] Fix | Delete
[2] Fix | Delete
help.completion = function (opts, cb) {
[3] Fix | Delete
if (opts.conf.argv.remain.length > 2) return cb(null, [])
[4] Fix | Delete
getSections(cb)
[5] Fix | Delete
}
[6] Fix | Delete
[7] Fix | Delete
var path = require('path')
[8] Fix | Delete
var spawn = require('./utils/spawn')
[9] Fix | Delete
var npm = require('./npm.js')
[10] Fix | Delete
var log = require('npmlog')
[11] Fix | Delete
var openUrl = require('./utils/open-url')
[12] Fix | Delete
var glob = require('glob')
[13] Fix | Delete
var didYouMean = require('./utils/did-you-mean')
[14] Fix | Delete
var cmdList = require('./config/cmd-list').cmdList
[15] Fix | Delete
var shorthands = require('./config/cmd-list').shorthands
[16] Fix | Delete
var commands = cmdList.concat(Object.keys(shorthands))
[17] Fix | Delete
var output = require('./utils/output.js')
[18] Fix | Delete
[19] Fix | Delete
function help (args, cb) {
[20] Fix | Delete
var argv = npm.config.get('argv').cooked
[21] Fix | Delete
[22] Fix | Delete
var argnum = 0
[23] Fix | Delete
if (args.length === 2 && ~~args[0]) {
[24] Fix | Delete
argnum = ~~args.shift()
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
// npm help foo bar baz: search topics
[28] Fix | Delete
if (args.length > 1 && args[0]) {
[29] Fix | Delete
return npm.commands['help-search'](args, argnum, cb)
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
var section = npm.deref(args[0]) || args[0]
[33] Fix | Delete
[34] Fix | Delete
// npm help <noargs>: show basic usage
[35] Fix | Delete
if (!section) {
[36] Fix | Delete
var valid = argv[0] === 'help' ? 0 : 1
[37] Fix | Delete
return npmUsage(valid, cb)
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
// npm <command> -h: show command usage
[41] Fix | Delete
if (npm.config.get('usage') &&
[42] Fix | Delete
npm.commands[section] &&
[43] Fix | Delete
npm.commands[section].usage) {
[44] Fix | Delete
npm.config.set('loglevel', 'silent')
[45] Fix | Delete
log.level = 'silent'
[46] Fix | Delete
output(npm.commands[section].usage)
[47] Fix | Delete
return cb()
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
// npm apihelp <section>: Prefer section 3 over section 1
[51] Fix | Delete
var apihelp = argv.length && argv[0].indexOf('api') !== -1
[52] Fix | Delete
var pref = apihelp ? [3, 1, 5, 7] : [1, 3, 5, 7]
[53] Fix | Delete
if (argnum) {
[54] Fix | Delete
pref = [ argnum ].concat(pref.filter(function (n) {
[55] Fix | Delete
return n !== argnum
[56] Fix | Delete
}))
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
// npm help <section>: Try to find the path
[60] Fix | Delete
var manroot = path.resolve(__dirname, '..', 'man')
[61] Fix | Delete
[62] Fix | Delete
// legacy
[63] Fix | Delete
if (section === 'global') section = 'folders'
[64] Fix | Delete
else if (section.match(/.*json/)) section = section.replace('.json', '-json')
[65] Fix | Delete
[66] Fix | Delete
// find either /section.n or /npm-section.n
[67] Fix | Delete
// The glob is used in the glob. The regexp is used much
[68] Fix | Delete
// further down. Globs and regexps are different
[69] Fix | Delete
var compextglob = '.+(gz|bz2|lzma|[FYzZ]|xz)'
[70] Fix | Delete
var compextre = '\\.(gz|bz2|lzma|[FYzZ]|xz)$'
[71] Fix | Delete
var f = '+(npm-' + section + '|' + section + ').[0-9]?(' + compextglob + ')'
[72] Fix | Delete
return glob(manroot + '/*/' + f, function (er, mans) {
[73] Fix | Delete
if (er) return cb(er)
[74] Fix | Delete
[75] Fix | Delete
if (!mans.length) return npm.commands['help-search'](args, cb)
[76] Fix | Delete
[77] Fix | Delete
mans = mans.map(function (man) {
[78] Fix | Delete
var ext = path.extname(man)
[79] Fix | Delete
if (man.match(new RegExp(compextre))) man = path.basename(man, ext)
[80] Fix | Delete
[81] Fix | Delete
return man
[82] Fix | Delete
})
[83] Fix | Delete
[84] Fix | Delete
viewMan(pickMan(mans, pref), cb)
[85] Fix | Delete
})
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
function pickMan (mans, pref_) {
[89] Fix | Delete
var nre = /([0-9]+)$/
[90] Fix | Delete
var pref = {}
[91] Fix | Delete
pref_.forEach(function (sect, i) {
[92] Fix | Delete
pref[sect] = i
[93] Fix | Delete
})
[94] Fix | Delete
mans = mans.sort(function (a, b) {
[95] Fix | Delete
var an = a.match(nre)[1]
[96] Fix | Delete
var bn = b.match(nre)[1]
[97] Fix | Delete
return an === bn ? (a > b ? -1 : 1)
[98] Fix | Delete
: pref[an] < pref[bn] ? -1
[99] Fix | Delete
: 1
[100] Fix | Delete
})
[101] Fix | Delete
return mans[0]
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
function viewMan (man, cb) {
[105] Fix | Delete
var nre = /([0-9]+)$/
[106] Fix | Delete
var num = man.match(nre)[1]
[107] Fix | Delete
var section = path.basename(man, '.' + num)
[108] Fix | Delete
[109] Fix | Delete
// at this point, we know that the specified man page exists
[110] Fix | Delete
var manpath = path.join(__dirname, '..', 'man')
[111] Fix | Delete
var env = {}
[112] Fix | Delete
Object.keys(process.env).forEach(function (i) {
[113] Fix | Delete
env[i] = process.env[i]
[114] Fix | Delete
})
[115] Fix | Delete
env.MANPATH = manpath
[116] Fix | Delete
var viewer = npm.config.get('viewer')
[117] Fix | Delete
[118] Fix | Delete
var conf
[119] Fix | Delete
switch (viewer) {
[120] Fix | Delete
case 'woman':
[121] Fix | Delete
var a = ['-e', '(woman-find-file \'' + man + '\')']
[122] Fix | Delete
conf = { env: env, stdio: 'inherit' }
[123] Fix | Delete
var woman = spawn('emacsclient', a, conf)
[124] Fix | Delete
woman.on('close', cb)
[125] Fix | Delete
break
[126] Fix | Delete
[127] Fix | Delete
case 'browser':
[128] Fix | Delete
openUrl(htmlMan(man), 'help available at the following URL', cb)
[129] Fix | Delete
break
[130] Fix | Delete
[131] Fix | Delete
default:
[132] Fix | Delete
conf = { env: env, stdio: 'inherit' }
[133] Fix | Delete
var manProcess = spawn('man', [num, section], conf)
[134] Fix | Delete
manProcess.on('close', cb)
[135] Fix | Delete
break
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
function htmlMan (man) {
[140] Fix | Delete
var sect = +man.match(/([0-9]+)$/)[1]
[141] Fix | Delete
var f = path.basename(man).replace(/[.]([0-9]+)$/, '')
[142] Fix | Delete
switch (sect) {
[143] Fix | Delete
case 1:
[144] Fix | Delete
sect = 'cli-commands'
[145] Fix | Delete
break
[146] Fix | Delete
case 5:
[147] Fix | Delete
sect = 'configuring-npm'
[148] Fix | Delete
break
[149] Fix | Delete
case 7:
[150] Fix | Delete
sect = 'using-npm'
[151] Fix | Delete
break
[152] Fix | Delete
default:
[153] Fix | Delete
throw new Error('invalid man section: ' + sect)
[154] Fix | Delete
}
[155] Fix | Delete
return path.resolve(__dirname, '..', 'docs', 'public', sect, f, 'index.html')
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
function npmUsage (valid, cb) {
[159] Fix | Delete
npm.config.set('loglevel', 'silent')
[160] Fix | Delete
log.level = 'silent'
[161] Fix | Delete
output([
[162] Fix | Delete
'\nUsage: npm <command>',
[163] Fix | Delete
'',
[164] Fix | Delete
'where <command> is one of:',
[165] Fix | Delete
npm.config.get('long') ? usages()
[166] Fix | Delete
: ' ' + wrap(commands),
[167] Fix | Delete
'',
[168] Fix | Delete
'npm <command> -h quick help on <command>',
[169] Fix | Delete
'npm -l display full usage info',
[170] Fix | Delete
'npm help <term> search for help on <term>',
[171] Fix | Delete
'npm help npm involved overview',
[172] Fix | Delete
'',
[173] Fix | Delete
'Specify configs in the ini-formatted file:',
[174] Fix | Delete
' ' + npm.config.get('userconfig'),
[175] Fix | Delete
'or on the command line via: npm <command> --key value',
[176] Fix | Delete
'Config info can be viewed via: npm help config',
[177] Fix | Delete
'',
[178] Fix | Delete
'npm@' + npm.version + ' ' + path.dirname(__dirname)
[179] Fix | Delete
].join('\n'))
[180] Fix | Delete
[181] Fix | Delete
if (npm.argv.length > 1) {
[182] Fix | Delete
output(didYouMean(npm.argv[1], commands))
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
cb(valid)
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
function usages () {
[189] Fix | Delete
// return a string of <command>: <usage>
[190] Fix | Delete
var maxLen = 0
[191] Fix | Delete
return Object.keys(npm.commands).filter(function (c) {
[192] Fix | Delete
return c === npm.deref(c)
[193] Fix | Delete
}).reduce(function (set, c) {
[194] Fix | Delete
set.push([c, npm.commands[c].usage || ''])
[195] Fix | Delete
maxLen = Math.max(maxLen, c.length)
[196] Fix | Delete
return set
[197] Fix | Delete
}, []).map(function (item) {
[198] Fix | Delete
var c = item[0]
[199] Fix | Delete
var usage = item[1]
[200] Fix | Delete
return '\n ' +
[201] Fix | Delete
c + (new Array(maxLen - c.length + 2).join(' ')) +
[202] Fix | Delete
(usage.split('\n').join('\n' + (new Array(maxLen + 6).join(' '))))
[203] Fix | Delete
}).join('\n')
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
function wrap (arr) {
[207] Fix | Delete
var out = ['']
[208] Fix | Delete
var l = 0
[209] Fix | Delete
var line
[210] Fix | Delete
[211] Fix | Delete
line = process.stdout.columns
[212] Fix | Delete
if (!line) {
[213] Fix | Delete
line = 60
[214] Fix | Delete
} else {
[215] Fix | Delete
line = Math.min(60, Math.max(line - 16, 24))
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
arr.sort(function (a, b) { return a < b ? -1 : 1 })
[219] Fix | Delete
.forEach(function (c) {
[220] Fix | Delete
if (out[l].length + c.length + 2 < line) {
[221] Fix | Delete
out[l] += ', ' + c
[222] Fix | Delete
} else {
[223] Fix | Delete
out[l++] += ','
[224] Fix | Delete
out[l] = c
[225] Fix | Delete
}
[226] Fix | Delete
})
[227] Fix | Delete
return out.join('\n ').substr(2)
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
function getSections (cb) {
[231] Fix | Delete
var g = path.resolve(__dirname, '../man/man[0-9]/*.[0-9]')
[232] Fix | Delete
glob(g, function (er, files) {
[233] Fix | Delete
if (er) return cb(er)
[234] Fix | Delete
[235] Fix | Delete
cb(null, Object.keys(files.reduce(function (acc, file) {
[236] Fix | Delete
file = path.basename(file).replace(/\.[0-9]+$/, '')
[237] Fix | Delete
file = file.replace(/^npm-/, '')
[238] Fix | Delete
acc[file] = true
[239] Fix | Delete
return acc
[240] Fix | Delete
}, { help: true })))
[241] Fix | Delete
})
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function