Implement app rm command

This commit is contained in:
Juan Cruz Viotti 2014-11-21 09:43:03 -04:00
parent 1c1e8b375e
commit 37c68118db
4 changed files with 28 additions and 0 deletions

View File

@ -2,6 +2,7 @@ _ = require('lodash')
device = require('../device/device')
table = require('../table/table')
server = require('../server/server')
widgets = require('../widgets/widgets')
applicationModel = require('../models/application')
authHooks = require('../hooks/auth')
config = require('../config')
@ -38,3 +39,9 @@ exports.restart = authHooks.failIfNotLoggedIn (id) ->
# TODO: Move this URL to config
server.post "/application/#{id}/restart", (error) ->
throw error if error?
exports.remove = authHooks.failIfNotLoggedIn (id) ->
widgets.confirmRemoval 'application', (error, confirmed) ->
return if not confirmed
applicationModel.remove(id).catch (error) ->
throw error if error?

View File

@ -41,6 +41,11 @@ program
.description('Restart an application')
.action(app.restart)
program
.command('app:rm <id>')
.description('Remove an application')
.action(app.remove)
# ---------- Device Module ----------
device = require('./actions/device')

View File

@ -18,3 +18,8 @@ exports.get = (id) ->
Promise.reject(new Error('Not found'))
return application
exports.remove = (id) ->
return canvas.delete
resource: 'application'
id: id

View File

@ -14,3 +14,14 @@ exports.login = (callback) ->
message: 'Password'
}
], _.partial(callback, null))
exports.confirmRemoval = (name, callback) ->
inquirer.prompt [
{
type: 'confirm'
name: 'confirmed'
message: "Are you sure you want to delete the #{name}?"
default: false
}
], (response) ->
return callback(null, response.confirmed)