Permalink
Browse files

Feature request #13: specify .cson file at command line

  • Loading branch information...
1 parent 7091453 commit 4384c5eacd1f4542bef1ca87b5a8124e495d44ef @brandonramirez brandonramirez committed Oct 28, 2012
Showing with 31 additions and 17 deletions.
  1. +29 −16 bin/buildr.coffee
  2. +2 −1 package.json
View
@@ -2,9 +2,18 @@
# Requires
cson = require 'cson'
-fs = require "fs"
+fs = require 'fs'
+path = require 'path'
buildr = require __dirname+'/../lib/buildr.coffee'
-cwd = process.cwd()
+optimist = require 'optimist'
+
+# Argument parsing
+argv = optimist.options('file', {
+ alias: 'f',
+ default: 'buildr.cson'
+}).argv;
+
+filename = path.resolve argv.file
#Preprocessors
preprocessors = [
@@ -17,18 +26,22 @@ preprocessors = [
new_data
]
data = ''
-fs.readFile "#{cwd}/buildr.cson", (err,d) ->
- throw err if err
- data = d.toString()
-
- console.log "Preprocessing configuration file..."
- for p in preprocessors
- data = p data
- console.log "Preprocessed."
-
- # Parse the config file
- cson.parse data, (err,config) ->
- throw err if err
- myBuildr = buildr.createInstance(config)
- myBuildr.process (err) ->
+fs.exists filename, (exists) ->
+ if exists
+ fs.readFile filename, (err,d) ->
throw err if err
+ data = d.toString()
+
+ console.log "Preprocessing configuration file..."
+ for p in preprocessors
+ data = p data
+ console.log "Preprocessed."
+
+ # Parse the config file
+ cson.parse data, (err,config) ->
+ throw err if err
+ myBuildr = buildr.createInstance(config)
+ myBuildr.process (err) ->
+ throw err if err
+ else
+ console.error "Configuration file not found: #{filename}"
View
@@ -60,7 +60,8 @@
"pulverizr": "0.7.x",
"cson": ">=1.4",
"watch-tree-maintained": "0.1.x",
- "caterpillar": "1.x"
+ "caterpillar": "1.x",
+ "optimist": ">=0.3"
},
"engines" : {
"node": ">=0.4.0"

0 comments on commit 4384c5e

Please sign in to comment.