Permalink
Browse files

[api doc] Finished up work on `jitsu help *` commands

  • Loading branch information...
indexzero committed Mar 12, 2011
1 parent f1ea9d7 commit c6305f814a52b92bcad9f92ac347a745177211df
View
@@ -36,7 +36,7 @@ jitsu.log = require('jitsu/log');
jitsu.api = {};
jitsu.api.Client = require('jitsu/api/client').Client;
jitsu.api.Apps = require('jitsu/api/apps').Apps;
-jitsu.api.Snapshots = require('jitsu/api/snapshots').Snapshots
+jitsu.api.Snapshots = require('jitsu/api/snapshots').Snapshots;
jitsu.api.Users = require('jitsu/api/users').Users;
jitsu.prompt = require('jitsu/prompt');
jitsu.config = require('jitsu/config');
@@ -80,18 +80,21 @@ jitsu.exec = function (command, callback) {
jitsu.setup();
}
- winston.info('Executing command ' + jitsu.commands.parse(command).splice(0,2).join(' ').magenta);
+ winston.info('Executing command ' + jitsu.commands.parse(command).splice(0, 2).join(' ').magenta);
jitsu.commands.run(command, function (err, shallow) {
if (err && !/403/.test(err.message)) {
- winston.error('Error running command ' + command.magenta);
- winston.error(err.message);
+ if (err && err.message) {
+ winston.error('Error running command ' + command.magenta);
+ winston.error(err.message);
+ }
if (err.stack && !shallow) {
err.stack.split('\n').forEach(function (trace) {
winston.error(trace);
- })
+ });
}
- return
+ winston.info('Nodejitsu '.grey + 'not ok'.red.bold);
+ return;
}
//
@@ -139,7 +142,7 @@ jitsu.auth = function (callback) {
winston.info('Authenticated as ' + jitsu.config.username.magenta);
callback();
});
-}
+};
//
// ### function setupUser (callback)
@@ -148,7 +151,7 @@ jitsu.auth = function (callback) {
// and saves the resulting configuration to disk.
//
jitsu.setupUser = function (callback) {
- winston.info('No user has been setup on this machine')
+ winston.info('No user has been setup on this machine');
jitsu.prompt.get(['username', 'password'], function (result) {
jitsu.config.settings.auth = [result.username, result.password].join(':');
jitsu.setup();
View
@@ -56,16 +56,18 @@ Client.prototype._request = function (method, uri /* variable arguments */) {
return callback(err);
}
+ var statusCode, result, error;
+
try {
- var statusCode = response.statusCode.toString(),
- result = JSON.parse(body);
+ statusCode = response.statusCode.toString();
+ result = JSON.parse(body);
}
catch (ex) {
// Ignore Errors
}
if (Object.keys(jitsu.failCodes).indexOf(statusCode) !== -1) {
- var error = new Error('Nodejitsu Error (' + statusCode + '): ' + jitsu.failCodes[statusCode]);
+ error = new Error('Nodejitsu Error (' + statusCode + '): ' + jitsu.failCodes[statusCode]);
error.result = result;
return callback(error);
}
@@ -105,16 +107,18 @@ Client.prototype._upload = function (uri, contentType, file, callback, success)
return callback(err);
}
+ var statusCode, result, error;
+
try {
- var statusCode = response.statusCode.toString(),
- result = JSON.parse(body);
+ statusCode = response.statusCode.toString();
+ result = JSON.parse(body);
}
catch (ex) {
// Ignore Errors
}
if (Object.keys(jitsu.failCodes).indexOf(statusCode) !== -1) {
- var error = new Error('Nodejitsu Error (' + statusCode + '): ' + jitsu.failCodes[statusCode]);
+ error = new Error('Nodejitsu Error (' + statusCode + '): ' + jitsu.failCodes[statusCode]);
error.result = result;
return callback(error);
}
View
@@ -48,14 +48,20 @@ commands.run = function (command, callback) {
commands.commands.help.show(name);
return callback();
}
+ else if (name === 'help' && (!action || action === 'show')) {
+ commands.commands.help.show('help');
+ return callback();
+ }
if (!commands.commands[name]) {
return callback(new Error('Cannot run command on unknown resource: ' + name), true);
}
resource = commands.commands[name];
if (!resource[action]) {
- return callback(new Error('Cannot run unknown action ' + action + ' on resource ' + name), true);
+ winston.error('Unknown action ' + action + ' on resource ' + name.magenta);
+ commands.commands.help.show(name);
+ return callback(true);
}
//
@@ -81,10 +87,10 @@ commands.run = function (command, callback) {
//
expected = resource[action].length;
if (parts.length > expected) {
- return callback(new Error('Wrong number of arguments: ' + parts.length + ' for ' + expected), true)
+ return callback(new Error('Wrong number of arguments: ' + parts.length + ' for ' + expected), true);
}
- function runCommand () {
+ function runCommand() {
resource[action].apply(resource, parts);
}
View
@@ -27,7 +27,7 @@ apps.usage = [
'For commands that take a <name> parameter, if no parameter',
'is supplied, jitsu will attempt to read the package.json',
'from the current directory.'
-]
+];
//
// ### function list (callback)
@@ -45,7 +45,10 @@ apps.create = function (name, callback) {
pkg.name = name || pkg.name;
jitsu.apps.list(function (err, apps) {
- var existing = apps.filter(function (a) { return a.name === pkg.name });
+ var existing = apps.filter(function (a) {
+ return a.name === pkg.name;
+ });
+
if (existing.length > 0) {
return winston.warn('Cannot create duplicate application ' + pkg.name.magenta);
}
@@ -66,6 +69,18 @@ apps.create = function (name, callback) {
});
};
+//
+// Usage for `jitsu apps create [<name>]`
+//
+apps.create.usage = [
+ 'Creates an application using the package.json file in the',
+ 'current directory, if <name> is supplied then this is used',
+ 'instead of the `name` property in the package.json file.',
+ '',
+ 'jitsu apps create',
+ 'jitsu apps create <name>'
+];
+
//
// ### function list (callback)
// #### @callback {function} Continuation to pass control to when complete.
@@ -95,6 +110,15 @@ apps.list = function (callback) {
});
};
+//
+// Usage for `jitsu apps list`
+//
+apps.list.usage = [
+ 'Lists all of the applications for the current user',
+ '',
+ 'jitsu apps list'
+];
+
//
// ### function view (name, callback)
// #### @name {string} **optional** Name of the application to view
@@ -103,15 +127,6 @@ apps.list = function (callback) {
// If no name is supplied this will view the application in the current directory.
//
apps.view = function (name, callback) {
- if (!callback) {
- callback = name;
- return jitsu.utils.readPackage(process.cwd(), function (err, package) {
- name = package.name;
- executeView();
- });
- }
-
-
function executeView() {
jitsu.apps.view(name, function (err, app) {
if (err) {
@@ -126,8 +141,28 @@ apps.view = function (name, callback) {
});
}
+ if (!callback) {
+ callback = name;
+ return jitsu.utils.readPackage(process.cwd(), function (err, pkg) {
+ name = pkg.name;
+ executeView();
+ });
+ }
+
executeView();
-}
+};
+
+//
+// Usage for `jitsu apps view [<name>]`
+//
+apps.view.usage = [
+ 'Lists the information for the application in the current',
+ 'directory. If <name> is supplied then that application',
+ 'is listed instead.',
+ '',
+ 'jitsu apps view',
+ 'jitsu apps view <name>'
+];
//
// ### function list (callback)
@@ -167,6 +202,18 @@ apps.update = function (name, callback) {
});
};
+//
+// Usage for `jitsu apps update [<name>]`
+//
+apps.update.usage = [
+ 'Updates the application in the current directory',
+ 'with the information in the package.json file. If',
+ '<name> is supplied the application with <name> is updated.',
+ '',
+ 'jitsu apps update',
+ 'jitsu apps update <name>'
+];
+
//
// ### function destroy (callback)
// #### @name {string} **optional** Name of the application to destroy.
@@ -175,75 +222,108 @@ apps.update = function (name, callback) {
// this will destroy the application in the current directory.
//
apps.destroy = function (name, callback) {
- if (!callback) {
- callback = name;
- return jitsu.utils.readPackage(process.cwd(), function (err, package) {
- name = package.name;
- executeDestroy();
- });
- }
-
- function executeDestroy () {
+ function executeDestroy() {
winston.info('Destroying app ' + name.magenta);
jitsu.apps.destroy(name, function (err) {
winston.silly('Done destroying app ' + name.magenta);
return err ? callback(err) : callback();
});
}
+
+ if (!callback) {
+ callback = name;
+ return jitsu.utils.readPackage(process.cwd(), function (err, pkg) {
+ name = pkg.name;
+ executeDestroy();
+ });
+ }
executeDestroy();
};
+//
+// Usage for `jitsu apps destroy [<name>]`
+//
+apps.destroy.usage = [
+ 'Destroys the application in the current directory. If',
+ '<name> is supplied then that application is destroyed instead',
+ '',
+ 'jitsu apps destroy',
+ 'jitsu apps destroy <name>'
+];
+
//
// ### function start (callback)
// #### @name {string} **optional** Name of the application to start.
// #### @callback {function} Continuation to pass control to when complete.
// Starts the application specified by `name`. If no name is supplied
// this will start the application in the current directory.
//
-apps.start = function (name, callback) {
- if (!callback) {
- callback = name;
- return jitsu.utils.readPackage(process.cwd(), function (err, package) {
- name = package.name;
- executeStart();
- });
- }
-
- function executeStart () {
+apps.start = function (name, callback) {
+ function executeStart() {
winston.info('Starting app ' + name.magenta);
jitsu.apps.start(name, function (err) {
winston.info('App ' + name.magenta + ' is now started');
return err ? callback(err) : callback();
});
}
+
+ if (!callback) {
+ callback = name;
+ return jitsu.utils.readPackage(process.cwd(), function (err, pkg) {
+ name = pkg.name;
+ executeStart();
+ });
+ }
executeStart();
};
+//
+// Usage for `jitsu apps start [<name>]`
+//
+apps.start.usage = [
+ 'Starts the application in the current directory. If <name>',
+ 'is supplied then that application is started instead.',
+ '',
+ 'jitsu apps start',
+ 'jitsu apps start <name>'
+];
+
//
// ### function stop (callback)
// #### @name {string} **optional** Name of the application to stop.
// #### @callback {function} Continuation to pass control to when complete.
// Stops the application specified by `name`. If no name is supplied
// this will stop the application in the current directory.
//
-apps.stop = function (name, callback) {
- if (!callback) {
- callback = name;
- return jitsu.utils.readPackage(process.cwd(), function (err, package) {
- name = package.name;
- executeStop();
- });
- }
-
- function executeStop () {
+apps.stop = function (name, callback) {
+ function executeStop() {
winston.info('Stopping app ' + name.magenta);
jitsu.apps.stop(name, function (err) {
winston.info('App ' + name.magenta + ' is now stopped');
return err ? callback(err) : callback();
});
}
+
+ if (!callback) {
+ callback = name;
+ return jitsu.utils.readPackage(process.cwd(), function (err, pkg) {
+ name = pkg.name;
+ executeStop();
+ });
+ }
- executeStart();
-};
+ executeStop();
+};
+
+//
+// Usage for `jitsu apps stop [<name>]`
+//
+apps.stop.usage = [
+ 'Stops the application in the current directory. If <name>',
+ 'is supplied then that application is stopped instead.',
+ '',
+ 'jitsu apps stop',
+ 'jitsu apps stop <name>'
+];
Oops, something went wrong.

0 comments on commit c6305f8

Please sign in to comment.