/**
 * argv.js
 * client arguments & defaults
 */

var
	fs = require('fs')
	, path = require('path')
	, banner = fs.readFileSync(
		path.resolve(
			__dirname
			, 'banner'
		)
	)
	, defaults
	, argv
;

if (process.env.NODE_ENV === "development") {

	defaults = {

		cloudHost : "127.0.0.1"
		, streamHost : "127.0.0.1"
		, apiHost : "127.0.0.1"
		, logFile : path.resolve(process.env.PWD, 'ninjablock.log')
		, updateLock : path.resolve(process.env.PWD, '.has_updated')
		, serialFile : path.resolve(process.env.PWD, 'serial-development.conf')
		, tokenFile : path.resolve(process.env.PWD, 'token-development.conf')
		, env : 'development'
		, streamPort : 3003
		, cloudPort : 3001
		, apiPort : 3000
		, secure : false
		, debug : true
		, client : process.env.NINJA_CLIENT_NAME
	}
}
else if (process.env.NODE_ENV === "hacking") {

	defaults = {
		cloudHost : "zendo.ninja.is"
		, apiHost : "api.ninja.is"
		, streamHost : "stream.ninja.is"
		, logFile : path.resolve(process.env.PWD, 'ninjablock.log')
		, updateLock : path.resolve(process.env.PWD, '.has_updated')	
		, serialFile : path.resolve(process.env.PWD, 'serial-hacking.conf')
		, tokenFile : path.resolve(process.env.PWD, 'token-hacking.conf')
		, env : 'hacking'
		, streamPort : 443
		, cloudPort : 443
		, apiPort : 443
		, secure : true
		, debug : true
		, client : process.env.NINJA_CLIENT_NAME
	}
}
else if (process.env.NODE_ENV === "beta") {

	defaults = {
		cloudHost : "wakai-zendo.ninja.is"
		, apiHost : "wakai.ninja.is"
		, streamHost : "wakai-stream.ninja.is"
		, logFile : path.resolve(process.env.PWD, 'ninjablock.log')
		, updateLock : path.resolve(process.env.PWD, '.has_updated')	
		, serialFile : path.resolve(process.env.PWD, 'serial-beta.conf')
		, tokenFile : path.resolve(process.env.PWD, 'token-beta.conf')
		, env : 'beta'
		, streamPort : 443
		, cloudPort : 443
		, apiPort : 443
		, secure : true
		, debug : true
		, client : process.env.NINJA_CLIENT_NAME
	}
}
else {

	defaults = {

		cloudHost : "zendo.ninja.is"
		, streamHost : "stream.ninja.is"
		, apiHost : "api.ninja.is"
		, logFile : '/var/log/ninjablock.log'
		, updateLock : '/etc/opt/ninja/.has_updated'
		, serialFile : '/etc/opt/ninja/serial.conf'
		, tokenFile : '/etc/opt/ninja/token.conf'
		, env : 'production'
		, streamPort : 443
		, cloudPort : 443
		, apiPort : 443
		, secure : true
		, debug : false
		, client : process.env.NINJA_CLIENT_NAME
	}
	if(!process.env.NODE_ENV) { process.env.NODE_ENV = "production"; }
}

argv = require('optimist')

	.usage(

		[	banner
			, "This process requires certain parameters to run."
			, "Please see usage information below."
			, ""
			, "Example: $0 --devicePath /dev/tty.usb*B"
		].join("\n")
	)
	.default(defaults)
	.boolean('secure')
	.boolean('debug')
	.argv
;

module.exports = argv;

@@ -193,16 +193,37 @@
 %09, argv%0A
+  , join = path.join%0A
 ;%0A%0Aif (p
@@ -378,36 +378,28 @@
 e : 
-path.resolve(process.env.PWD
+join(__dirname, '..'
 , 'n
@@ -435,36 +435,28 @@
 k : 
-path.resolve(process.env.PWD
+join(__dirname, '..'
 , '.
@@ -490,36 +490,28 @@
 e : 
-path.resolve(process.env.PWD
+join(__dirname, '..'
 , 's
@@ -555,36 +555,28 @@
 e : 
-path.resolve(process.env.PWD
+join(__dirname, '..'
 , 't
@@ -944,36 +944,28 @@
 e : 
-path.resolve(process.env.PWD
+join(__dirname, '..'
 , 'n
@@ -1001,36 +1001,28 @@
 k : 
-path.resolve(process.env.PWD
+join(__dirname, '..'
 , '.
@@ -1057,36 +1057,28 @@
 e : 
-path.resolve(process.env.PWD
+join(__dirname, '..'
 , 's
@@ -1118,36 +1118,28 @@
 e : 
-path.resolve(process.env.PWD
+join(__dirname, '..'
 , 't
@@ -1506,36 +1506,28 @@
 e : 
-path.resolve(process.env.PWD
+join(__dirname, '..'
 , 'n
@@ -1563,36 +1563,28 @@
 k : 
-path.resolve(process.env.PWD
+join(__dirname, '..'
 , '.
@@ -1619,36 +1619,28 @@
 e : 
-path.resolve(process.env.PWD
+join(__dirname, '..'
 , 's
@@ -1677,36 +1677,28 @@
 e : 
-path.resolve(process.env.PWD
+join(__dirname, '..'
 , 't

Replace process.env.PWD with __dirname+'../'