Permalink
Browse files

Use `minimist` to parse arguments.

  • Loading branch information...
mrluanma committed Dec 25, 2014
1 parent cdda585 commit afcd1a2ce4649e3f9b246a9b734d1bd9b1b361d4
Showing with 115 additions and 97 deletions.
  1. +27 −0 .gitignore
  2. +0 −40 args.js
  3. +24 −7 local.js
  4. +3 −1 package.json
  5. +22 −8 server.js
  6. +0 −28 src/args.coffee
  7. +21 −6 src/local.coffee
  8. +18 −7 src/server.coffee
View
@@ -0,0 +1,27 @@
# Logs
logs
*.log
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules
View
40 args.js

This file was deleted.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,7 +1,9 @@
{
"name": "shadowsocks-heroku",
"version": "0.9.7",
"dependencies": {},
"dependencies": {
"minimist": "^1.1.0"
},
"engines": {
"node": "0.10.x"
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View
@@ -22,23 +22,38 @@ net = require("net")
http = require("http")
fs = require("fs")
path = require("path")
args = require('./args')
parseArgs = require("minimist")
Encryptor = require("./encrypt").Encryptor
console.log args.version
options =
alias:
'b': 'local_address'
'l': 'local_port'
's': 'server'
'r': 'remote_port'
'k': 'password',
'c': 'config_file',
'm': 'method'
string: ['local_address', 'server', 'password',
'config_file', 'method']
default:
'local_address': '127.0.0.1'
'local_port': 1080
'remote_port': 80
'config_file': path.resolve(__dirname, "config.json")
inetNtoa = (buf) ->
buf[0] + "." + buf[1] + "." + buf[2] + "." + buf[3]
configFromArgs = args.parseArgs()
configContent = fs.readFileSync(configFromArgs.config_file || path.resolve(__dirname, "config.json"))
configFromArgs = parseArgs process.argv.slice(2), options
configContent = fs.readFileSync(configFromArgs.config_file)
config = JSON.parse(configContent)
for k, v of configFromArgs
config[k] = v
SERVER = config.server
REMOTE_PORT = config.remote_port || 80
LOCAL_ADDRESS = config.local_address || '127.0.0.1'
REMOTE_PORT = config.remote_port
LOCAL_ADDRESS = config.local_address
PORT = config.local_port
KEY = config.password
METHOD = config.method
View
@@ -22,24 +22,35 @@ net = require("net")
fs = require("fs")
path = require("path")
http = require("http")
args = require("./args")
parseArgs = require("minimist")
Encryptor = require("./encrypt").Encryptor
console.log args.version
options =
alias:
'r': 'remote_port'
'k': 'password',
'c': 'config_file',
'm': 'method'
string: ['password', 'method', 'config_file']
default:
'remote_port': process.env.PORT || 8080
'password': process.env.KEY
'method': process.env.METHOD
'config_file': path.resolve(__dirname, "config.json")
inetNtoa = (buf) ->
buf[0] + "." + buf[1] + "." + buf[2] + "." + buf[3]
configFromArgs = args.parseArgs()
configFile = configFromArgs.config_file or path.resolve(__dirname, "config.json")
configFromArgs = parseArgs process.argv.slice(2), options
configFile = configFromArgs.config_file
configContent = fs.readFileSync(configFile)
config = JSON.parse(configContent)
for k, v of configFromArgs
config[k] = v
timeout = Math.floor(config.timeout * 1000)
PORT = process.env.PORT || 8080
KEY = process.env.KEY || config.password
METHOD = process.env.METHOD || config.method
PORT = config.remote_port
KEY = config.password
METHOD = config.method
server = http.createServer (req, res) ->
res.writeHead 200, 'Content-Type':'text/plain'

0 comments on commit afcd1a2

Please sign in to comment.