From 9ae54b7f285dd64dd57d6293d3bc36f814e0fff1 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sat, 9 Aug 2014 06:19:44 -0400 Subject: [PATCH] feature(console) add optional glob for wildcard parsing --- lib/server/console.js | 11 ++++++++++- lib/server/find.js | 9 +++------ package.json | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/server/console.js b/lib/server/console.js index 309103a7..0a89ec52 100644 --- a/lib/server/console.js +++ b/lib/server/console.js @@ -39,6 +39,10 @@ stdout : CLOUDCMD + ' exit \n' + CLOUDCMD + ' update \n', }; + + Util.exec.try(function() { + find = require('glob'); + }); /** * function listen on servers port @@ -338,7 +342,12 @@ if (!isWildCard) exec(command, {cwd: paramDir}, onExec); else - find(paramDir, function(error, dir) { + find(paramDir, function(error, dirs) { + var dir; + + if (!error) + dir = dirs[0]; + paramDir = dir; exec(command, {cwd: dir}, onExec); }); diff --git a/lib/server/find.js b/lib/server/find.js index cb0de5c7..7320bc51 100644 --- a/lib/server/find.js +++ b/lib/server/find.js @@ -14,21 +14,18 @@ throw(Error('Callback is absent!')); fs.readdir(dir, function(error, names) { - var result; + var result = []; if (!error) - names.some(function(name) { + names.forEach(function(name) { var is = name.match(regExp); if (is) - result = name; + result.push(path.join(dir, name)); return is; }); - if (result) - result = path.join(dir, result); - callback(error, result); }); }; diff --git a/package.json b/package.json index daaf8075..06ae7fc6 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "dependencies": { "dropbox": "0.10.x", "express": "~4.6.1", + "glob": "~4.0.5", "http-auth": "2.1.x", "marked": "~0.3.2", "minify": "~0.7.x",