Skip to content

Commit

Permalink
#18 cli returns error code on err
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunong Xiao committed Sep 4, 2013
1 parent 1cc7b77 commit aa3d0d5
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 47 deletions.
121 changes: 77 additions & 44 deletions bin/fash.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ Fash.prototype.do_create = function(subcmd, opts, args, callback) {
var self = this;

if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

if (args.length !== 0 || !opts.v || !opts.p) {
this.do_help('help', {}, [subcmd], callback);
return (callback(false));
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

var pnodes = opts.p.split(' ');
Expand All @@ -76,13 +78,13 @@ Fash.prototype.do_create = function(subcmd, opts, args, callback) {
}, function(err, chash) {
if (err) {
console.error(err);
return callback(false);
return callback(err);
}

chash.serialize(function(_err, sh) {
if (_err) {
console.error(_err);
return callback(false);
return callback(_err);
}
if (opts.o) {
console.log(sh);
Expand Down Expand Up @@ -132,13 +134,15 @@ Fash.prototype.do_create.help = (
Fash.prototype.do_deserialize_ring = function(subcmd, opts, args, callback) {
var self = this;
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

if (args.length !== 0 || !opts.l) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

var hashOptions = {
Expand Down Expand Up @@ -174,6 +178,7 @@ Fash.prototype.do_deserialize_ring = function(subcmd, opts, args, callback) {
if (err) {
console.error(err);
}
return callback(err);
});
return (undefined);
};
Expand All @@ -199,13 +204,15 @@ Fash.prototype.do_deserialize_ring.help = (
Fash.prototype.do_add_data = function(subcmd, opts, args, callback) {
var self = this;
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

if (args.length !== 0 || !opts.v || !opts.d) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

var hashOptions = {
Expand Down Expand Up @@ -239,8 +246,9 @@ Fash.prototype.do_add_data = function(subcmd, opts, args, callback) {
hashOptions.backend = fash.BACKEND.LEVEL_DB;
constructor = fash.load;
if (!opts.l) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
} else {
hashOptions.location = opts.l;
return cb();
Expand Down Expand Up @@ -289,6 +297,7 @@ Fash.prototype.do_add_data = function(subcmd, opts, args, callback) {
if (err) {
console.error(err);
}
return callback(err);
});
return (undefined);
};
Expand Down Expand Up @@ -327,13 +336,15 @@ Fash.prototype.do_add_data.help = (
Fash.prototype.do_remap_vnode = function(subcmd, opts, args, callback) {
var self = this;
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

if (args.length !== 0 || !opts.v || !opts.p) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

var hashOptions = {
Expand Down Expand Up @@ -367,8 +378,9 @@ Fash.prototype.do_remap_vnode = function(subcmd, opts, args, callback) {
hashOptions.backend = fash.BACKEND.LEVEL_DB;
constructor = fash.load;
if (!opts.l) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
} else {
hashOptions.location = opts.l;
return cb();
Expand Down Expand Up @@ -416,6 +428,7 @@ Fash.prototype.do_remap_vnode = function(subcmd, opts, args, callback) {
if (err) {
console.error(err);
}
return callback(err);
});
return (undefined);
};
Expand Down Expand Up @@ -454,13 +467,15 @@ Fash.prototype.do_remap_vnode.help = (
Fash.prototype.do_remove_pnode = function(subcmd, opts, args, callback) {
var self = this;
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

if (args.length !== 0 || !opts.p) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

var hashOptions = {
Expand Down Expand Up @@ -494,8 +509,9 @@ Fash.prototype.do_remove_pnode = function(subcmd, opts, args, callback) {
hashOptions.backend = fash.BACKEND.LEVEL_DB;
constructor = fash.load;
if (!opts.l) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
} else {
hashOptions.location = opts.l;
return cb();
Expand Down Expand Up @@ -529,6 +545,7 @@ Fash.prototype.do_remove_pnode = function(subcmd, opts, args, callback) {
if (err) {
console.error(err);
}
return callback(err);
});

return (undefined);
Expand Down Expand Up @@ -564,13 +581,15 @@ Fash.prototype.do_remove_pnode.help = (
Fash.prototype.do_get_node = function(subcmd, opts, args, callback) {
var self = this;
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

if (args.length !== 1) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

var hashOptions = {
Expand Down Expand Up @@ -604,8 +623,9 @@ Fash.prototype.do_get_node = function(subcmd, opts, args, callback) {
hashOptions.backend = fash.BACKEND.LEVEL_DB;
constructor = fash.load;
if (!opts.l) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
} else {
hashOptions.location = opts.l;
return cb();
Expand Down Expand Up @@ -633,6 +653,7 @@ Fash.prototype.do_get_node = function(subcmd, opts, args, callback) {
if (err) {
console.error(err);
}
return callback(err);
});

return (undefined);
Expand Down Expand Up @@ -660,8 +681,9 @@ Fash.prototype.do_get_node.help = (
Fash.prototype.do_print_hash = function(subcmd, opts, args, callback) {
var self = this;
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

var hashOptions = {
Expand Down Expand Up @@ -695,8 +717,9 @@ Fash.prototype.do_print_hash = function(subcmd, opts, args, callback) {
hashOptions.backend = fash.BACKEND.LEVEL_DB;
constructor = fash.load;
if (!opts.l) {
this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
} else {
hashOptions.location = opts.l;
return cb();
Expand Down Expand Up @@ -725,6 +748,7 @@ Fash.prototype.do_print_hash = function(subcmd, opts, args, callback) {
if (err) {
console.error(err);
}
return callback(err);
});

return (undefined);
Expand Down Expand Up @@ -755,8 +779,9 @@ Fash.prototype.do_diff = function (subcmd, opts, args, callback) {
if (opts.help || args.length !== 2 ||
(args[0] === '-' && args[1] === '-')) {

this.do_help('help', {}, [subcmd], callback);
return (callback());
this.do_help('help', {}, [subcmd], function(err) {
return callback(err ? err : true);
});
}

function chooseBackend(b) {
Expand All @@ -767,7 +792,7 @@ Fash.prototype.do_diff = function (subcmd, opts, args, callback) {
} else {
console.error('one of %j must be specified if not passing ' +
'topology via stdin', BACKENDS);
return (callback());
return (callback(true));
}
}

Expand All @@ -779,7 +804,7 @@ Fash.prototype.do_diff = function (subcmd, opts, args, callback) {
} else {
console.error('one of %j must be specified if not passing ' +
'topology via stdin', BACKENDS);
return (callback());
return (callback(true));
}
}

Expand Down Expand Up @@ -808,7 +833,7 @@ Fash.prototype.do_diff = function (subcmd, opts, args, callback) {
} else {
console.error('one of %j must be specified if not passing ' +
'topology via stdin', BACKENDS);
return (callback());
return (callback(true));
}
}

Expand Down Expand Up @@ -960,6 +985,7 @@ Fash.prototype.do_diff = function (subcmd, opts, args, callback) {
]}, function (err) {
if (err) {
console.error(err);
return callback(err);
}
});
return (undefined);
Expand All @@ -984,4 +1010,11 @@ Fash.prototype.do_diff.help = (
+ ' fash diff -b leveldb -b memory leveldbdir ring.json'
);

cmdln.main(Fash); // mainline
var cli = new Fash();
cli.main(process.argv, function(err, subcmd) {
if (err) {
process.exit(1);
} else {
process.exit(0);
}
});
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports = {
IN_MEMORY: './backend/in_memory',
LEVEL_DB: './backend/leveldb'
},
VERSION: '2.0.2',
VERSION: '2.1.0',
assertVersion: assertVersion
};

Expand Down
4 changes: 2 additions & 2 deletions tools/jsl.node.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Configuration File for JavaScript Lint
# Configuration File for JavaScript Lint
#
# This configuration file can be used to lint a collection of scripts, or to enable
# or disable warnings for scripts that are linted via the command line.
Expand All @@ -12,7 +12,7 @@
+ambiguous_else_stmt # the else statement could be matched with one of multiple if statements (use curly braces to indicate intent
+ambiguous_nested_stmt # block statements containing block statements should use curly braces to resolve ambiguity
+ambiguous_newline # unexpected end of line; it is ambiguous whether these lines are part of the same statement
+anon_no_return_value # anonymous function does not always return value
-anon_no_return_value # anonymous function does not always return value
+assign_to_function_call # assignment to a function call
-block_without_braces # block statement without curly braces
+comma_separated_stmts # multiple statements separated by commas (use semicolons?)
Expand Down

0 comments on commit aa3d0d5

Please sign in to comment.