Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #10 from b1-systems/master

allow arguments to be passed
  • Loading branch information...
commit 18f27ac202c55839a332d02250b0f0a1c89f2d4d 2 parents 98180bc + 4677d5f
Edward Hotchkiss authored
Showing with 40 additions and 35 deletions.
  1. +32 −31 bin/always.js
  2. +3 −2 package.json
  3. +5 −2 test/cli.test.js
View
63 bin/always.js
@@ -18,6 +18,7 @@ var fs = require('fs')
, node = null
, file = null
, app = null
+ , app_args = []
, parser = 'node' // will change depending on file extension
, cleaned
, beep = false
@@ -27,39 +28,38 @@ var fs = require('fs')
* setup CLI
**/
-if (args.length === 2) {
+if (args.length < 3) {
logger('No file specified!'.yellow);
process.exit(0);
} else {
- switch(args[2]) {
- case 'help':
- case '-h':
- case '--help':
- help();
- break;
- case 'version':
- case '-v':
- case '--version':
- displayVersion();
- break;
- case 'start':
- if (args[3] === undefined){
- logger('No file specified!'.yellow);
- process.exit(0);
- } else {
- startDaemon(args[3]);
- }
- break;
- default:
- initializeDevelopment();
- break;
- }
-
- if(args[3] == 'beep'){
- beep = true;
+ var done = false
+ for(i=2; i < args.length; i += 1) {
+ if(args[i] === undefined) {
+ break
+ }
+ if(done) {
+ app_args.push(args[i]);
+ continue
+ }
+ switch(args[i]) {
+ case '-h':
+ case '--help':
+ help();
+ break;
+ case '-v':
+ case '--version':
+ displayVersion();
+ break;
+ case '-b':
+ case '--beep':
+ beep = true;
+ break;
+ default:
+ app = args[i];
+ done = true;
+ }
}
-
-
+ initializeDevelopment();
};
/**
@@ -68,7 +68,7 @@ if (args.length === 2) {
*/
function initializeDevelopment(){
- app = npm(args[2]);
+ app = npm(app);
if (path.extname(app) == '.coffee') {
// The file contains coffee script, use coffee to run it. Does this work on
@@ -97,6 +97,7 @@ function initializeDevelopment(){
'',
'Options:',
' -v, --version current `always` version',
+ ' -b, --beep beep when restarting',
' -h, --help help!',
''
].join('\n'));
@@ -220,7 +221,7 @@ function start(){
if (!exists(app)){
return false;
} else {
- node = spawn(parser, [app]);
+ node = spawn(parser, [app].concat(app_args));
// watch node child process file
initializeFileMonitor(app);
View
5 package.json
@@ -2,7 +2,7 @@
"author":"Edward Hotchkiss <edwardhotchkiss@me.com>",
"name":"always",
"description":"CLI Tool to run a NodeJS Process, Restarting on File Changes & Crashes",
- "version":"2.0.0",
+ "version":"2.1.0",
"repository":{
"type":"git",
"url":"git://github.com/edwardhotchkiss/always.git"
@@ -12,7 +12,8 @@
{ "name": "Edward Hotchkiss","email": "edwardhotchkiss@me.com" },
{ "name": "mugenen","email": "https://twitter.com/#!/Scaled_Wurm" },
{ "name": "MikeMayer", "github": "https://github.com/MikeMayer" },
- { "name": "Wronex", "github": "https://github.com/wronex" }
+ { "name": "Wronex", "github": "https://github.com/wronex" },
+ { "name": "poelzi", "github": "https://github.com/poelzi" }
],
"keywords":["always","process","forever","error","uncaught"],
"engines":{
View
7 test/cli.test.js
@@ -15,8 +15,10 @@ var fs = require('fs')
var testApp =
'var http = require(\'http\');\n'+
+ 'console.log(process.argv.join(" "));\n' +
'var app = http.createServer(function(request, response) {\n'+
- ' response.end(\'hi\');\n'+
+ ' console.log(process.argv);\n'+
+ ' response.end("hi");\n'+
'});\n'+
'app.listen(8000)';
@@ -58,7 +60,7 @@ vows.describe('always vows setup & teardown')
'when running `always start app.js`':{
topic:function() {
var self = this;
- var child = spawn('node', args),
+ var child = spawn('node', args.concat(["--myarg", "blubb"])),
stdout = '',
stderr = '';
exitCode = 0;
@@ -84,6 +86,7 @@ vows.describe('always vows setup & teardown')
},
'stdout should not be an empty value':function(error, exitCode, stdout, stderr){
assert.notEqual(stdout, '');
+ assert.match(stdout, /.*\-\-myarg blubb/);
},
'stderr should be an empty value':function(error, exitCode, stdout, stderr){
assert.equal(stderr, '');
Please sign in to comment.
Something went wrong with that request. Please try again.