Skip to content

Commit

Permalink
better command line parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Kainz committed Aug 8, 2011
1 parent e9d23f8 commit abea35f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
27 changes: 13 additions & 14 deletions bin/jmx4node
@@ -1,29 +1,28 @@
#!/usr/bin/env node

var _usage = "Usage: $0 <url> <command> [params]\n" +
" valid <command>s are\n" +
" list [<mbean>]\n" +
" read <mbean> [<attribute>]" +
" dump [<mbean>]";

var util = require('util');
var jolokia = require("../index");
var _ = require("underscore");
var argv = require('optimist').usage(_usage).argv;

process.on('uncaughtException', function(err) {
console.log("exception while running: " + err.message + "\n" + err.stack + "\n");

usage(true);
process.exit(1);
});

function usage(exit) {
console.log("usage: " + process.argv[1] + " <url> <command> [params]");
console.log(" valid <command>s are");
console.log(" list [<mbean>]");
console.log(" read <mbean> [<attribute>]");
console.log(" dump [<mbean>]");

if (exit) {
process.exit(1);
}
function usage() {
argv.showHelp();
process.exit(1);
}

if (process.argv.length < 4) {
usage(true);
usage();
}

var url = process.argv[2];
Expand All @@ -44,5 +43,5 @@ if (command === 'list') {
console.log(util.inspect(response, true, 10));
});
} else {
usage(true);
usage();
}
6 changes: 4 additions & 2 deletions lib/jolokia-client.js
Expand Up @@ -114,8 +114,10 @@ function collectMBeans(json, alreadyFound, scope) {
function client(target) {
this.url = url.parse(target, false);

if (this.url.protocol != "http:") {
throw target + " is not a supported URL";
var protocol = this.url.protocol;

if (protocol != "http:" && protocol != "https:") {
throw this.url + " is not a supported URL";
}

this.client = http.createClient(80, this.url.hostname);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -16,5 +16,5 @@
"main": "index",
"bin": { "jmx4node": "./bin/jmx4node" },
"engines": { "node": ">= 0.4.1" },
"dependencies" : { "underscore" : ">= 1.1.6"}
"dependencies" : { "underscore" : ">= 1.1.6", " optimist" : ">=0.2.5"}
}

0 comments on commit abea35f

Please sign in to comment.