Skip to content

Commit

Permalink
[api] App and Log commands can now accept fully qualified application…
Browse files Browse the repository at this point in the history
… names
  • Loading branch information
Marak committed Nov 18, 2011
1 parent 2b84bca commit 371732c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
54 changes: 44 additions & 10 deletions lib/jitsu/commands/apps.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ apps.deploy.usage = [
// using `name` if supplied and falling back to `package.name`. // using `name` if supplied and falling back to `package.name`.
// //
apps.create = function (target, callback) { apps.create = function (target, callback) {

var name;

if (!callback) { if (!callback) {
callback = target; callback = target;
target = null; target = null;
} }


var name;

function executeCreate (err, pkg) { function executeCreate (err, pkg) {
if (err) { if (err) {
winston.error(err); winston.error(err);
Expand Down Expand Up @@ -233,10 +234,17 @@ apps.create.usage = [
// #### @callback {function} Continuation to pass control to when complete. // #### @callback {function} Continuation to pass control to when complete.
// Lists the applications for the authenticated user. // Lists the applications for the authenticated user.
// //
apps.list = function (callback) { apps.list = function (username, callback) {
winston.info('Listing apps'); winston.info('Listing apps');
jitsu.apps.list(function (err, apps) {
if(!callback){
callback = username;
username = jitsu.config.get('username');
}

jitsu.apps.list(username, function (err, apps) {
if (err) { if (err) {
console.log(err);
return callback(err); return callback(err);
} }


Expand Down Expand Up @@ -282,6 +290,11 @@ apps.list.usage = [
// If no name is supplied this will view the application in the current directory. // If no name is supplied this will view the application in the current directory.
// //
apps.view = function (name, callback) { apps.view = function (name, callback) {

if(name.search('/') === -1){
name = jitsu.config.get('username') + '/' + name;
}

function executeView() { function executeView() {
jitsu.apps.view(name, function (err, app) { jitsu.apps.view(name, function (err, app) {
if (err) { if (err) {
Expand Down Expand Up @@ -324,11 +337,11 @@ apps.view.usage = [
// Lists the applications for the authenticated user. // Lists the applications for the authenticated user.
// //
apps.update = function (name, callback) { apps.update = function (name, callback) {
if (!callback) {
callback = name; if(name.search('/') === -1){
name = null; name = jitsu.config.get('username') + '/' + name;
} }

winston.silly('Reading package.json in ' + process.cwd()); winston.silly('Reading package.json in ' + process.cwd());
jitsu.package.tryRead(process.cwd(), callback, function (pkg) { jitsu.package.tryRead(process.cwd(), callback, function (pkg) {
name = name || pkg.name; name = name || pkg.name;
Expand Down Expand Up @@ -371,6 +384,11 @@ apps.update.usage = [
// this will destroy the application in the current directory. // this will destroy the application in the current directory.
// //
apps.destroy = function (name, callback) { apps.destroy = function (name, callback) {

if(name.search('/') === -1){
name = jitsu.config.get('username') + '/' + name;
}

function executeDestroy() { function executeDestroy() {
winston.info('Destroying app ' + name.magenta); winston.info('Destroying app ' + name.magenta);
jitsu.apps.destroy(name, function (err) { jitsu.apps.destroy(name, function (err) {
Expand Down Expand Up @@ -408,7 +426,13 @@ apps.destroy.usage = [
// Starts the application specified by `name`. If no name is supplied // Starts the application specified by `name`. If no name is supplied
// this will start the application in the current directory. // this will start the application in the current directory.
// //
apps.start = function (name, callback) { apps.start = function (name, callback) {

if(name.search('/') === -1){
name = jitsu.config.get('username') + '/' + name;
}

console.log(name);
function executeStart() { function executeStart() {
winston.info('Starting app ' + name.magenta); winston.info('Starting app ' + name.magenta);
jitsu.apps.start(name, function (err) { jitsu.apps.start(name, function (err) {
Expand Down Expand Up @@ -458,6 +482,11 @@ apps.start.usage = [
// this will restart the application in the current directory. // this will restart the application in the current directory.
// //
apps.restart = function (name, callback) { apps.restart = function (name, callback) {

if(name.search('/') === -1){
name = jitsu.config.get('username') + '/' + name;
}

function executeRestart() { function executeRestart() {
winston.info('Restarting app ' + name.magenta); winston.info('Restarting app ' + name.magenta);
jitsu.apps.restart(name, function (err) { jitsu.apps.restart(name, function (err) {
Expand Down Expand Up @@ -500,6 +529,11 @@ apps.restart.usage = [
// this will stop the application in the current directory. // this will stop the application in the current directory.
// //
apps.stop = function (name, callback) { apps.stop = function (name, callback) {

if(name.search('/') === -1){
name = jitsu.config.get('username') + '/' + name;
}

function executeStop() { function executeStop() {
winston.info('Stopping app ' + name.magenta); winston.info('Stopping app ' + name.magenta);
jitsu.apps.stop(name, function (err) { jitsu.apps.stop(name, function (err) {
Expand Down
11 changes: 8 additions & 3 deletions lib/jitsu/commands/logs.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ logs.all = function (amount, callback) {
amount = 10; amount = 10;
} }


jitsu.logs.byUser(amount, function (err, apps) { jitsu.logs.byUser(jitsu.config.get('username'), amount, function (err, apps) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
Expand Down Expand Up @@ -82,6 +82,11 @@ logs.app = function (appName, amount, callback) {
// This is defined so that it can get called once all the arguments are // This is defined so that it can get called once all the arguments are
// sorted out. // sorted out.
var byApp = function (appName, amount, callback) { var byApp = function (appName, amount, callback) {

if(appName.search('/') === -1){
appName = jitsu.config.get('username') + '/' + appName;
}

jitsu.logs.byApp(appName, amount, function (err, results) { jitsu.logs.byApp(appName, amount, function (err, results) {
if (err) { if (err) {
return callback(err); return callback(err);
Expand All @@ -108,14 +113,14 @@ logs.app = function (appName, amount, callback) {
} else { } else {
// Plug in the app name and go // Plug in the app name and go
appName = result["app name"]; appName = result["app name"];
byApp(appName, 10, callback); byApp(appName, 100, callback);
} }
}); });
} }
}); });
} else if (callback === undefined) { } else if (callback === undefined) {
callback = amount; callback = amount;
amount = 10; amount = 100;
byApp(appName, amount, callback); byApp(appName, amount, callback);
} else { } else {
byApp(appName, amount, callback); byApp(appName, amount, callback);
Expand Down

0 comments on commit 371732c

Please sign in to comment.