diff options
author | isaacs <i@izs.me> | 2011-03-16 10:00:38 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-03-22 01:56:13 +0300 |
commit | 660caf659ef86e84a3d2ebdb8711958000380b0a (patch) | |
tree | 44128730765beac0d65fadaf6da270d9f184cc39 /lib | |
parent | e9472403fa29ecffc1b42b1e99b239ddc31f7348 (diff) |
use abstracted completion functions
Diffstat (limited to 'lib')
-rw-r--r-- | lib/edit.js | 32 | ||||
-rw-r--r-- | lib/explore.js | 7 | ||||
-rw-r--r-- | lib/outdated.js | 37 | ||||
-rw-r--r-- | lib/prune.js | 2 | ||||
-rw-r--r-- | lib/rebuild.js | 5 |
5 files changed, 7 insertions, 76 deletions
diff --git a/lib/edit.js b/lib/edit.js index b30ee6eaa..82a883a06 100644 --- a/lib/edit.js +++ b/lib/edit.js @@ -4,37 +4,7 @@ module.exports = edit edit.usage = "npm edit <pkg>" -edit.completion = function (opts, cb) { - var conf = opts.conf - , args = conf.argv.remain - if (args.length > 3) return cb() - var local - , global - , localDir = npm.dir - , globalDir = path.join(npm.config.get("prefix"), "node_modules") - if (npm.config.get("global")) local = [], next() - else fs.readdir(localDir, function (er, pkgs) { - local = (pkgs || []).filter(function (p) { - return p.charAt(0) !== "." - }) - next() - }) - fs.readdir(globalDir, function (er, pkgs) { - global = (pkgs || []).filter(function (p) { - return p.charAt(0) !== "." - }) - next() - }) - function next () { - if (!local || !global) return - if (!npm.config.get("global")) { - global = global.map(function (g) { - return [g, "-g"] - }) - } - return cb(null, local.concat(global)) - } -} +edit.completion = require("./utils/completion/installed-shallow") var npm = require("../npm") , exec = require("./utils/exec") diff --git a/lib/explore.js b/lib/explore.js index 1938154d2..e05f120cd 100644 --- a/lib/explore.js +++ b/lib/explore.js @@ -2,11 +2,8 @@ // open a subshell to the package folder. module.exports = explore -explore.usage = "npm explore <pkg>[@<version>] [<cmd>]" -explore.completion = function (args, index, cb) { - var installedPkgs = require("./utils/completion/installed-packages") - installedPkgs(args, index, true, false, cb) -} +explore.usage = "npm explore <pkg> [<cmd>]" +explore.completion = require("./utils/completion/installed-shallow") var npm = require("../npm") , exec = require("./utils/exec") diff --git a/lib/outdated.js b/lib/outdated.js index d3b3b604b..6e23ddd01 100644 --- a/lib/outdated.js +++ b/lib/outdated.js @@ -15,43 +15,8 @@ module.exports = outdated outdated.usage = "npm outdated [<pkg> [<pkg> ...]]" -outdated.completion = function (opts, cb) { - var local - , global - , readInstalled = require("./utils/read-installed") - readInstalled(npm.prefix, function (er, data) { - local = data || {} - next() - }) - readInstalled(npm.config.get("prefix"), function (er, data) { - global = data || {} - next() - }) - - function getNames_ (d, n) { - if (d.realName && n) { - if (n[d.realName]) return n - n[d.realName] = true - } - if (!n) n = {} - Object.keys(d.dependencies || {}).forEach(function (dep) { - getNames_(d.dependencies[dep], n) - }) - return n - } - function getNames (d) { - return Object.keys(getNames_(d)) - } - - function next () { - if (!local || !global) return - var names = getNames(local).concat(getNames(global).map(function (g) { - return [g, "-g"] - })) - return cb(null, names) - } +outdated.completion = require("./utils/completion/installed-deep") -} var readInstalled = require("./utils/read-installed") , path = require("path") diff --git a/lib/prune.js b/lib/prune.js index a39a7a4f8..b830d2e21 100644 --- a/lib/prune.js +++ b/lib/prune.js @@ -7,6 +7,8 @@ prune.usage = "npm prune" var readInstalled = require("./utils/read-installed") , npm = require("../npm") +prune.completion = require("./utils/completion/installed-deep") + function prune (args, cb) { readInstalled(npm.prefix, function (er, data) { if (er) return cb(er) diff --git a/lib/rebuild.js b/lib/rebuild.js index f5f234aa1..a43e6c253 100644 --- a/lib/rebuild.js +++ b/lib/rebuild.js @@ -10,10 +10,7 @@ var readInstalled = require("./utils/read-installed") rebuild.usage = "npm rebuild [<name>[@<version>] [name[@<version>] ...]]" -rebuild.completion = function (args, index, cb) { - var installedPkgs = require("./utils/completion/installed-packages") - installedPkgs(args, index, true, true, cb) -} +rebuild.completion = require("./utils/completion/installed-deep") function rebuild (args, cb) { readInstalled(npm.prefix, function (er, data) { |