Skip to content

Commit

Permalink
(new) --help, --json, --notimeout options
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Aug 8, 2010
1 parent 1405ab3 commit cb96a81
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions bin/http-console
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,25 @@ require.paths.unshift(path.join(__dirname, '..', 'lib'));

var httpConsole = require('http-console');

var help = [
'usage: http-console [host:port] [options]\n',
'options:',
' --cookies remember cookies',
'-v, --verbose print requests',
' --json set "Content-Type" header to application/json',
' --notimeout don\'t timeout requests',
' --ssl create a secure connection',
' --version print version',
'-h, --help display this message'
].join('\n');

var argv = process.argv.slice(2), args = [],
arg, option,
options = {
rememberCookies: false,
useSSL: protocol === 'https',
json: false,
timeout: true,
verbose: false
};

Expand All @@ -31,6 +45,16 @@ while (arg = argv.shift()) {
case 'version':
sys.print('http-console v' + httpConsole.version);
process.exit(0);
case 'json':
options.json = true;
break;
case 'notimeout':
options.timeout = false;
break;
case 'h':
case 'help':
sys.print(help);
process.exit(0);
default:
sys.print("http-console: unrecognized option '" + option[0] + "'");
process.exit(1);
Expand All @@ -40,7 +64,7 @@ while (arg = argv.shift()) {
}
}

var hostPort = args.shift() || 'http://127.0.0.1:80',
var hostPort = args.shift() || 'http://127.0.0.1:8080',
protocol = hostPort.match(/^(https?)?/)[0] || 'http';

hostPort = hostPort.replace(protocol + '://', '').split(':');
Expand All @@ -52,4 +76,3 @@ var console = new(httpConsole.Console)(host, port, options);

console.initialize();


0 comments on commit cb96a81

Please sign in to comment.