<commit_before>
module.exports = help

help.completion = function (opts, cb) {
  if (opts.conf.argv.remain.length > 2) return cb(null, [])
  getSections(cb)
}

var path = require("path")
  , spawn = require("./utils/spawn")
  , npm = require("./npm.js")
  , log = require("npmlog")
  , opener = require("opener")
  , glob = require("glob")

function help (args, cb) {
  npm.spinner.stop()
  var argv = npm.config.get("argv").cooked

  var argnum = 0
  if (args.length === 2 && ~~args[0]) {
    argnum = ~~args.shift()
  }

  // npm help foo bar baz: search topics
  if (args.length > 1 && args[0]) {
    return npm.commands["help-search"](args, argnum, cb)
  }

  var section = npm.deref(args[0]) || args[0]

  // npm help <noargs>:  show basic usage
  if (!section) {
    var valid = argv[0] === "help" ? 0 : 1
    return npmUsage(valid, cb)
  }


  // npm <cmd> -h: show command usage
  if ( npm.config.get("usage")
    && npm.commands[section]
    && npm.commands[section].usage
  ) {
    npm.config.set("loglevel", "silent")
    log.level = "silent"
    console.log(npm.commands[section].usage)
    return cb()
  }

  // npm apihelp <section>: Prefer section 3 over section 1
  var apihelp = argv.length && -1 !== argv[0].indexOf("api")
  var pref = apihelp ? [3, 1, 5, 7] : [1, 3, 5, 7]
  if (argnum)
    pref = [ argnum ].concat(pref.filter(function (n) {
      return n !== argnum
    }))

  // npm help <section>: Try to find the path
  var manroot = path.resolve(__dirname, "..", "man")

  // legacy
  if (section === "global") section = "folders"
  else if (section === "json") section = "package.json"

  // find either /section.n or /npm-section.n
  var compext = "\\.+(gz|bz2|lzma|[FYzZ]|xz)$"
  var f = "+(npm-" + section + "|" + section + ").[0-9]?(" + compext + ")"
  return glob(manroot + "/*/" + f, function (er, mans) {
    if (er) return cb(er)

    if (!mans.length) return npm.commands["help-search"](args, cb)

    mans = mans.map(function (man) {
      var ext = path.extname(man)
      if (man.match(new RegExp(compext))) man = path.basename(man, ext)

      return man
    })

    viewMan(pickMan(mans, pref), cb)
  })
}

function pickMan (mans, pref_) {<commit_msg>help: Don't confuse glob with regexp<commit_after>
module.exports = help

help.completion = function (opts, cb) {
  if (opts.conf.argv.remain.length > 2) return cb(null, [])
  getSections(cb)
}

var path = require("path")
  , spawn = require("./utils/spawn")
  , npm = require("./npm.js")
  , log = require("npmlog")
  , opener = require("opener")
  , glob = require("glob")

function help (args, cb) {
  npm.spinner.stop()
  var argv = npm.config.get("argv").cooked

  var argnum = 0
  if (args.length === 2 && ~~args[0]) {
    argnum = ~~args.shift()
  }

  // npm help foo bar baz: search topics
  if (args.length > 1 && args[0]) {
    return npm.commands["help-search"](args, argnum, cb)
  }

  var section = npm.deref(args[0]) || args[0]

  // npm help <noargs>:  show basic usage
  if (!section) {
    var valid = argv[0] === "help" ? 0 : 1
    return npmUsage(valid, cb)
  }


  // npm <cmd> -h: show command usage
  if ( npm.config.get("usage")
    && npm.commands[section]
    && npm.commands[section].usage
  ) {
    npm.config.set("loglevel", "silent")
    log.level = "silent"
    console.log(npm.commands[section].usage)
    return cb()
  }

  // npm apihelp <section>: Prefer section 3 over section 1
  var apihelp = argv.length && -1 !== argv[0].indexOf("api")
  var pref = apihelp ? [3, 1, 5, 7] : [1, 3, 5, 7]
  if (argnum)
    pref = [ argnum ].concat(pref.filter(function (n) {
      return n !== argnum
    }))

  // npm help <section>: Try to find the path
  var manroot = path.resolve(__dirname, "..", "man")

  // legacy
  if (section === "global") section = "folders"
  else if (section === "json") section = "package.json"

  // find either /section.n or /npm-section.n
  // The glob is used in the glob.  The regexp is used much
  // further down.  Globs and regexps are different
  var compextglob = ".+(gz|bz2|lzma|[FYzZ]|xz)"
  var compextre = "\\.(gz|bz2|lzma|[FYzZ]|xz)$"
  var f = "+(npm-" + section + "|" + section + ").[0-9]?(" + compextglob + ")"
  return glob(manroot + "/*/" + f, function (er, mans) {
    if (er) return cb(er)

    if (!mans.length) return npm.commands["help-search"](args, cb)

    mans = mans.map(function (man) {
      var ext = path.extname(man)
      if (man.match(new RegExp(compextre))) man = path.basename(man, ext)

      return man
    })

    viewMan(pickMan(mans, pref), cb)
  })
}

function pickMan (mans, pref_) {
{'fraction_non_alphanumeric': 0.18670747704416266, 'fraction_numerical': 0.011587232181897682, 'mean_word_length': 2.9439655172413794, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7604559', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1669, 'n_words': 437}