You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bh...@apache.org on 2013/05/30 19:19:34 UTC
webworks commit: [CB-3381] Output usage info on error for all scripts
Updated Branches:
refs/heads/master 8b3a57a63 -> 8968d01da
[CB-3381] Output usage info on error for all scripts
Reviewed by Bryan Higgins <bh...@blackberry.com>
Tested by Tracy Li <tl...@blackberry.com>
Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/8968d01d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/8968d01d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/8968d01d
Branch: refs/heads/master
Commit: 8968d01daf313d96e379e98c1e91484c00afaeb6
Parents: 8b3a57a
Author: DanielAudino <da...@blackberry.com>
Authored: Mon May 27 09:54:32 2013 -0400
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Thu May 30 13:22:10 2013 -0400
----------------------------------------------------------------------
blackberry10/bin/create.js | 34 +++++++++---
.../bin/templates/project/cordova/lib/build | 5 ++-
.../bin/templates/project/cordova/lib/plugin.js | 2 +
blackberry10/bin/templates/project/cordova/lib/run | 3 +
.../bin/templates/project/cordova/lib/target | 40 +++++++++++----
5 files changed, 65 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/8968d01d/blackberry10/bin/create.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/create.js b/blackberry10/bin/create.js
index 5ef05ec..78c8e95 100644
--- a/blackberry10/bin/create.js
+++ b/blackberry10/bin/create.js
@@ -30,7 +30,7 @@ var build,
wrench = require("wrench"),
utils = require(path.join(__dirname, 'lib/utils')),
version = getVersion(),
- project_path = path.resolve(process.argv[2]),
+ project_path = validateProjectPath(),
app_id = process.argv[3],
bar_name = process.argv[4],
TARGETS = ["device", "simulator"],
@@ -67,18 +67,32 @@ function validBarName(barName) {
return (typeof barName === "undefined") || barNameRegex.test(barName);
}
-function validate() {
- if (!project_path) {
- throw "You must give a project PATH";
+function validateProjectPath() {
+ if (!process.argv[2]) {
+ console.log("You must give a project PATH");
+ help();
+ process.exit(2);
+ return "";
+ } else {
+ return path.resolve(process.argv[2]);
}
+}
+
+function validate() {
if (fs.existsSync(project_path)) {
- throw "The project path must be an empty directory";
+ console.log("The project path must be an empty directory");
+ help();
+ process.exit(2);
}
if (!validPackageName(app_id)) {
- throw "App ID must be sequence of alpha-numeric (optionally seperated by '.') characters, no longer than 50 characters";
+ console.log("App ID must be sequence of alpha-numeric (optionally seperated by '.') characters, no longer than 50 characters");
+ help();
+ process.exit(2);
}
if (!validBarName(bar_name)) {
- throw "BAR filename can only contain alpha-numeric, '.', '-' and '_' characters";
+ console.log("BAR filename can only contain alpha-numeric, '.', '-' and '_' characters");
+ help();
+ process.exit(2);
}
}
@@ -154,10 +168,14 @@ function installPlugins() {
require(pluginScript).add(path.join(__dirname, "..", "plugins"));
}
-if ( process.argv[2] === "-h" || process.argv[2] === "--help" ) {
+function help() {
console.log("\nUsage: create <project path> [package name [BAR filename]] \n");
console.log("Options: \n");
console.log(" -h, --help output usage information \n");
+}
+
+if ( process.argv[2] === "-h" || process.argv[2] === "--help" ) {
+ help();
} else {
try {
validate();
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/8968d01d/blackberry10/bin/templates/project/cordova/lib/build
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/build b/blackberry10/bin/templates/project/cordova/lib/build
index d2a8ea6..561b016 100755
--- a/blackberry10/bin/templates/project/cordova/lib/build
+++ b/blackberry10/bin/templates/project/cordova/lib/build
@@ -55,6 +55,7 @@ function doReleaseBuild() {
bbwpArgv.push( projectProperties.keystorepass);
} else {
console.log("No signing password provided. Please use --keystorepass via command-line or enter a value for keystorepass in project.json");
+ console.log(command.helpInformation());
process.exit(2);
}
@@ -116,7 +117,9 @@ try {
command.parse(process.argv);
if (command.debug && command.release) {
- throw "Invalid build command: cannot specify both debug and release parameters."
+ console.log("Invalid build command: cannot specify both debug and release parameters.");
+ console.log(command.helpInformation());
+ process.exit(2);
}
// Implicitly call clean first
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/8968d01d/blackberry10/bin/templates/project/cordova/lib/plugin.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/plugin.js b/blackberry10/bin/templates/project/cordova/lib/plugin.js
index 1f11481..cac797d 100644
--- a/blackberry10/bin/templates/project/cordova/lib/plugin.js
+++ b/blackberry10/bin/templates/project/cordova/lib/plugin.js
@@ -104,6 +104,7 @@ function addPlugin (pluginPath) {
plugin = path.resolve(GLOBAL_PLUGIN_PATH, plugin);
if (!fs.existsSync(plugin)) {
console.log("Input ", pluginPath || argumentor.plugin, " cannot be resolved as a plugin");
+ listHelp();
process.exit(1);
}
}
@@ -119,6 +120,7 @@ function addPlugin (pluginPath) {
if (!pluginDirs.length) {
console.log("No plugins could be found given the input " + pluginPath || argumentor.plugin);
+ listHelp();
process.exit(1);
} else {
pluginDirs.forEach(function (pluginDir) {
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/8968d01d/blackberry10/bin/templates/project/cordova/lib/run
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/run b/blackberry10/bin/templates/project/cordova/lib/run
index 295a469..98ec9ea 100755
--- a/blackberry10/bin/templates/project/cordova/lib/run
+++ b/blackberry10/bin/templates/project/cordova/lib/run
@@ -104,16 +104,19 @@ function execNativeDeploy(optionsArray, callback) {
function checkTarget() {
if (!target) {
console.log("No target exists, to add that target please run target add <name> <ip> [-t | --type <device | simulator>] [-p <password>] [--pin <devicepin>]");
+ console.log(program.helpInformation());
return false;
}
if (!properties.targets[target]) {
console.log("The target \""+target+"\" does not exist, to add that target please run target add "+target+" <ip> [-t | --type <device | simulator>] [-p <password>] [--pin <devicepin>]");
+ console.log(program.helpInformation());
return false;
}
if (properties.targets[target].ip) {
ip = properties.targets[target].ip;
} else {
console.log("IP is not defined in target \""+target+"\"");
+ console.log(program.helpInformation());
return false;
}
if (properties.targets[target].password) {
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/8968d01d/blackberry10/bin/templates/project/cordova/lib/target
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/target b/blackberry10/bin/templates/project/cordova/lib/target
index c21e6c7..0a5746b 100644
--- a/blackberry10/bin/templates/project/cordova/lib/target
+++ b/blackberry10/bin/templates/project/cordova/lib/target
@@ -41,7 +41,9 @@ function isValidIp(ip) {
ipArray;
if (typeof ip !== 'string') {
- throw "IP is required";
+ console.log("IP is required");
+ console.log(commander.helpInformation());
+ process.exit(2);
} else {
ipArray = ip.split('.');
if (ipArray.length !== 4) {
@@ -61,7 +63,9 @@ function isValidType(type) {
var result = true;
if (typeof type !== 'string') {
- throw "target type is required";
+ console.log("target type is required");
+ console.log(commander.helpInformation());
+ process.exit(2);
}
else if (!(type === 'device' || type === 'simulator')) {
result = false;
@@ -98,7 +102,9 @@ commander
.description("Add specified target")
.action(function () {
if (commander.args.length === 1) {
- throw "Target details not specified";
+ console.log("Target details not specified");
+ console.log(commander.helpInformation());
+ process.exit(2);
}
name = commander.args[0];
ip = commander.args[1];
@@ -110,13 +116,19 @@ commander
pin = commander.pin;
}
if (!isValidIp(ip)) {
- throw "Invalid IP: " + ip;
+ console.log("Invalid IP: " + ip);
+ console.log(commander.helpInformation());
+ process.exit(2);
}
if (!isValidType(type)) {
- throw "Invalid target type: " + type;
+ console.log("Invalid target type: " + type);
+ console.log(commander.helpInformation());
+ process.exit(2);
}
if (!isValidPin(pin)) {
- throw "Invalid PIN: " + pin;
+ console.log("Invalid PIN: " + pin);
+ console.log(commander.helpInformation());
+ process.exit(2);
}
if (properties.targets.hasOwnProperty(name)) {
console.log("Overwriting target: " + name);
@@ -129,11 +141,15 @@ commander
.description("Remove specified target")
.action(function () {
if (commander.args.length === 1) {
- throw 'No target specified';
+ console.log('No target specified');
+ console.log(commander.helpInformation());
+ process.exit(2);
}
name = commander.args[0];
if (!properties.targets.hasOwnProperty(name)) {
- throw "Target: '" + name + "' not found";
+ console.log("Target: '" + name + "' not found");
+ console.log(commander.helpInformation());
+ process.exit(2);
}
if (name === properties.defaultTarget) {
console.log("Deleting default target, please set a new default target");
@@ -154,14 +170,18 @@ commander
if (properties.targets.hasOwnProperty(name)) {
properties.defaultTarget = name;
} else {
- throw "Target '" + name + "' not found";
+ console.log("Target '" + name + "' not found");
+ console.log(commander.helpInformation());
+ process.exit(2);
}
});
commander
.command('*')
.action(function () {
- throw 'Unrecognized command';
+ console.log('Unrecognized command');
+ console.log(commander.helpInformation());
+ process.exit(2);
});