From 77d84103f6bbaa1a0ef28bfd03ff1691a7a2de68 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 19 Nov 2014 09:23:40 -0400 Subject: [PATCH] Implement app info action --- lib/actions/app.coffee | 13 ++++++++++++- lib/app.coffee | 5 +++++ lib/models/application.coffee | 12 ++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/actions/app.coffee b/lib/actions/app.coffee index 51f5e48d..c189a00d 100644 --- a/lib/actions/app.coffee +++ b/lib/actions/app.coffee @@ -6,7 +6,6 @@ applicationModel = require('../models/application') authHooks = require('../hooks/auth') exports.list = authHooks.failIfNotLoggedIn -> - applicationModel.getAll().then (applications) -> applications = _.map applications, (application) -> @@ -19,3 +18,15 @@ exports.list = authHooks.failIfNotLoggedIn -> } console.log cliff.stringifyObjectRows(applications, _.keys _.first applications) + +exports.info = authHooks.failIfNotLoggedIn (id) -> + applicationModel.get(id).then (application) -> + + console.log("ID: #{application.id}") + console.log("Name: #{application.app_name}") + console.log("Device Type: #{device.getDisplayName(application.device_type)}") + console.log("Git Repository: #{application.git_repository}") + console.log("Commit: #{application.commit}") + + .catch (error) -> + throw error diff --git a/lib/app.coffee b/lib/app.coffee index 4c2a116d..5152dfd2 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -33,6 +33,11 @@ program .description('Show a list of your apps') .action(app.list) +program + .command('app ') + .description('Show an application') + .action(app.info) + # ---------- Preferences Module ---------- preferences = require('./actions/preferences') diff --git a/lib/models/application.coffee b/lib/models/application.coffee index 985aac85..fd1e3e9b 100644 --- a/lib/models/application.coffee +++ b/lib/models/application.coffee @@ -1,3 +1,4 @@ +Promise = require('bluebird') canvas = require('./_canvas') exports.getAll = -> @@ -6,3 +7,14 @@ exports.getAll = -> options: orderby: 'app_name asc' expand: 'device' + +exports.get = (id) -> + return canvas.get + resource: 'application' + id: id + + .then (application) -> + if not application? + Promise.reject(new Error('Not found')) + + return application