Permalink
Browse files

add component-ls(1) --depth support

  • Loading branch information...
tj committed Dec 20, 2012
1 parent e6552c5 commit 2208f00b960f6ba977f8eee640d8f90b3d75c067
Showing with 9 additions and 3 deletions.
  1. +9 −3 bin/component-ls
View
@@ -13,7 +13,9 @@ var program = require('commander')
// parse argv
-program.parse(process.argv);
+program
+ .option('-d, --depth <n>', 'set the depth to <n>', Infinity)
+ .parse(process.argv);
// output tree
@@ -29,7 +31,8 @@ console.log(indent(archy(tree)));
* @return {Object}
*/
-function tree(file, paths){
+function tree(file, paths, depth){
+ depth = depth || 0;
var conf = require(resolve(file));
var deps = Object.keys(conf.dependencies || {});
var node = {};
@@ -44,13 +47,16 @@ function tree(file, paths){
node.label = '\033[36m' + conf.name + '\033[m';
node.label += ' \033[90m' + (conf.version || '') + '\033[m';
+ // --depth n
+ if (++depth > program.depth) return node;
+
// dependencies
node.nodes = deps.map(function(dep){
var dep = dep.replace('/', '-');
var file = lookup(dep, paths);
if (!file) throw new Error('failed to resolve location of "' + dep + '"');
file = resolve(file, 'component.json');
- return tree(file, paths);
+ return tree(file, paths, depth);
});
return node;

0 comments on commit 2208f00

Please sign in to comment.