Permalink
Browse files

add --version cmdline parameter

  • Loading branch information...
1 parent cc9aa60 commit 6caa37673b4df0ea6e18e00da4b994d22bc3141e @andrewrk committed Jul 13, 2012
Showing with 10 additions and 1 deletion.
  1. +10 −1 src/cmd.co
View
@@ -4,7 +4,8 @@ const path = require('path')
const optparse = require('optparse')
const switches =
- * '-h' '--help' "shows this help section"
+ * '-h' '--help' "shows this help section and exit"
+ * '-v' '--version' "print the version number and exit"
* '-b' '--bare' "compile without a top-level function wrapper"
* '-w' '--watch' "watch source files and recompile when any change"
* '-l' '--lib PATH' "add an additional search directory for source files"
@@ -19,6 +20,14 @@ parser.on \help, !->
printUsage!
process.exit(1)
+parser.on \version, !->
+ lib_dir = path.dirname(fs.realpathSync(__filename))
+ pkg_path = path.resolve(lib_dir, "..", "package.json")
+ data = fs.readFileSync(pkg_path, 'utf8')
+ pkg = JSON.parse(data)
+ console.log(pkg.version)
+ process.exit(1)
+
mainfile = null
parser.on 0, !-> mainfile := it

0 comments on commit 6caa376

Please sign in to comment.