Resin CLI Events integration. Fix #103

This commit is contained in:
mike 2015-09-01 00:39:48 +03:00 committed by Juan Cruz Viotti
parent d10d4ce185
commit b0650530cc
11 changed files with 124 additions and 24 deletions

View File

@ -1,5 +1,5 @@
(function() {
var _, commandOptions, helpers, resin, vcs, visuals;
var _, commandOptions, events, helpers, resin, vcs, visuals;
_ = require('lodash');
@ -11,6 +11,8 @@
vcs = require('resin-vcs');
events = require('resin-cli-events');
helpers = require('../utils/helpers');
exports.create = {
@ -34,7 +36,10 @@
}).then(helpers.selectDeviceType).then(function(deviceType) {
return resin.models.application.create(params.name, deviceType);
}).then(function(application) {
return console.info("Application created: " + application.app_name + " (" + application.device_type + ", id " + application.id + ")");
console.info("Application created: " + application.app_name + " (" + application.device_type + ", id " + application.id + ")");
return events.send('application.create', {
application: application.id
});
}).nodeify(done);
}
};
@ -58,7 +63,10 @@
permission: 'user',
action: function(params, options, done) {
return resin.models.application.get(params.name).then(function(application) {
return console.log(visuals.table.vertical(application, ["$" + application.app_name + "$", 'id', 'device_type', 'git_repository', 'commit']));
console.log(visuals.table.vertical(application, ["$" + application.app_name + "$", 'id', 'device_type', 'git_repository', 'commit']));
return events.send('application.open', {
application: application.id
});
}).nodeify(done);
}
};
@ -82,6 +90,12 @@
action: function(params, options, done) {
return helpers.confirm(options.yes, 'Are you sure you want to delete the application?').then(function() {
return resin.models.application.remove(params.name);
}).tap(function() {
return resin.models.application.get(params.name).then(function(application) {
return events.send('application.delete', {
application: application.id
});
});
}).nodeify(done);
}
};

View File

@ -1,5 +1,5 @@
(function() {
var Promise, TOKEN_URL, _, form, open, resin, settings, url, validEmail, visuals;
var Promise, TOKEN_URL, _, events, form, open, resin, settings, url, validEmail, visuals;
Promise = require('bluebird');
@ -19,6 +19,8 @@
validEmail = require('valid-email');
events = require('resin-cli-events');
TOKEN_URL = url.resolve(settings.get('dashboardUrl'), '/preferences');
exports.login = {
@ -40,7 +42,8 @@
});
});
}).then(resin.auth.loginWithToken).then(resin.auth.whoami).tap(function(username) {
return console.info("Successfully logged in as: " + username);
console.info("Successfully logged in as: " + username);
return events.send('user.login');
}).nodeify(done);
}
};
@ -51,7 +54,9 @@
help: 'Use this command to logout from your resin.io account.o\n\nExamples:\n\n $ resin logout',
permission: 'user',
action: function(params, options, done) {
return resin.auth.logout().nodeify(done);
return resin.auth.logout().then(function() {
return events.send('user.logout');
}).nodeify(done);
}
};
@ -86,7 +91,9 @@
return true;
}
}
]).then(resin.auth.register).then(resin.auth.loginWithToken).nodeify(done);
]).then(resin.auth.register).then(resin.auth.loginWithToken).tap(function() {
return events.send('user.signup');
}).nodeify(done);
}
};

View File

@ -1,5 +1,5 @@
(function() {
var Promise, _, async, capitano, commandOptions, deviceConfig, form, helpers, htmlToText, image, inject, manager, pine, registerDevice, resin, vcs, visuals;
var Promise, _, async, capitano, commandOptions, deviceConfig, events, form, helpers, htmlToText, image, inject, manager, pine, registerDevice, resin, vcs, visuals;
Promise = require('bluebird');
@ -29,6 +29,8 @@
form = require('resin-cli-form');
events = require('resin-cli-events');
htmlToText = require('html-to-text');
helpers = require('../utils/helpers');
@ -63,7 +65,10 @@
if (device.last_seen == null) {
device.last_seen = 'Not seen';
}
return console.log(visuals.table.vertical(device, ["$" + device.name + "$", 'id', 'device_type', 'is_online', 'ip_address', 'application_name', 'status', 'last_seen', 'uuid', 'commit', 'supervisor_version', 'is_web_accessible', 'note']));
console.log(visuals.table.vertical(device, ["$" + device.name + "$", 'id', 'device_type', 'is_online', 'ip_address', 'application_name', 'status', 'last_seen', 'uuid', 'commit', 'supervisor_version', 'is_web_accessible', 'note']));
return events.send('device.open', {
device: device.uuid
});
}).nodeify(done);
}
};
@ -77,6 +82,10 @@
action: function(params, options, done) {
return helpers.confirm(options.yes, 'Are you sure you want to delete the device?').then(function() {
return resin.models.device.remove(params.uuid);
}).tap(function() {
return events.send('device.delete', {
device: params.uuid
});
}).nodeify(done);
}
};
@ -105,7 +114,11 @@
message: 'How do you want to name this device?',
type: 'input'
});
}).then(_.partial(resin.models.device.rename, params.uuid)).nodeify(done);
}).then(_.partial(resin.models.device.rename, params.uuid)).tap(function() {
return events.send('device.rename', {
device: params.uuid
});
}).nodeify(done);
}
};

View File

@ -1,5 +1,5 @@
(function() {
var Promise, _, commandOptions, helpers, resin, visuals;
var Promise, _, commandOptions, events, helpers, resin, visuals;
Promise = require('bluebird');
@ -9,6 +9,8 @@
visuals = require('resin-cli-visuals');
events = require('resin-cli-events');
commandOptions = require('./command-options');
helpers = require('../utils/helpers');
@ -58,9 +60,15 @@
action: function(params, options, done) {
return helpers.confirm(options.yes, 'Are you sure you want to delete the environment variable?').then(function() {
if (options.device) {
return resin.models.environmentVariables.device.remove(params.id);
resin.models.environmentVariables.device.remove(params.id);
return events.send('deviceEnvironmentVariable.delete', {
id: params.id
});
} else {
return resin.models.environmentVariables.remove(params.id);
resin.models.environmentVariables.remove(params.id);
return events.send('environmentVariable.delete', {
id: params.id
});
}
}).nodeify(done);
}
@ -83,9 +91,19 @@
}
}
if (options.application != null) {
return resin.models.environmentVariables.create(options.application, params.key, params.value);
return resin.models.environmentVariables.create(options.application, params.key, params.value).then(function() {
return resin.models.application.get(options.application).then(function(application) {
return events.send('environmentVariable.create', {
application: application.id
});
});
});
} else if (options.device != null) {
return resin.models.environmentVariables.device.create(options.device, params.key, params.value);
return resin.models.environmentVariables.device.create(options.device, params.key, params.value).then(function() {
return events.send('deviceEnvironmentVariable.create', {
device: options.device
});
});
} else {
throw new Error('You must specify an application or device');
}
@ -102,9 +120,17 @@
action: function(params, options, done) {
return Promise["try"](function() {
if (options.device) {
return resin.models.environmentVariables.device.update(params.id, params.value);
return resin.models.environmentVariables.device.update(params.id, params.value).then(function() {
return events.send('deviceEnvironmentVariable.edit', {
id: params.id
});
});
} else {
return resin.models.environmentVariables.update(params.id, params.value);
return resin.models.environmentVariables.update(params.id, params.value).then(function() {
return events.send('environmentVariable.edit', {
id: params.id
});
});
}
}).nodeify(done);
}

View File

@ -1,5 +1,5 @@
(function() {
var Promise, _, capitano, commandOptions, fs, helpers, resin, visuals;
var Promise, _, capitano, commandOptions, events, fs, helpers, resin, visuals;
Promise = require('bluebird');
@ -13,6 +13,8 @@
visuals = require('resin-cli-visuals');
events = require('resin-cli-events');
commandOptions = require('./command-options');
helpers = require('../utils/helpers');
@ -51,6 +53,10 @@
action: function(params, options, done) {
return helpers.confirm(options.yes, 'Are you sure you want to delete the key?').then(function() {
return resin.models.key.remove(params.id);
}).tap(function() {
return events.send('publicKey.delete', {
id: params.id
});
}).nodeify(done);
}
};
@ -72,7 +78,9 @@
return callback(null, data);
});
});
}).then(_.partial(resin.models.key.create, params.name)).nodeify(done);
}).then(_.partial(resin.models.key.create, params.name)).tap(function() {
return events.send('publicKey.create');
}).nodeify(done);
}
};

View File

@ -3,6 +3,7 @@ resin = require('resin-sdk')
visuals = require('resin-cli-visuals')
commandOptions = require('./command-options')
vcs = require('resin-vcs')
events = require('resin-cli-events')
helpers = require('../utils/helpers')
exports.create =
@ -45,6 +46,7 @@ exports.create =
return resin.models.application.create(params.name, deviceType)
.then (application) ->
console.info("Application created: #{application.app_name} (#{application.device_type}, id #{application.id})")
events.send('application.create', application: application.id)
.nodeify(done)
exports.list =
@ -92,6 +94,7 @@ exports.info =
'git_repository'
'commit'
]
events.send('application.open', application: application.id)
.nodeify(done)
exports.restart =
@ -127,6 +130,9 @@ exports.remove =
action: (params, options, done) ->
helpers.confirm(options.yes, 'Are you sure you want to delete the application?').then ->
resin.models.application.remove(params.name)
.tap ->
resin.models.application.get(params.name).then (application) ->
events.send('application.delete', application: application.id)
.nodeify(done)
exports.associate =

View File

@ -7,6 +7,7 @@ settings = require('resin-settings-client')
form = require('resin-cli-form')
visuals = require('resin-cli-visuals')
validEmail = require('valid-email')
events = require('resin-cli-events')
TOKEN_URL = url.resolve(settings.get('dashboardUrl'), '/preferences')
@ -50,6 +51,7 @@ exports.login =
.then(resin.auth.whoami)
.tap (username) ->
console.info("Successfully logged in as: #{username}")
events.send('user.login')
.nodeify(done)
exports.logout =
@ -64,7 +66,9 @@ exports.logout =
'''
permission: 'user'
action: (params, options, done) ->
resin.auth.logout().nodeify(done)
resin.auth.logout().then ->
events.send('user.logout')
.nodeify(done)
exports.signup =
signature: 'signup'
@ -111,6 +115,8 @@ exports.signup =
.then(resin.auth.register)
.then(resin.auth.loginWithToken)
.tap ->
events.send('user.signup')
.nodeify(done)
exports.whoami =

View File

@ -12,6 +12,7 @@ registerDevice = require('resin-register-device')
pine = require('resin-pine')
deviceConfig = require('resin-device-config')
form = require('resin-cli-form')
events = require('resin-cli-events')
htmlToText = require('html-to-text')
helpers = require('../utils/helpers')
@ -86,6 +87,7 @@ exports.info =
'is_web_accessible'
'note'
]
events.send('device.open', device: device.uuid)
.nodeify(done)
exports.remove =
@ -107,6 +109,8 @@ exports.remove =
action: (params, options, done) ->
helpers.confirm(options.yes, 'Are you sure you want to delete the device?').then ->
resin.models.device.remove(params.uuid)
.tap ->
events.send('device.delete', device: params.uuid)
.nodeify(done)
exports.identify =
@ -148,6 +152,8 @@ exports.rename =
type: 'input'
.then(_.partial(resin.models.device.rename, params.uuid))
.tap ->
events.send('device.rename', device: params.uuid)
.nodeify(done)
exports.await =

View File

@ -2,6 +2,7 @@ Promise = require('bluebird')
_ = require('lodash')
resin = require('resin-sdk')
visuals = require('resin-cli-visuals')
events = require('resin-cli-events')
commandOptions = require('./command-options')
helpers = require('../utils/helpers')
@ -85,8 +86,10 @@ exports.remove =
helpers.confirm(options.yes, 'Are you sure you want to delete the environment variable?').then ->
if options.device
resin.models.environmentVariables.device.remove(params.id)
events.send('deviceEnvironmentVariable.delete', id: params.id)
else
resin.models.environmentVariables.remove(params.id)
events.send('environmentVariable.delete', id: params.id)
.nodeify(done)
exports.add =
@ -126,9 +129,12 @@ exports.add =
console.info("Warning: using #{params.key}=#{params.value} from host environment")
if options.application?
resin.models.environmentVariables.create(options.application, params.key, params.value)
resin.models.environmentVariables.create(options.application, params.key, params.value).then ->
resin.models.application.get(options.application).then (application) ->
events.send('environmentVariable.create', application: application.id)
else if options.device?
resin.models.environmentVariables.device.create(options.device, params.key, params.value)
resin.models.environmentVariables.device.create(options.device, params.key, params.value).then ->
events.send('deviceEnvironmentVariable.create', device: options.device)
else
throw new Error('You must specify an application or device')
.nodeify(done)
@ -151,7 +157,9 @@ exports.rename =
action: (params, options, done) ->
Promise.try ->
if options.device
resin.models.environmentVariables.device.update(params.id, params.value)
resin.models.environmentVariables.device.update(params.id, params.value).then ->
events.send('deviceEnvironmentVariable.edit', id: params.id)
else
resin.models.environmentVariables.update(params.id, params.value)
resin.models.environmentVariables.update(params.id, params.value).then ->
events.send('environmentVariable.edit', id: params.id)
.nodeify(done)

View File

@ -4,6 +4,7 @@ _ = require('lodash')
resin = require('resin-sdk')
capitano = require('capitano')
visuals = require('resin-cli-visuals')
events = require('resin-cli-events')
commandOptions = require('./command-options')
helpers = require('../utils/helpers')
@ -69,6 +70,8 @@ exports.remove =
action: (params, options, done) ->
helpers.confirm(options.yes, 'Are you sure you want to delete the key?').then ->
resin.models.key.remove(params.id)
.tap ->
events.send('publicKey.delete', id: params.id)
.nodeify(done)
exports.add =
@ -95,4 +98,6 @@ exports.add =
return callback(null, data)
.then(_.partial(resin.models.key.create, params.name))
.tap ->
events.send('publicKey.create')
.nodeify(done)

View File

@ -50,6 +50,7 @@
"nplugm": "^3.0.0",
"npm": "^2.13.0",
"open": "0.0.5",
"resin-cli-events": "^1.0.2",
"resin-cli-form": "^1.2.1",
"resin-cli-visuals": "^1.1.0",
"resin-config-inject": "^2.0.0",