build bare modules

This commit is contained in:
Eugene Mirotin 2017-03-22 12:46:06 +03:00
parent b3aa3d35f7
commit 95fff4b7c4
40 changed files with 2577 additions and 2714 deletions

View File

@ -15,101 +15,97 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var commandOptions;
(function() {
var commandOptions;
commandOptions = require('./command-options');
commandOptions = require('./command-options');
exports.create = {
signature: 'app create <name>',
description: 'create an application',
help: 'Use this command to create a new resin.io application.\n\nYou can specify the application type with the `--type` option.\nOtherwise, an interactive dropdown will be shown for you to select from.\n\nYou can see a list of supported device types with\n\n $ resin devices supported\n\nExamples:\n\n $ resin app create MyApp\n $ resin app create MyApp --type raspberry-pi',
options: [
{
signature: 'type',
parameter: 'type',
description: 'application type',
alias: 't'
exports.create = {
signature: 'app create <name>',
description: 'create an application',
help: 'Use this command to create a new resin.io application.\n\nYou can specify the application type with the `--type` option.\nOtherwise, an interactive dropdown will be shown for you to select from.\n\nYou can see a list of supported device types with\n\n $ resin devices supported\n\nExamples:\n\n $ resin app create MyApp\n $ resin app create MyApp --type raspberry-pi',
options: [
{
signature: 'type',
parameter: 'type',
description: 'application type',
alias: 't'
}
],
permission: 'user',
action: function(params, options, done) {
var patterns, resin;
resin = require('resin-sdk-preconfigured');
patterns = require('../utils/patterns');
return resin.models.application.has(params.name).then(function(hasApplication) {
if (hasApplication) {
throw new Error('You already have an application with that name!');
}
],
permission: 'user',
action: function(params, options, done) {
var patterns, resin;
resin = require('resin-sdk-preconfigured');
patterns = require('../utils/patterns');
return resin.models.application.has(params.name).then(function(hasApplication) {
if (hasApplication) {
throw new Error('You already have an application with that name!');
}
}).then(function() {
return options.type || patterns.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 + ")");
}).nodeify(done);
}
};
}).then(function() {
return options.type || patterns.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 + ")");
}).nodeify(done);
}
};
exports.list = {
signature: 'apps',
description: 'list all applications',
help: 'Use this command to list all your applications.\n\nNotice this command only shows the most important bits of information for each app.\nIf you want detailed information, use resin app <name> instead.\n\nExamples:\n\n $ resin apps',
permission: 'user',
primary: true,
action: function(params, options, done) {
var resin, visuals;
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return resin.models.application.getAll().then(function(applications) {
return console.log(visuals.table.horizontal(applications, ['id', 'app_name', 'device_type', 'online_devices', 'devices_length']));
}).nodeify(done);
}
};
exports.list = {
signature: 'apps',
description: 'list all applications',
help: 'Use this command to list all your applications.\n\nNotice this command only shows the most important bits of information for each app.\nIf you want detailed information, use resin app <name> instead.\n\nExamples:\n\n $ resin apps',
permission: 'user',
primary: true,
action: function(params, options, done) {
var resin, visuals;
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return resin.models.application.getAll().then(function(applications) {
return console.log(visuals.table.horizontal(applications, ['id', 'app_name', 'device_type', 'online_devices', 'devices_length']));
}).nodeify(done);
}
};
exports.info = {
signature: 'app <name>',
description: 'list a single application',
help: 'Use this command to show detailed information for a single application.\n\nExamples:\n\n $ resin app MyApp',
permission: 'user',
primary: true,
action: function(params, options, done) {
var resin, visuals;
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
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']));
}).nodeify(done);
}
};
exports.info = {
signature: 'app <name>',
description: 'list a single application',
help: 'Use this command to show detailed information for a single application.\n\nExamples:\n\n $ resin app MyApp',
permission: 'user',
primary: true,
action: function(params, options, done) {
var resin, visuals;
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
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']));
}).nodeify(done);
}
};
exports.restart = {
signature: 'app restart <name>',
description: 'restart an application',
help: 'Use this command to restart all devices that belongs to a certain application.\n\nExamples:\n\n $ resin app restart MyApp',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.application.restart(params.name).nodeify(done);
}
};
exports.restart = {
signature: 'app restart <name>',
description: 'restart an application',
help: 'Use this command to restart all devices that belongs to a certain application.\n\nExamples:\n\n $ resin app restart MyApp',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.application.restart(params.name).nodeify(done);
}
};
exports.remove = {
signature: 'app rm <name>',
description: 'remove an application',
help: 'Use this command to remove a resin.io application.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin app rm MyApp\n $ resin app rm MyApp --yes',
options: [commandOptions.yes],
permission: 'user',
action: function(params, options, done) {
var patterns, resin;
resin = require('resin-sdk-preconfigured');
patterns = require('../utils/patterns');
return patterns.confirm(options.yes, 'Are you sure you want to delete the application?').then(function() {
return resin.models.application.remove(params.name);
}).nodeify(done);
}
};
}).call(this);
exports.remove = {
signature: 'app rm <name>',
description: 'remove an application',
help: 'Use this command to remove a resin.io application.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin app rm MyApp\n $ resin app rm MyApp --yes',
options: [commandOptions.yes],
permission: 'user',
action: function(params, options, done) {
var patterns, resin;
resin = require('resin-sdk-preconfigured');
patterns = require('../utils/patterns');
return patterns.confirm(options.yes, 'Are you sure you want to delete the application?').then(function() {
return resin.models.application.remove(params.name);
}).nodeify(done);
}
};

View File

@ -15,150 +15,146 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function() {
exports.login = {
signature: 'login',
description: 'login to resin.io',
help: 'Use this command to login to your resin.io account.\n\nThis command will prompt you to login using the following login types:\n\n- Web authorization: open your web browser and prompt you to authorize the CLI\nfrom the dashboard.\n\n- Credentials: using email/password and 2FA.\n\n- Token: using the authentication token from the preferences page.\n\nExamples:\n\n $ resin login\n $ resin login --web\n $ resin login --token "..."\n $ resin login --credentials\n $ resin login --credentials --email johndoe@gmail.com --password secret',
options: [
{
signature: 'token',
description: 'auth token',
parameter: 'token',
alias: 't'
}, {
signature: 'web',
description: 'web-based login',
boolean: true,
alias: 'w'
}, {
signature: 'credentials',
description: 'credential-based login',
boolean: true,
alias: 'c'
}, {
signature: 'email',
parameter: 'email',
description: 'email',
alias: ['e', 'u']
}, {
signature: 'password',
parameter: 'password',
description: 'password',
alias: 'p'
}
],
primary: true,
action: function(params, options, done) {
var Promise, _, auth, capitano, form, login, messages, patterns, resin;
_ = require('lodash');
Promise = require('bluebird');
capitano = Promise.promisifyAll(require('capitano'));
resin = require('resin-sdk-preconfigured');
auth = require('resin-cli-auth');
form = require('resin-cli-form');
patterns = require('../utils/patterns');
messages = require('../utils/messages');
login = function(options) {
if (options.token != null) {
return Promise["try"](function() {
if (_.isString(options.token)) {
return options.token;
}
return form.ask({
message: 'Token (from the preferences page)',
name: 'token',
type: 'input'
});
}).then(resin.auth.loginWithToken);
} else if (options.credentials) {
return patterns.authenticate(options);
} else if (options.web) {
console.info('Connecting to the web dashboard');
return auth.login();
}
return patterns.askLoginType().then(function(loginType) {
if (loginType === 'register') {
return capitano.runAsync('signup');
exports.login = {
signature: 'login',
description: 'login to resin.io',
help: 'Use this command to login to your resin.io account.\n\nThis command will prompt you to login using the following login types:\n\n- Web authorization: open your web browser and prompt you to authorize the CLI\nfrom the dashboard.\n\n- Credentials: using email/password and 2FA.\n\n- Token: using the authentication token from the preferences page.\n\nExamples:\n\n $ resin login\n $ resin login --web\n $ resin login --token "..."\n $ resin login --credentials\n $ resin login --credentials --email johndoe@gmail.com --password secret',
options: [
{
signature: 'token',
description: 'auth token',
parameter: 'token',
alias: 't'
}, {
signature: 'web',
description: 'web-based login',
boolean: true,
alias: 'w'
}, {
signature: 'credentials',
description: 'credential-based login',
boolean: true,
alias: 'c'
}, {
signature: 'email',
parameter: 'email',
description: 'email',
alias: ['e', 'u']
}, {
signature: 'password',
parameter: 'password',
description: 'password',
alias: 'p'
}
],
primary: true,
action: function(params, options, done) {
var Promise, _, auth, capitano, form, login, messages, patterns, resin;
_ = require('lodash');
Promise = require('bluebird');
capitano = Promise.promisifyAll(require('capitano'));
resin = require('resin-sdk-preconfigured');
auth = require('resin-cli-auth');
form = require('resin-cli-form');
patterns = require('../utils/patterns');
messages = require('../utils/messages');
login = function(options) {
if (options.token != null) {
return Promise["try"](function() {
if (_.isString(options.token)) {
return options.token;
}
options[loginType] = true;
return login(options);
});
};
return resin.settings.get('resinUrl').then(function(resinUrl) {
console.log(messages.resinAsciiArt);
console.log("\nLogging in to " + resinUrl);
return login(options);
}).then(resin.auth.whoami).tap(function(username) {
console.info("Successfully logged in as: " + username);
return console.info("\nNow what?\n\n" + messages.gettingStarted + "\n\nFind out about more super powers by running:\n\n $ resin help\n\n" + messages.reachingOut);
}).nodeify(done);
}
};
exports.logout = {
signature: 'logout',
description: 'logout from resin.io',
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) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.auth.logout().nodeify(done);
}
};
exports.signup = {
signature: 'signup',
description: 'signup to resin.io',
help: 'Use this command to signup for a resin.io account.\n\nIf signup is successful, you\'ll be logged in to your new user automatically.\n\nExamples:\n\n $ resin signup\n Email: me@mycompany.com\n Username: johndoe\n Password: ***********\n\n $ resin whoami\n johndoe',
action: function(params, options, done) {
var form, resin, validation;
resin = require('resin-sdk-preconfigured');
form = require('resin-cli-form');
validation = require('../utils/validation');
return resin.settings.get('resinUrl').then(function(resinUrl) {
console.log("\nRegistering to " + resinUrl);
return form.run([
{
message: 'Email:',
name: 'email',
type: 'input',
validate: validation.validateEmail
}, {
message: 'Username:',
name: 'username',
return form.ask({
message: 'Token (from the preferences page)',
name: 'token',
type: 'input'
}, {
message: 'Password:',
name: 'password',
type: 'password',
validate: validation.validatePassword
}
]);
}).then(resin.auth.register).then(resin.auth.loginWithToken).nodeify(done);
}
};
});
}).then(resin.auth.loginWithToken);
} else if (options.credentials) {
return patterns.authenticate(options);
} else if (options.web) {
console.info('Connecting to the web dashboard');
return auth.login();
}
return patterns.askLoginType().then(function(loginType) {
if (loginType === 'register') {
return capitano.runAsync('signup');
}
options[loginType] = true;
return login(options);
});
};
return resin.settings.get('resinUrl').then(function(resinUrl) {
console.log(messages.resinAsciiArt);
console.log("\nLogging in to " + resinUrl);
return login(options);
}).then(resin.auth.whoami).tap(function(username) {
console.info("Successfully logged in as: " + username);
return console.info("\nNow what?\n\n" + messages.gettingStarted + "\n\nFind out about more super powers by running:\n\n $ resin help\n\n" + messages.reachingOut);
}).nodeify(done);
}
};
exports.whoami = {
signature: 'whoami',
description: 'get current username and email address',
help: 'Use this command to find out the current logged in username and email address.\n\nExamples:\n\n $ resin whoami',
permission: 'user',
action: function(params, options, done) {
var Promise, resin, visuals;
Promise = require('bluebird');
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return Promise.props({
username: resin.auth.whoami(),
email: resin.auth.getEmail(),
url: resin.settings.get('resinUrl')
}).then(function(results) {
return console.log(visuals.table.vertical(results, ['$account information$', 'username', 'email', 'url']));
}).nodeify(done);
}
};
exports.logout = {
signature: 'logout',
description: 'logout from resin.io',
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) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.auth.logout().nodeify(done);
}
};
}).call(this);
exports.signup = {
signature: 'signup',
description: 'signup to resin.io',
help: 'Use this command to signup for a resin.io account.\n\nIf signup is successful, you\'ll be logged in to your new user automatically.\n\nExamples:\n\n $ resin signup\n Email: me@mycompany.com\n Username: johndoe\n Password: ***********\n\n $ resin whoami\n johndoe',
action: function(params, options, done) {
var form, resin, validation;
resin = require('resin-sdk-preconfigured');
form = require('resin-cli-form');
validation = require('../utils/validation');
return resin.settings.get('resinUrl').then(function(resinUrl) {
console.log("\nRegistering to " + resinUrl);
return form.run([
{
message: 'Email:',
name: 'email',
type: 'input',
validate: validation.validateEmail
}, {
message: 'Username:',
name: 'username',
type: 'input'
}, {
message: 'Password:',
name: 'password',
type: 'password',
validate: validation.validatePassword
}
]);
}).then(resin.auth.register).then(resin.auth.loginWithToken).nodeify(done);
}
};
exports.whoami = {
signature: 'whoami',
description: 'get current username and email address',
help: 'Use this command to find out the current logged in username and email address.\n\nExamples:\n\n $ resin whoami',
permission: 'user',
action: function(params, options, done) {
var Promise, resin, visuals;
Promise = require('bluebird');
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return Promise.props({
username: resin.auth.whoami(),
email: resin.auth.getEmail(),
url: resin.settings.get('resinUrl')
}).then(function(results) {
return console.log(visuals.table.vertical(results, ['$account information$', 'username', 'email', 'url']));
}).nodeify(done);
}
};

View File

@ -15,70 +15,66 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var _;
(function() {
var _;
_ = require('lodash');
_ = require('lodash');
exports.yes = {
signature: 'yes',
description: 'confirm non interactively',
boolean: true,
alias: 'y'
};
exports.yes = {
signature: 'yes',
description: 'confirm non interactively',
boolean: true,
alias: 'y'
};
exports.optionalApplication = {
signature: 'application',
parameter: 'application',
description: 'application name',
alias: ['a', 'app']
};
exports.optionalApplication = {
signature: 'application',
parameter: 'application',
description: 'application name',
alias: ['a', 'app']
};
exports.application = _.defaults({
required: 'You have to specify an application'
}, exports.optionalApplication);
exports.application = _.defaults({
required: 'You have to specify an application'
}, exports.optionalApplication);
exports.optionalDevice = {
signature: 'device',
parameter: 'device',
description: 'device uuid',
alias: 'd'
};
exports.optionalDevice = {
signature: 'device',
parameter: 'device',
description: 'device uuid',
alias: 'd'
};
exports.booleanDevice = {
signature: 'device',
description: 'device',
boolean: true,
alias: 'd'
};
exports.booleanDevice = {
signature: 'device',
description: 'device',
boolean: true,
alias: 'd'
};
exports.network = {
signature: 'network',
parameter: 'network',
description: 'network type',
alias: 'n'
};
exports.network = {
signature: 'network',
parameter: 'network',
description: 'network type',
alias: 'n'
};
exports.wifiSsid = {
signature: 'ssid',
parameter: 'ssid',
description: 'wifi ssid, if network is wifi',
alias: 's'
};
exports.wifiSsid = {
signature: 'ssid',
parameter: 'ssid',
description: 'wifi ssid, if network is wifi',
alias: 's'
};
exports.wifiKey = {
signature: 'key',
parameter: 'key',
description: 'wifi key, if network is wifi',
alias: 'k'
};
exports.wifiKey = {
signature: 'key',
parameter: 'key',
description: 'wifi key, if network is wifi',
alias: 'k'
};
exports.forceUpdateLock = {
signature: 'force',
description: 'force action if the update lock is set',
boolean: true,
alias: 'f'
};
}).call(this);
exports.forceUpdateLock = {
signature: 'force',
description: 'force action if the update lock is set',
boolean: true,
alias: 'f'
};

View File

@ -15,228 +15,224 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var commandOptions;
(function() {
var commandOptions;
commandOptions = require('./command-options');
commandOptions = require('./command-options');
exports.read = {
signature: 'config read',
description: 'read a device configuration',
help: 'Use this command to read the config.json file from the mounted filesystem (e.g. SD card) of a provisioned device"\n\nExamples:\n\n $ resin config read --type raspberry-pi\n $ resin config read --type raspberry-pi --drive /dev/disk2',
options: [
{
signature: 'type',
description: 'device type',
parameter: 'type',
alias: 't',
required: 'You have to specify a device type'
}, {
signature: 'drive',
description: 'drive',
parameter: 'drive',
alias: 'd'
}
],
permission: 'user',
root: true,
action: function(params, options, done) {
var Promise, config, prettyjson, umount, visuals;
Promise = require('bluebird');
config = require('resin-config-json');
visuals = require('resin-cli-visuals');
umount = Promise.promisifyAll(require('umount'));
prettyjson = require('prettyjson');
return Promise["try"](function() {
return options.drive || visuals.drive('Select the device drive');
}).tap(umount.umountAsync).then(function(drive) {
return config.read(drive, options.type);
}).tap(function(configJSON) {
return console.info(prettyjson.render(configJSON));
}).nodeify(done);
exports.read = {
signature: 'config read',
description: 'read a device configuration',
help: 'Use this command to read the config.json file from the mounted filesystem (e.g. SD card) of a provisioned device"\n\nExamples:\n\n $ resin config read --type raspberry-pi\n $ resin config read --type raspberry-pi --drive /dev/disk2',
options: [
{
signature: 'type',
description: 'device type',
parameter: 'type',
alias: 't',
required: 'You have to specify a device type'
}, {
signature: 'drive',
description: 'drive',
parameter: 'drive',
alias: 'd'
}
};
],
permission: 'user',
root: true,
action: function(params, options, done) {
var Promise, config, prettyjson, umount, visuals;
Promise = require('bluebird');
config = require('resin-config-json');
visuals = require('resin-cli-visuals');
umount = Promise.promisifyAll(require('umount'));
prettyjson = require('prettyjson');
return Promise["try"](function() {
return options.drive || visuals.drive('Select the device drive');
}).tap(umount.umountAsync).then(function(drive) {
return config.read(drive, options.type);
}).tap(function(configJSON) {
return console.info(prettyjson.render(configJSON));
}).nodeify(done);
}
};
exports.write = {
signature: 'config write <key> <value>',
description: 'write a device configuration',
help: 'Use this command to write the config.json file to the mounted filesystem (e.g. SD card) of a provisioned device\n\nExamples:\n\n $ resin config write --type raspberry-pi username johndoe\n $ resin config write --type raspberry-pi --drive /dev/disk2 username johndoe\n $ resin config write --type raspberry-pi files.network/settings "..."',
options: [
{
signature: 'type',
description: 'device type',
parameter: 'type',
alias: 't',
required: 'You have to specify a device type'
}, {
signature: 'drive',
description: 'drive',
parameter: 'drive',
alias: 'd'
}
],
permission: 'user',
root: true,
action: function(params, options, done) {
var Promise, _, config, umount, visuals;
Promise = require('bluebird');
_ = require('lodash');
config = require('resin-config-json');
visuals = require('resin-cli-visuals');
umount = Promise.promisifyAll(require('umount'));
return Promise["try"](function() {
return options.drive || visuals.drive('Select the device drive');
}).tap(umount.umountAsync).then(function(drive) {
return config.read(drive, options.type).then(function(configJSON) {
console.info("Setting " + params.key + " to " + params.value);
_.set(configJSON, params.key, params.value);
return configJSON;
}).tap(function() {
return umount.umountAsync(drive);
}).then(function(configJSON) {
return config.write(drive, options.type, configJSON);
});
exports.write = {
signature: 'config write <key> <value>',
description: 'write a device configuration',
help: 'Use this command to write the config.json file to the mounted filesystem (e.g. SD card) of a provisioned device\n\nExamples:\n\n $ resin config write --type raspberry-pi username johndoe\n $ resin config write --type raspberry-pi --drive /dev/disk2 username johndoe\n $ resin config write --type raspberry-pi files.network/settings "..."',
options: [
{
signature: 'type',
description: 'device type',
parameter: 'type',
alias: 't',
required: 'You have to specify a device type'
}, {
signature: 'drive',
description: 'drive',
parameter: 'drive',
alias: 'd'
}
],
permission: 'user',
root: true,
action: function(params, options, done) {
var Promise, _, config, umount, visuals;
Promise = require('bluebird');
_ = require('lodash');
config = require('resin-config-json');
visuals = require('resin-cli-visuals');
umount = Promise.promisifyAll(require('umount'));
return Promise["try"](function() {
return options.drive || visuals.drive('Select the device drive');
}).tap(umount.umountAsync).then(function(drive) {
return config.read(drive, options.type).then(function(configJSON) {
console.info("Setting " + params.key + " to " + params.value);
_.set(configJSON, params.key, params.value);
return configJSON;
}).tap(function() {
return console.info('Done');
}).nodeify(done);
}
};
return umount.umountAsync(drive);
}).then(function(configJSON) {
return config.write(drive, options.type, configJSON);
});
}).tap(function() {
return console.info('Done');
}).nodeify(done);
}
};
exports.inject = {
signature: 'config inject <file>',
description: 'inject a device configuration file',
help: 'Use this command to inject a config.json file to the mounted filesystem (e.g. SD card) of a provisioned device"\n\nExamples:\n\n $ resin config inject my/config.json --type raspberry-pi\n $ resin config inject my/config.json --type raspberry-pi --drive /dev/disk2',
options: [
{
signature: 'type',
description: 'device type',
parameter: 'type',
alias: 't',
required: 'You have to specify a device type'
}, {
signature: 'drive',
description: 'drive',
parameter: 'drive',
alias: 'd'
}
],
permission: 'user',
root: true,
action: function(params, options, done) {
var Promise, config, fs, umount, visuals;
Promise = require('bluebird');
config = require('resin-config-json');
visuals = require('resin-cli-visuals');
umount = Promise.promisifyAll(require('umount'));
fs = Promise.promisifyAll(require('fs'));
return Promise["try"](function() {
return options.drive || visuals.drive('Select the device drive');
}).tap(umount.umountAsync).then(function(drive) {
return fs.readFileAsync(params.file, 'utf8').then(JSON.parse).then(function(configJSON) {
return config.write(drive, options.type, configJSON);
});
}).tap(function() {
return console.info('Done');
}).nodeify(done);
exports.inject = {
signature: 'config inject <file>',
description: 'inject a device configuration file',
help: 'Use this command to inject a config.json file to the mounted filesystem (e.g. SD card) of a provisioned device"\n\nExamples:\n\n $ resin config inject my/config.json --type raspberry-pi\n $ resin config inject my/config.json --type raspberry-pi --drive /dev/disk2',
options: [
{
signature: 'type',
description: 'device type',
parameter: 'type',
alias: 't',
required: 'You have to specify a device type'
}, {
signature: 'drive',
description: 'drive',
parameter: 'drive',
alias: 'd'
}
};
],
permission: 'user',
root: true,
action: function(params, options, done) {
var Promise, config, fs, umount, visuals;
Promise = require('bluebird');
config = require('resin-config-json');
visuals = require('resin-cli-visuals');
umount = Promise.promisifyAll(require('umount'));
fs = Promise.promisifyAll(require('fs'));
return Promise["try"](function() {
return options.drive || visuals.drive('Select the device drive');
}).tap(umount.umountAsync).then(function(drive) {
return fs.readFileAsync(params.file, 'utf8').then(JSON.parse).then(function(configJSON) {
return config.write(drive, options.type, configJSON);
});
}).tap(function() {
return console.info('Done');
}).nodeify(done);
}
};
exports.reconfigure = {
signature: 'config reconfigure',
description: 'reconfigure a provisioned device',
help: 'Use this command to reconfigure a provisioned device\n\nExamples:\n\n $ resin config reconfigure --type raspberry-pi\n $ resin config reconfigure --type raspberry-pi --advanced\n $ resin config reconfigure --type raspberry-pi --drive /dev/disk2',
options: [
{
signature: 'type',
description: 'device type',
parameter: 'type',
alias: 't',
required: 'You have to specify a device type'
}, {
signature: 'drive',
description: 'drive',
parameter: 'drive',
alias: 'd'
}, {
signature: 'advanced',
description: 'show advanced commands',
boolean: true,
alias: 'v'
}
],
permission: 'user',
root: true,
action: function(params, options, done) {
var Promise, capitano, config, umount, visuals;
Promise = require('bluebird');
config = require('resin-config-json');
visuals = require('resin-cli-visuals');
capitano = Promise.promisifyAll(require('capitano'));
umount = Promise.promisifyAll(require('umount'));
return Promise["try"](function() {
return options.drive || visuals.drive('Select the device drive');
}).tap(umount.umountAsync).then(function(drive) {
return config.read(drive, options.type).get('uuid').tap(function() {
return umount.umountAsync(drive);
}).then(function(uuid) {
var configureCommand;
configureCommand = "os configure " + drive + " " + uuid;
if (options.advanced) {
configureCommand += ' --advanced';
}
return capitano.runAsync(configureCommand);
});
}).then(function() {
return console.info('Done');
}).nodeify(done);
exports.reconfigure = {
signature: 'config reconfigure',
description: 'reconfigure a provisioned device',
help: 'Use this command to reconfigure a provisioned device\n\nExamples:\n\n $ resin config reconfigure --type raspberry-pi\n $ resin config reconfigure --type raspberry-pi --advanced\n $ resin config reconfigure --type raspberry-pi --drive /dev/disk2',
options: [
{
signature: 'type',
description: 'device type',
parameter: 'type',
alias: 't',
required: 'You have to specify a device type'
}, {
signature: 'drive',
description: 'drive',
parameter: 'drive',
alias: 'd'
}, {
signature: 'advanced',
description: 'show advanced commands',
boolean: true,
alias: 'v'
}
};
exports.generate = {
signature: 'config generate',
description: 'generate a config.json file',
help: 'Use this command to generate a config.json for a device or application\n\nExamples:\n\n $ resin config generate --device 7cf02a6\n $ resin config generate --device 7cf02a6 --output config.json\n $ resin config generate --app MyApp\n $ resin config generate --app MyApp --output config.json',
options: [
commandOptions.optionalApplication, commandOptions.optionalDevice, {
signature: 'output',
description: 'output',
parameter: 'output',
alias: 'o'
}
],
permission: 'user',
action: function(params, options, done) {
var Promise, _, deviceConfig, form, fs, prettyjson, resin;
Promise = require('bluebird');
fs = Promise.promisifyAll(require('fs'));
resin = require('resin-sdk-preconfigured');
_ = require('lodash');
form = require('resin-cli-form');
deviceConfig = require('resin-device-config');
prettyjson = require('prettyjson');
if ((options.device == null) && (options.application == null)) {
throw new Error('You have to pass either a device or an application.\n\nSee the help page for examples:\n\n $ resin help config generate');
}
return Promise["try"](function() {
if (options.device != null) {
return resin.models.device.get(options.device);
],
permission: 'user',
root: true,
action: function(params, options, done) {
var Promise, capitano, config, umount, visuals;
Promise = require('bluebird');
config = require('resin-config-json');
visuals = require('resin-cli-visuals');
capitano = Promise.promisifyAll(require('capitano'));
umount = Promise.promisifyAll(require('umount'));
return Promise["try"](function() {
return options.drive || visuals.drive('Select the device drive');
}).tap(umount.umountAsync).then(function(drive) {
return config.read(drive, options.type).get('uuid').tap(function() {
return umount.umountAsync(drive);
}).then(function(uuid) {
var configureCommand;
configureCommand = "os configure " + drive + " " + uuid;
if (options.advanced) {
configureCommand += ' --advanced';
}
return resin.models.application.get(options.application);
}).then(function(resource) {
return resin.models.device.getManifestBySlug(resource.device_type).get('options').then(form.run).then(function(answers) {
if (resource.uuid != null) {
return deviceConfig.getByDevice(resource.uuid, answers);
}
return deviceConfig.getByApplication(resource.app_name, answers);
});
}).then(function(config) {
if (options.output != null) {
return fs.writeFileAsync(options.output, JSON.stringify(config));
}
return console.log(prettyjson.render(config));
}).nodeify(done);
}
};
return capitano.runAsync(configureCommand);
});
}).then(function() {
return console.info('Done');
}).nodeify(done);
}
};
}).call(this);
exports.generate = {
signature: 'config generate',
description: 'generate a config.json file',
help: 'Use this command to generate a config.json for a device or application\n\nExamples:\n\n $ resin config generate --device 7cf02a6\n $ resin config generate --device 7cf02a6 --output config.json\n $ resin config generate --app MyApp\n $ resin config generate --app MyApp --output config.json',
options: [
commandOptions.optionalApplication, commandOptions.optionalDevice, {
signature: 'output',
description: 'output',
parameter: 'output',
alias: 'o'
}
],
permission: 'user',
action: function(params, options, done) {
var Promise, _, deviceConfig, form, fs, prettyjson, resin;
Promise = require('bluebird');
fs = Promise.promisifyAll(require('fs'));
resin = require('resin-sdk-preconfigured');
_ = require('lodash');
form = require('resin-cli-form');
deviceConfig = require('resin-device-config');
prettyjson = require('prettyjson');
if ((options.device == null) && (options.application == null)) {
throw new Error('You have to pass either a device or an application.\n\nSee the help page for examples:\n\n $ resin help config generate');
}
return Promise["try"](function() {
if (options.device != null) {
return resin.models.device.get(options.device);
}
return resin.models.application.get(options.application);
}).then(function(resource) {
return resin.models.device.getManifestBySlug(resource.device_type).get('options').then(form.run).then(function(answers) {
if (resource.uuid != null) {
return deviceConfig.getByDevice(resource.uuid, answers);
}
return deviceConfig.getByApplication(resource.app_name, answers);
});
}).then(function(config) {
if (options.output != null) {
return fs.writeFileAsync(options.output, JSON.stringify(config));
}
return console.log(prettyjson.render(config));
}).nodeify(done);
}
};

View File

@ -15,313 +15,309 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var commandOptions;
(function() {
var commandOptions;
commandOptions = require('./command-options');
commandOptions = require('./command-options');
exports.list = {
signature: 'devices',
description: 'list all devices',
help: 'Use this command to list all devices that belong to you.\n\nYou can filter the devices by application by using the `--application` option.\n\nExamples:\n\n $ resin devices\n $ resin devices --application MyApp\n $ resin devices --app MyApp\n $ resin devices -a MyApp',
options: [commandOptions.optionalApplication],
permission: 'user',
primary: true,
action: function(params, options, done) {
var Promise, _, resin, visuals;
Promise = require('bluebird');
_ = require('lodash');
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return Promise["try"](function() {
if (options.application != null) {
return resin.models.device.getAllByApplication(options.application);
}
return resin.models.device.getAll();
}).tap(function(devices) {
devices = _.map(devices, function(device) {
device.uuid = device.uuid.slice(0, 7);
return device;
});
return console.log(visuals.table.horizontal(devices, ['id', 'uuid', 'name', 'device_type', 'application_name', 'status', 'is_online', 'supervisor_version', 'os_version']));
}).nodeify(done);
}
};
exports.info = {
signature: 'device <uuid>',
description: 'list a single device',
help: 'Use this command to show information about a single device.\n\nExamples:\n\n $ resin device 7cf02a6',
permission: 'user',
primary: true,
action: function(params, options, done) {
var resin, visuals;
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return resin.models.device.get(params.uuid).then(function(device) {
return resin.models.device.getStatus(device).then(function(status) {
device.status = status;
return console.log(visuals.table.vertical(device, ["$" + device.name + "$", 'id', 'device_type', 'status', 'is_online', 'ip_address', 'application_name', 'last_seen', 'uuid', 'commit', 'supervisor_version', 'is_web_accessible', 'note', 'os_version']));
});
}).nodeify(done);
}
};
exports.supported = {
signature: 'devices supported',
description: 'list all supported devices',
help: 'Use this command to get the list of all supported devices\n\nExamples:\n\n $ resin devices supported',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.config.getDeviceTypes().each(function(deviceType) {
return console.log(deviceType.slug);
}).nodeify(done);
}
};
exports.register = {
signature: 'device register <application>',
description: 'register a device',
help: 'Use this command to register a device to an application.\n\nExamples:\n\n $ resin device register MyApp',
permission: 'user',
options: [
{
signature: 'uuid',
description: 'custom uuid',
parameter: 'uuid',
alias: 'u'
exports.list = {
signature: 'devices',
description: 'list all devices',
help: 'Use this command to list all devices that belong to you.\n\nYou can filter the devices by application by using the `--application` option.\n\nExamples:\n\n $ resin devices\n $ resin devices --application MyApp\n $ resin devices --app MyApp\n $ resin devices -a MyApp',
options: [commandOptions.optionalApplication],
permission: 'user',
primary: true,
action: function(params, options, done) {
var Promise, _, resin, visuals;
Promise = require('bluebird');
_ = require('lodash');
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return Promise["try"](function() {
if (options.application != null) {
return resin.models.device.getAllByApplication(options.application);
}
],
action: function(params, options, done) {
var Promise, resin;
Promise = require('bluebird');
resin = require('resin-sdk-preconfigured');
return resin.models.application.get(params.application).then(function(application) {
return Promise["try"](function() {
return options.uuid || resin.models.device.generateUniqueKey();
}).then(function(uuid) {
console.info("Registering to " + application.app_name + ": " + uuid);
return resin.models.device.register(application.app_name, uuid);
});
}).get('uuid').nodeify(done);
}
};
return resin.models.device.getAll();
}).tap(function(devices) {
devices = _.map(devices, function(device) {
device.uuid = device.uuid.slice(0, 7);
return device;
});
return console.log(visuals.table.horizontal(devices, ['id', 'uuid', 'name', 'device_type', 'application_name', 'status', 'is_online', 'supervisor_version', 'os_version']));
}).nodeify(done);
}
};
exports.remove = {
signature: 'device rm <uuid>',
description: 'remove a device',
help: 'Use this command to remove a device from resin.io.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin device rm 7cf02a6\n $ resin device rm 7cf02a6 --yes',
options: [commandOptions.yes],
permission: 'user',
action: function(params, options, done) {
var patterns, resin;
resin = require('resin-sdk-preconfigured');
patterns = require('../utils/patterns');
return patterns.confirm(options.yes, 'Are you sure you want to delete the device?').then(function() {
return resin.models.device.remove(params.uuid);
}).nodeify(done);
}
};
exports.info = {
signature: 'device <uuid>',
description: 'list a single device',
help: 'Use this command to show information about a single device.\n\nExamples:\n\n $ resin device 7cf02a6',
permission: 'user',
primary: true,
action: function(params, options, done) {
var resin, visuals;
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return resin.models.device.get(params.uuid).then(function(device) {
return resin.models.device.getStatus(device).then(function(status) {
device.status = status;
return console.log(visuals.table.vertical(device, ["$" + device.name + "$", 'id', 'device_type', 'status', 'is_online', 'ip_address', 'application_name', 'last_seen', 'uuid', 'commit', 'supervisor_version', 'is_web_accessible', 'note', 'os_version']));
});
}).nodeify(done);
}
};
exports.identify = {
signature: 'device identify <uuid>',
description: 'identify a device with a UUID',
help: 'Use this command to identify a device.\n\nIn the Raspberry Pi, the ACT led is blinked several times.\n\nExamples:\n\n $ resin device identify 23c73a1',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.identify(params.uuid).nodeify(done);
}
};
exports.supported = {
signature: 'devices supported',
description: 'list all supported devices',
help: 'Use this command to get the list of all supported devices\n\nExamples:\n\n $ resin devices supported',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.config.getDeviceTypes().each(function(deviceType) {
return console.log(deviceType.slug);
}).nodeify(done);
}
};
exports.reboot = {
signature: 'device reboot <uuid>',
description: 'restart a device',
help: 'Use this command to remotely reboot a device\n\nExamples:\n\n $ resin device reboot 23c73a1',
options: [commandOptions.forceUpdateLock],
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.reboot(params.uuid, options).nodeify(done);
exports.register = {
signature: 'device register <application>',
description: 'register a device',
help: 'Use this command to register a device to an application.\n\nExamples:\n\n $ resin device register MyApp',
permission: 'user',
options: [
{
signature: 'uuid',
description: 'custom uuid',
parameter: 'uuid',
alias: 'u'
}
};
exports.shutdown = {
signature: 'device shutdown <uuid>',
description: 'shutdown a device',
help: 'Use this command to remotely shutdown a device\n\nExamples:\n\n $ resin device shutdown 23c73a1',
options: [commandOptions.forceUpdateLock],
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.shutdown(params.uuid, options).nodeify(done);
}
};
exports.enableDeviceUrl = {
signature: 'device public-url enable <uuid>',
description: 'enable public URL for a device',
help: 'Use this command to enable public URL for a device\n\nExamples:\n\n $ resin device public-url enable 23c73a1',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.enableDeviceUrl(params.uuid).nodeify(done);
}
};
exports.disableDeviceUrl = {
signature: 'device public-url disable <uuid>',
description: 'disable public URL for a device',
help: 'Use this command to disable public URL for a device\n\nExamples:\n\n $ resin device public-url disable 23c73a1',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.disableDeviceUrl(params.uuid).nodeify(done);
}
};
exports.getDeviceUrl = {
signature: 'device public-url <uuid>',
description: 'gets the public URL of a device',
help: 'Use this command to get the public URL of a device\n\nExamples:\n\n $ resin device public-url 23c73a1',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.getDeviceUrl(params.uuid).then(function(url) {
return console.log(url);
}).nodeify(done);
}
};
exports.hasDeviceUrl = {
signature: 'device public-url status <uuid>',
description: 'Returns true if public URL is enabled for a device',
help: 'Use this command to determine if public URL is enabled for a device\n\nExamples:\n\n $ resin device public-url status 23c73a1',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.hasDeviceUrl(params.uuid).then(function(hasDeviceUrl) {
return console.log(hasDeviceUrl);
}).nodeify(done);
}
};
exports.rename = {
signature: 'device rename <uuid> [newName]',
description: 'rename a resin device',
help: 'Use this command to rename a device.\n\nIf you omit the name, you\'ll get asked for it interactively.\n\nExamples:\n\n $ resin device rename 7cf02a6\n $ resin device rename 7cf02a6 MyPi',
permission: 'user',
action: function(params, options, done) {
var Promise, _, form, resin;
Promise = require('bluebird');
_ = require('lodash');
resin = require('resin-sdk-preconfigured');
form = require('resin-cli-form');
],
action: function(params, options, done) {
var Promise, resin;
Promise = require('bluebird');
resin = require('resin-sdk-preconfigured');
return resin.models.application.get(params.application).then(function(application) {
return Promise["try"](function() {
if (!_.isEmpty(params.newName)) {
return params.newName;
}
return form.ask({
message: 'How do you want to name this device?',
type: 'input'
});
}).then(_.partial(resin.models.device.rename, params.uuid)).nodeify(done);
}
};
return options.uuid || resin.models.device.generateUniqueKey();
}).then(function(uuid) {
console.info("Registering to " + application.app_name + ": " + uuid);
return resin.models.device.register(application.app_name, uuid);
});
}).get('uuid').nodeify(done);
}
};
exports.move = {
signature: 'device move <uuid>',
description: 'move a device to another application',
help: 'Use this command to move a device to another application you own.\n\nIf you omit the application, you\'ll get asked for it interactively.\n\nExamples:\n\n $ resin device move 7cf02a6\n $ resin device move 7cf02a6 --application MyNewApp',
permission: 'user',
options: [commandOptions.optionalApplication],
action: function(params, options, done) {
var _, patterns, resin;
resin = require('resin-sdk-preconfigured');
_ = require('lodash');
patterns = require('../utils/patterns');
return resin.models.device.get(params.uuid).then(function(device) {
return options.application || patterns.selectApplication(function(application) {
return _.all([application.device_type === device.device_type, device.application_name !== application.app_name]);
});
}).tap(function(application) {
return resin.models.device.move(params.uuid, application);
}).then(function(application) {
return console.info(params.uuid + " was moved to " + application);
}).nodeify(done);
}
};
exports.remove = {
signature: 'device rm <uuid>',
description: 'remove a device',
help: 'Use this command to remove a device from resin.io.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin device rm 7cf02a6\n $ resin device rm 7cf02a6 --yes',
options: [commandOptions.yes],
permission: 'user',
action: function(params, options, done) {
var patterns, resin;
resin = require('resin-sdk-preconfigured');
patterns = require('../utils/patterns');
return patterns.confirm(options.yes, 'Are you sure you want to delete the device?').then(function() {
return resin.models.device.remove(params.uuid);
}).nodeify(done);
}
};
exports.init = {
signature: 'device init',
description: 'initialise a device with resin os',
help: 'Use this command to download the OS image of a certain application and write it to an SD Card.\n\nNotice this command may ask for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin device init\n $ resin device init --application MyApp',
options: [
commandOptions.optionalApplication, commandOptions.yes, {
signature: 'advanced',
description: 'enable advanced configuration',
boolean: true,
alias: 'v'
exports.identify = {
signature: 'device identify <uuid>',
description: 'identify a device with a UUID',
help: 'Use this command to identify a device.\n\nIn the Raspberry Pi, the ACT led is blinked several times.\n\nExamples:\n\n $ resin device identify 23c73a1',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.identify(params.uuid).nodeify(done);
}
};
exports.reboot = {
signature: 'device reboot <uuid>',
description: 'restart a device',
help: 'Use this command to remotely reboot a device\n\nExamples:\n\n $ resin device reboot 23c73a1',
options: [commandOptions.forceUpdateLock],
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.reboot(params.uuid, options).nodeify(done);
}
};
exports.shutdown = {
signature: 'device shutdown <uuid>',
description: 'shutdown a device',
help: 'Use this command to remotely shutdown a device\n\nExamples:\n\n $ resin device shutdown 23c73a1',
options: [commandOptions.forceUpdateLock],
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.shutdown(params.uuid, options).nodeify(done);
}
};
exports.enableDeviceUrl = {
signature: 'device public-url enable <uuid>',
description: 'enable public URL for a device',
help: 'Use this command to enable public URL for a device\n\nExamples:\n\n $ resin device public-url enable 23c73a1',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.enableDeviceUrl(params.uuid).nodeify(done);
}
};
exports.disableDeviceUrl = {
signature: 'device public-url disable <uuid>',
description: 'disable public URL for a device',
help: 'Use this command to disable public URL for a device\n\nExamples:\n\n $ resin device public-url disable 23c73a1',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.disableDeviceUrl(params.uuid).nodeify(done);
}
};
exports.getDeviceUrl = {
signature: 'device public-url <uuid>',
description: 'gets the public URL of a device',
help: 'Use this command to get the public URL of a device\n\nExamples:\n\n $ resin device public-url 23c73a1',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.getDeviceUrl(params.uuid).then(function(url) {
return console.log(url);
}).nodeify(done);
}
};
exports.hasDeviceUrl = {
signature: 'device public-url status <uuid>',
description: 'Returns true if public URL is enabled for a device',
help: 'Use this command to determine if public URL is enabled for a device\n\nExamples:\n\n $ resin device public-url status 23c73a1',
permission: 'user',
action: function(params, options, done) {
var resin;
resin = require('resin-sdk-preconfigured');
return resin.models.device.hasDeviceUrl(params.uuid).then(function(hasDeviceUrl) {
return console.log(hasDeviceUrl);
}).nodeify(done);
}
};
exports.rename = {
signature: 'device rename <uuid> [newName]',
description: 'rename a resin device',
help: 'Use this command to rename a device.\n\nIf you omit the name, you\'ll get asked for it interactively.\n\nExamples:\n\n $ resin device rename 7cf02a6\n $ resin device rename 7cf02a6 MyPi',
permission: 'user',
action: function(params, options, done) {
var Promise, _, form, resin;
Promise = require('bluebird');
_ = require('lodash');
resin = require('resin-sdk-preconfigured');
form = require('resin-cli-form');
return Promise["try"](function() {
if (!_.isEmpty(params.newName)) {
return params.newName;
}
],
permission: 'user',
action: function(params, options, done) {
var Promise, capitano, helpers, patterns, resin, rimraf, tmp;
Promise = require('bluebird');
capitano = Promise.promisifyAll(require('capitano'));
rimraf = Promise.promisify(require('rimraf'));
tmp = Promise.promisifyAll(require('tmp'));
tmp.setGracefulCleanup();
resin = require('resin-sdk-preconfigured');
helpers = require('../utils/helpers');
patterns = require('../utils/patterns');
return Promise["try"](function() {
if (options.application != null) {
return options.application;
}
return patterns.selectApplication();
}).then(resin.models.application.get).then(function(application) {
var download;
download = function() {
return tmp.tmpNameAsync().then(function(temporalPath) {
return capitano.runAsync("os download " + application.device_type + " --output " + temporalPath);
}).disposer(function(temporalPath) {
return rimraf(temporalPath);
});
};
return Promise.using(download(), function(temporalPath) {
return capitano.runAsync("device register " + application.app_name).then(resin.models.device.get).tap(function(device) {
var configure;
configure = "os configure " + temporalPath + " " + device.uuid;
if (options.advanced) {
configure += ' --advanced';
}
return capitano.runAsync(configure).then(function() {
var message;
message = 'Initializing a device requires administrative permissions\ngiven that we need to access raw devices directly.\n';
return helpers.sudo(['os', 'initialize', temporalPath, '--type', application.device_type], message);
})["catch"](function(error) {
return resin.models.device.remove(device.uuid)["finally"](function() {
throw error;
});
return form.ask({
message: 'How do you want to name this device?',
type: 'input'
});
}).then(_.partial(resin.models.device.rename, params.uuid)).nodeify(done);
}
};
exports.move = {
signature: 'device move <uuid>',
description: 'move a device to another application',
help: 'Use this command to move a device to another application you own.\n\nIf you omit the application, you\'ll get asked for it interactively.\n\nExamples:\n\n $ resin device move 7cf02a6\n $ resin device move 7cf02a6 --application MyNewApp',
permission: 'user',
options: [commandOptions.optionalApplication],
action: function(params, options, done) {
var _, patterns, resin;
resin = require('resin-sdk-preconfigured');
_ = require('lodash');
patterns = require('../utils/patterns');
return resin.models.device.get(params.uuid).then(function(device) {
return options.application || patterns.selectApplication(function(application) {
return _.all([application.device_type === device.device_type, device.application_name !== application.app_name]);
});
}).tap(function(application) {
return resin.models.device.move(params.uuid, application);
}).then(function(application) {
return console.info(params.uuid + " was moved to " + application);
}).nodeify(done);
}
};
exports.init = {
signature: 'device init',
description: 'initialise a device with resin os',
help: 'Use this command to download the OS image of a certain application and write it to an SD Card.\n\nNotice this command may ask for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin device init\n $ resin device init --application MyApp',
options: [
commandOptions.optionalApplication, commandOptions.yes, {
signature: 'advanced',
description: 'enable advanced configuration',
boolean: true,
alias: 'v'
}
],
permission: 'user',
action: function(params, options, done) {
var Promise, capitano, helpers, patterns, resin, rimraf, tmp;
Promise = require('bluebird');
capitano = Promise.promisifyAll(require('capitano'));
rimraf = Promise.promisify(require('rimraf'));
tmp = Promise.promisifyAll(require('tmp'));
tmp.setGracefulCleanup();
resin = require('resin-sdk-preconfigured');
helpers = require('../utils/helpers');
patterns = require('../utils/patterns');
return Promise["try"](function() {
if (options.application != null) {
return options.application;
}
return patterns.selectApplication();
}).then(resin.models.application.get).then(function(application) {
var download;
download = function() {
return tmp.tmpNameAsync().then(function(temporalPath) {
return capitano.runAsync("os download " + application.device_type + " --output " + temporalPath);
}).disposer(function(temporalPath) {
return rimraf(temporalPath);
});
};
return Promise.using(download(), function(temporalPath) {
return capitano.runAsync("device register " + application.app_name).then(resin.models.device.get).tap(function(device) {
var configure;
configure = "os configure " + temporalPath + " " + device.uuid;
if (options.advanced) {
configure += ' --advanced';
}
return capitano.runAsync(configure).then(function() {
var message;
message = 'Initializing a device requires administrative permissions\ngiven that we need to access raw devices directly.\n';
return helpers.sudo(['os', 'initialize', temporalPath, '--type', application.device_type], message);
})["catch"](function(error) {
return resin.models.device.remove(device.uuid)["finally"](function() {
throw error;
});
});
}).then(function(device) {
console.log('Done');
return device.uuid;
});
}).nodeify(done);
}
};
}).call(this);
}).then(function(device) {
console.log('Done');
return device.uuid;
});
}).nodeify(done);
}
};

View File

@ -15,121 +15,117 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var commandOptions;
(function() {
var commandOptions;
commandOptions = require('./command-options');
commandOptions = require('./command-options');
exports.list = {
signature: 'envs',
description: 'list all environment variables',
help: 'Use this command to list all environment variables for\na particular application or device.\n\nThis command lists all custom environment variables.\nIf you want to see all environment variables, including private\nones used by resin, use the verbose option.\n\nExample:\n\n $ resin envs --application MyApp\n $ resin envs --application MyApp --verbose\n $ resin envs --device 7cf02a6',
options: [
commandOptions.optionalApplication, commandOptions.optionalDevice, {
signature: 'verbose',
description: 'show private environment variables',
boolean: true,
alias: 'v'
exports.list = {
signature: 'envs',
description: 'list all environment variables',
help: 'Use this command to list all environment variables for\na particular application or device.\n\nThis command lists all custom environment variables.\nIf you want to see all environment variables, including private\nones used by resin, use the verbose option.\n\nExample:\n\n $ resin envs --application MyApp\n $ resin envs --application MyApp --verbose\n $ resin envs --device 7cf02a6',
options: [
commandOptions.optionalApplication, commandOptions.optionalDevice, {
signature: 'verbose',
description: 'show private environment variables',
boolean: true,
alias: 'v'
}
],
permission: 'user',
action: function(params, options, done) {
var Promise, _, resin, visuals;
Promise = require('bluebird');
_ = require('lodash');
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return Promise["try"](function() {
if (options.application != null) {
return resin.models.environmentVariables.getAllByApplication(options.application);
} else if (options.device != null) {
return resin.models.environmentVariables.device.getAll(options.device);
} else {
throw new Error('You must specify an application or device');
}
],
permission: 'user',
action: function(params, options, done) {
var Promise, _, resin, visuals;
Promise = require('bluebird');
_ = require('lodash');
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return Promise["try"](function() {
if (options.application != null) {
return resin.models.environmentVariables.getAllByApplication(options.application);
} else if (options.device != null) {
return resin.models.environmentVariables.device.getAll(options.device);
} else {
throw new Error('You must specify an application or device');
}
}).tap(function(environmentVariables) {
var isSystemVariable;
if (_.isEmpty(environmentVariables)) {
throw new Error('No environment variables found');
}
if (!options.verbose) {
isSystemVariable = resin.models.environmentVariables.isSystemVariable;
environmentVariables = _.reject(environmentVariables, isSystemVariable);
}
return console.log(visuals.table.horizontal(environmentVariables, ['id', 'name', 'value']));
}).nodeify(done);
}
};
}).tap(function(environmentVariables) {
var isSystemVariable;
if (_.isEmpty(environmentVariables)) {
throw new Error('No environment variables found');
}
if (!options.verbose) {
isSystemVariable = resin.models.environmentVariables.isSystemVariable;
environmentVariables = _.reject(environmentVariables, isSystemVariable);
}
return console.log(visuals.table.horizontal(environmentVariables, ['id', 'name', 'value']));
}).nodeify(done);
}
};
exports.remove = {
signature: 'env rm <id>',
description: 'remove an environment variable',
help: 'Use this command to remove an environment variable from an application.\n\nDon\'t remove resin specific variables, as things might not work as expected.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nIf you want to eliminate a device environment variable, pass the `--device` boolean option.\n\nExamples:\n\n $ resin env rm 215\n $ resin env rm 215 --yes\n $ resin env rm 215 --device',
options: [commandOptions.yes, commandOptions.booleanDevice],
permission: 'user',
action: function(params, options, done) {
var patterns, resin;
resin = require('resin-sdk-preconfigured');
patterns = require('../utils/patterns');
return patterns.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);
} else {
return resin.models.environmentVariables.remove(params.id);
}
}).nodeify(done);
}
};
exports.remove = {
signature: 'env rm <id>',
description: 'remove an environment variable',
help: 'Use this command to remove an environment variable from an application.\n\nDon\'t remove resin specific variables, as things might not work as expected.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nIf you want to eliminate a device environment variable, pass the `--device` boolean option.\n\nExamples:\n\n $ resin env rm 215\n $ resin env rm 215 --yes\n $ resin env rm 215 --device',
options: [commandOptions.yes, commandOptions.booleanDevice],
permission: 'user',
action: function(params, options, done) {
var patterns, resin;
resin = require('resin-sdk-preconfigured');
patterns = require('../utils/patterns');
return patterns.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);
} else {
return resin.models.environmentVariables.remove(params.id);
}
}).nodeify(done);
}
};
exports.add = {
signature: 'env add <key> [value]',
description: 'add an environment variable',
help: 'Use this command to add an enviroment variable to an application.\n\nIf value is omitted, the tool will attempt to use the variable\'s value\nas defined in your host machine.\n\nUse the `--device` option if you want to assign the environment variable\nto a specific device.\n\nIf the value is grabbed from the environment, a warning message will be printed.\nUse `--quiet` to remove it.\n\nExamples:\n\n $ resin env add EDITOR vim --application MyApp\n $ resin env add TERM --application MyApp\n $ resin env add EDITOR vim --device 7cf02a6',
options: [commandOptions.optionalApplication, commandOptions.optionalDevice],
permission: 'user',
action: function(params, options, done) {
var Promise, resin;
Promise = require('bluebird');
resin = require('resin-sdk-preconfigured');
return Promise["try"](function() {
exports.add = {
signature: 'env add <key> [value]',
description: 'add an environment variable',
help: 'Use this command to add an enviroment variable to an application.\n\nIf value is omitted, the tool will attempt to use the variable\'s value\nas defined in your host machine.\n\nUse the `--device` option if you want to assign the environment variable\nto a specific device.\n\nIf the value is grabbed from the environment, a warning message will be printed.\nUse `--quiet` to remove it.\n\nExamples:\n\n $ resin env add EDITOR vim --application MyApp\n $ resin env add TERM --application MyApp\n $ resin env add EDITOR vim --device 7cf02a6',
options: [commandOptions.optionalApplication, commandOptions.optionalDevice],
permission: 'user',
action: function(params, options, done) {
var Promise, resin;
Promise = require('bluebird');
resin = require('resin-sdk-preconfigured');
return Promise["try"](function() {
if (params.value == null) {
params.value = process.env[params.key];
if (params.value == null) {
params.value = process.env[params.key];
if (params.value == null) {
throw new Error("Environment value not found for key: " + params.key);
} else {
console.info("Warning: using " + params.key + "=" + params.value + " from host environment");
}
}
if (options.application != null) {
return resin.models.environmentVariables.create(options.application, params.key, params.value);
} else if (options.device != null) {
return resin.models.environmentVariables.device.create(options.device, params.key, params.value);
throw new Error("Environment value not found for key: " + params.key);
} else {
throw new Error('You must specify an application or device');
console.info("Warning: using " + params.key + "=" + params.value + " from host environment");
}
}).nodeify(done);
}
};
}
if (options.application != null) {
return resin.models.environmentVariables.create(options.application, params.key, params.value);
} else if (options.device != null) {
return resin.models.environmentVariables.device.create(options.device, params.key, params.value);
} else {
throw new Error('You must specify an application or device');
}
}).nodeify(done);
}
};
exports.rename = {
signature: 'env rename <id> <value>',
description: 'rename an environment variable',
help: 'Use this command to rename an enviroment variable from an application.\n\nPass the `--device` boolean option if you want to rename a device environment variable.\n\nExamples:\n\n $ resin env rename 376 emacs\n $ resin env rename 376 emacs --device',
permission: 'user',
options: [commandOptions.booleanDevice],
action: function(params, options, done) {
var Promise, resin;
Promise = require('bluebird');
resin = require('resin-sdk-preconfigured');
return Promise["try"](function() {
if (options.device) {
return resin.models.environmentVariables.device.update(params.id, params.value);
} else {
return resin.models.environmentVariables.update(params.id, params.value);
}
}).nodeify(done);
}
};
}).call(this);
exports.rename = {
signature: 'env rename <id> <value>',
description: 'rename an environment variable',
help: 'Use this command to rename an enviroment variable from an application.\n\nPass the `--device` boolean option if you want to rename a device environment variable.\n\nExamples:\n\n $ resin env rename 376 emacs\n $ resin env rename 376 emacs --device',
permission: 'user',
options: [commandOptions.booleanDevice],
action: function(params, options, done) {
var Promise, resin;
Promise = require('bluebird');
resin = require('resin-sdk-preconfigured');
return Promise["try"](function() {
if (options.device) {
return resin.models.environmentVariables.device.update(params.id, params.value);
} else {
return resin.models.environmentVariables.update(params.id, params.value);
}
}).nodeify(done);
}
};

View File

@ -15,123 +15,119 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var _, capitano, columnify, command, general, indent, messages, parse, print;
(function() {
var _, capitano, columnify, command, general, indent, messages, parse, print;
_ = require('lodash');
_ = require('lodash');
_.str = require('underscore.string');
_.str = require('underscore.string');
capitano = require('capitano');
capitano = require('capitano');
columnify = require('columnify');
columnify = require('columnify');
messages = require('../utils/messages');
messages = require('../utils/messages');
parse = function(object) {
return _.object(_.map(object, function(item) {
var signature;
if (item.alias != null) {
signature = item.toString();
} else {
signature = item.signature.toString();
}
return [signature, item.description];
}));
};
indent = function(text) {
text = _.map(_.str.lines(text), function(line) {
return ' ' + line;
});
return text.join('\n');
};
print = function(data) {
return console.log(indent(columnify(data, {
showHeaders: false,
minWidth: 35
})));
};
general = function(params, options, done) {
var commands, groupedCommands;
console.log('Usage: resin [COMMAND] [OPTIONS]\n');
console.log(messages.gettingStarted + "\n");
console.log(messages.reachingOut);
console.log('\nPrimary commands:\n');
commands = _.reject(capitano.state.commands, function(command) {
return command.isWildcard();
});
groupedCommands = _.groupBy(commands, function(command) {
if (command.plugin) {
return 'plugins';
} else if (command.primary) {
return 'primary';
}
return 'secondary';
});
print(parse(groupedCommands.primary));
if (options.verbose) {
if (!_.isEmpty(groupedCommands.plugins)) {
console.log('\nInstalled plugins:\n');
print(parse(groupedCommands.plugins));
}
console.log('\nAdditional commands:\n');
print(parse(groupedCommands.secondary));
parse = function(object) {
return _.object(_.map(object, function(item) {
var signature;
if (item.alias != null) {
signature = item.toString();
} else {
console.log('\nRun `resin help --verbose` to list additional commands');
signature = item.signature.toString();
}
if (!_.isEmpty(capitano.state.globalOptions)) {
console.log('\nGlobal Options:\n');
print(parse(capitano.state.globalOptions));
return [signature, item.description];
}));
};
indent = function(text) {
text = _.map(_.str.lines(text), function(line) {
return ' ' + line;
});
return text.join('\n');
};
print = function(data) {
return console.log(indent(columnify(data, {
showHeaders: false,
minWidth: 35
})));
};
general = function(params, options, done) {
var commands, groupedCommands;
console.log('Usage: resin [COMMAND] [OPTIONS]\n');
console.log(messages.gettingStarted + "\n");
console.log(messages.reachingOut);
console.log('\nPrimary commands:\n');
commands = _.reject(capitano.state.commands, function(command) {
return command.isWildcard();
});
groupedCommands = _.groupBy(commands, function(command) {
if (command.plugin) {
return 'plugins';
} else if (command.primary) {
return 'primary';
}
return 'secondary';
});
print(parse(groupedCommands.primary));
if (options.verbose) {
if (!_.isEmpty(groupedCommands.plugins)) {
console.log('\nInstalled plugins:\n');
print(parse(groupedCommands.plugins));
}
console.log('\nAdditional commands:\n');
print(parse(groupedCommands.secondary));
} else {
console.log('\nRun `resin help --verbose` to list additional commands');
}
if (!_.isEmpty(capitano.state.globalOptions)) {
console.log('\nGlobal Options:\n');
print(parse(capitano.state.globalOptions));
}
return done();
};
command = function(params, options, done) {
return capitano.state.getMatchCommand(params.command, function(error, command) {
if (error != null) {
return done(error);
}
if ((command == null) || command.isWildcard()) {
return done(new Error("Command not found: " + params.command));
}
console.log("Usage: " + command.signature);
if (command.help != null) {
console.log("\n" + command.help);
} else if (command.description != null) {
console.log("\n" + (_.str.humanize(command.description)));
}
if (!_.isEmpty(command.options)) {
console.log('\nOptions:\n');
print(parse(command.options));
}
return done();
};
});
};
command = function(params, options, done) {
return capitano.state.getMatchCommand(params.command, function(error, command) {
if (error != null) {
return done(error);
}
if ((command == null) || command.isWildcard()) {
return done(new Error("Command not found: " + params.command));
}
console.log("Usage: " + command.signature);
if (command.help != null) {
console.log("\n" + command.help);
} else if (command.description != null) {
console.log("\n" + (_.str.humanize(command.description)));
}
if (!_.isEmpty(command.options)) {
console.log('\nOptions:\n');
print(parse(command.options));
}
return done();
});
};
exports.help = {
signature: 'help [command...]',
description: 'show help',
help: 'Get detailed help for an specific command.\n\nExamples:\n\n $ resin help apps\n $ resin help os download',
primary: true,
options: [
{
signature: 'verbose',
description: 'show additional commands',
boolean: true,
alias: 'v'
}
],
action: function(params, options, done) {
if (params.command != null) {
return command(params, options, done);
} else {
return general(params, options, done);
}
exports.help = {
signature: 'help [command...]',
description: 'show help',
help: 'Get detailed help for an specific command.\n\nExamples:\n\n $ resin help apps\n $ resin help os download',
primary: true,
options: [
{
signature: 'verbose',
description: 'show additional commands',
boolean: true,
alias: 'v'
}
};
}).call(this);
],
action: function(params, options, done) {
if (params.command != null) {
return command(params, options, done);
} else {
return general(params, options, done);
}
}
};

View File

@ -15,25 +15,21 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function() {
module.exports = {
wizard: require('./wizard'),
app: require('./app'),
info: require('./info'),
auth: require('./auth'),
device: require('./device'),
env: require('./environment-variables'),
keys: require('./keys'),
logs: require('./logs'),
local: require('./local'),
notes: require('./notes'),
help: require('./help'),
os: require('./os'),
settings: require('./settings'),
config: require('./config'),
sync: require('./sync'),
ssh: require('./ssh')
};
}).call(this);
module.exports = {
wizard: require('./wizard'),
app: require('./app'),
info: require('./info'),
auth: require('./auth'),
device: require('./device'),
env: require('./environment-variables'),
keys: require('./keys'),
logs: require('./logs'),
local: require('./local'),
notes: require('./notes'),
help: require('./help'),
os: require('./os'),
settings: require('./settings'),
config: require('./config'),
sync: require('./sync'),
ssh: require('./ssh')
};

View File

@ -15,18 +15,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function() {
exports.version = {
signature: 'version',
description: 'output the version number',
help: 'Display the Resin CLI version.',
action: function(params, options, done) {
var packageJSON;
packageJSON = require('../../package.json');
console.log(packageJSON.version);
return done();
}
};
}).call(this);
exports.version = {
signature: 'version',
description: 'output the version number',
help: 'Display the Resin CLI version.',
action: function(params, options, done) {
var packageJSON;
packageJSON = require('../../package.json');
console.log(packageJSON.version);
return done();
}
};

View File

@ -15,84 +15,80 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var commandOptions;
(function() {
var commandOptions;
commandOptions = require('./command-options');
commandOptions = require('./command-options');
exports.list = {
signature: 'keys',
description: 'list all ssh keys',
help: 'Use this command to list all your SSH keys.\n\nExamples:\n\n $ resin keys',
permission: 'user',
action: function(params, options, done) {
var resin, visuals;
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return resin.models.key.getAll().then(function(keys) {
return console.log(visuals.table.horizontal(keys, ['id', 'title']));
}).nodeify(done);
}
};
exports.list = {
signature: 'keys',
description: 'list all ssh keys',
help: 'Use this command to list all your SSH keys.\n\nExamples:\n\n $ resin keys',
permission: 'user',
action: function(params, options, done) {
var resin, visuals;
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return resin.models.key.getAll().then(function(keys) {
return console.log(visuals.table.horizontal(keys, ['id', 'title']));
}).nodeify(done);
}
};
exports.info = {
signature: 'key <id>',
description: 'list a single ssh key',
help: 'Use this command to show information about a single SSH key.\n\nExamples:\n\n $ resin key 17',
permission: 'user',
action: function(params, options, done) {
var resin, visuals;
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return resin.models.key.get(params.id).then(function(key) {
console.log(visuals.table.vertical(key, ['id', 'title']));
return console.log('\n' + key.public_key);
}).nodeify(done);
}
};
exports.info = {
signature: 'key <id>',
description: 'list a single ssh key',
help: 'Use this command to show information about a single SSH key.\n\nExamples:\n\n $ resin key 17',
permission: 'user',
action: function(params, options, done) {
var resin, visuals;
resin = require('resin-sdk-preconfigured');
visuals = require('resin-cli-visuals');
return resin.models.key.get(params.id).then(function(key) {
console.log(visuals.table.vertical(key, ['id', 'title']));
return console.log('\n' + key.public_key);
}).nodeify(done);
}
};
exports.remove = {
signature: 'key rm <id>',
description: 'remove a ssh key',
help: 'Use this command to remove a SSH key from resin.io.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin key rm 17\n $ resin key rm 17 --yes',
options: [commandOptions.yes],
permission: 'user',
action: function(params, options, done) {
var patterns, resin;
resin = require('resin-sdk-preconfigured');
patterns = require('../utils/patterns');
return patterns.confirm(options.yes, 'Are you sure you want to delete the key?').then(function() {
return resin.models.key.remove(params.id);
}).nodeify(done);
}
};
exports.remove = {
signature: 'key rm <id>',
description: 'remove a ssh key',
help: 'Use this command to remove a SSH key from resin.io.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin key rm 17\n $ resin key rm 17 --yes',
options: [commandOptions.yes],
permission: 'user',
action: function(params, options, done) {
var patterns, resin;
resin = require('resin-sdk-preconfigured');
patterns = require('../utils/patterns');
return patterns.confirm(options.yes, 'Are you sure you want to delete the key?').then(function() {
return resin.models.key.remove(params.id);
}).nodeify(done);
}
};
exports.add = {
signature: 'key add <name> [path]',
description: 'add a SSH key to resin.io',
help: 'Use this command to associate a new SSH key with your account.\n\nIf `path` is omitted, the command will attempt\nto read the SSH key from stdin.\n\nExamples:\n\n $ resin key add Main ~/.ssh/id_rsa.pub\n $ cat ~/.ssh/id_rsa.pub | resin key add Main',
permission: 'user',
action: function(params, options, done) {
var Promise, _, capitano, fs, resin;
_ = require('lodash');
Promise = require('bluebird');
fs = Promise.promisifyAll(require('fs'));
capitano = require('capitano');
resin = require('resin-sdk-preconfigured');
return Promise["try"](function() {
if (params.path != null) {
return fs.readFileAsync(params.path, {
encoding: 'utf8'
});
}
return Promise.fromNode(function(callback) {
return capitano.utils.getStdin(function(data) {
return callback(null, data);
});
exports.add = {
signature: 'key add <name> [path]',
description: 'add a SSH key to resin.io',
help: 'Use this command to associate a new SSH key with your account.\n\nIf `path` is omitted, the command will attempt\nto read the SSH key from stdin.\n\nExamples:\n\n $ resin key add Main ~/.ssh/id_rsa.pub\n $ cat ~/.ssh/id_rsa.pub | resin key add Main',
permission: 'user',
action: function(params, options, done) {
var Promise, _, capitano, fs, resin;
_ = require('lodash');
Promise = require('bluebird');
fs = Promise.promisifyAll(require('fs'));
capitano = require('capitano');
resin = require('resin-sdk-preconfigured');
return Promise["try"](function() {
if (params.path != null) {
return fs.readFileAsync(params.path, {
encoding: 'utf8'
});
}).then(_.partial(resin.models.key.create, params.name)).nodeify(done);
}
};
}).call(this);
}
return Promise.fromNode(function(callback) {
return capitano.utils.getStdin(function(data) {
return callback(null, data);
});
});
}).then(_.partial(resin.models.key.create, params.name)).nodeify(done);
}
};

View File

@ -1,114 +1,111 @@
// Generated by CoffeeScript 1.12.4
(function() {
var Docker, Promise, _, chalk, dockerPort, dockerTimeout, filterOutSupervisorContainer, form;
var Docker, Promise, _, chalk, dockerPort, dockerTimeout, filterOutSupervisorContainer, form;
Promise = require('bluebird');
Promise = require('bluebird');
_ = require('lodash');
_ = require('lodash');
Docker = require('docker-toolbelt');
Docker = require('docker-toolbelt');
form = require('resin-cli-form');
form = require('resin-cli-form');
chalk = require('chalk');
chalk = require('chalk');
exports.dockerPort = dockerPort = 2375;
exports.dockerPort = dockerPort = 2375;
exports.dockerTimeout = dockerTimeout = 2000;
exports.dockerTimeout = dockerTimeout = 2000;
exports.filterOutSupervisorContainer = filterOutSupervisorContainer = function(container) {
var i, len, name, ref;
ref = container.Names;
for (i = 0, len = ref.length; i < len; i++) {
name = ref[i];
if (name.includes('resin_supervisor')) {
return false;
}
exports.filterOutSupervisorContainer = filterOutSupervisorContainer = function(container) {
var i, len, name, ref;
ref = container.Names;
for (i = 0, len = ref.length; i < len; i++) {
name = ref[i];
if (name.includes('resin_supervisor')) {
return false;
}
return true;
};
}
return true;
};
exports.selectContainerFromDevice = Promise.method(function(deviceIp, filterSupervisor) {
var docker;
if (filterSupervisor == null) {
filterSupervisor = false;
exports.selectContainerFromDevice = Promise.method(function(deviceIp, filterSupervisor) {
var docker;
if (filterSupervisor == null) {
filterSupervisor = false;
}
docker = new Docker({
host: deviceIp,
port: dockerPort,
timeout: dockerTimeout
});
return docker.listContainersAsync({
all: true
}).filter(function(container) {
if (!filterSupervisor) {
return true;
}
docker = new Docker({
host: deviceIp,
port: dockerPort,
timeout: dockerTimeout
});
return docker.listContainersAsync({
all: true
}).filter(function(container) {
if (!filterSupervisor) {
return true;
}
return filterOutSupervisorContainer(container);
}).then(function(containers) {
if (_.isEmpty(containers)) {
throw new Error("No containers found in " + deviceIp);
}
return form.ask({
message: 'Select a container',
type: 'list',
choices: _.map(containers, function(container) {
var containerName, containerStatus, shortContainerId;
containerName = container.Names[0] || 'Untitled';
shortContainerId = ('' + container.Id).substr(0, 11);
containerStatus = container.Status;
return {
name: containerName + " (" + shortContainerId + ") - " + containerStatus,
value: container.Id
};
})
});
return filterOutSupervisorContainer(container);
}).then(function(containers) {
if (_.isEmpty(containers)) {
throw new Error("No containers found in " + deviceIp);
}
return form.ask({
message: 'Select a container',
type: 'list',
choices: _.map(containers, function(container) {
var containerName, containerStatus, shortContainerId;
containerName = container.Names[0] || 'Untitled';
shortContainerId = ('' + container.Id).substr(0, 11);
containerStatus = container.Status;
return {
name: containerName + " (" + shortContainerId + ") - " + containerStatus,
value: container.Id
};
})
});
});
});
exports.pipeContainerStream = Promise.method(function(arg) {
var container, deviceIp, docker, follow, name, outStream, ref;
deviceIp = arg.deviceIp, name = arg.name, outStream = arg.outStream, follow = (ref = arg.follow) != null ? ref : false;
docker = new Docker({
host: deviceIp,
port: dockerPort
});
container = docker.getContainer(name);
return container.inspectAsync().then(function(containerInfo) {
var ref1;
return containerInfo != null ? (ref1 = containerInfo.State) != null ? ref1.Running : void 0 : void 0;
}).then(function(isRunning) {
return container.attachAsync({
logs: !follow || !isRunning,
stream: follow && isRunning,
stdout: true,
stderr: true
});
}).then(function(containerStream) {
return containerStream.pipe(outStream);
})["catch"](function(err) {
err = '' + err.statusCode;
if (err === '404') {
return console.log(chalk.red.bold("Container '" + name + "' not found."));
}
throw err;
});
exports.pipeContainerStream = Promise.method(function(arg) {
var container, deviceIp, docker, follow, name, outStream, ref;
deviceIp = arg.deviceIp, name = arg.name, outStream = arg.outStream, follow = (ref = arg.follow) != null ? ref : false;
docker = new Docker({
host: deviceIp,
port: dockerPort
});
exports.getSubShellCommand = function(command) {
var os;
os = require('os');
if (os.platform() === 'win32') {
return {
program: 'cmd.exe',
args: ['/s', '/c', command]
};
} else {
return {
program: '/bin/sh',
args: ['-c', command]
};
container = docker.getContainer(name);
return container.inspectAsync().then(function(containerInfo) {
var ref1;
return containerInfo != null ? (ref1 = containerInfo.State) != null ? ref1.Running : void 0 : void 0;
}).then(function(isRunning) {
return container.attachAsync({
logs: !follow || !isRunning,
stream: follow && isRunning,
stdout: true,
stderr: true
});
}).then(function(containerStream) {
return containerStream.pipe(outStream);
})["catch"](function(err) {
err = '' + err.statusCode;
if (err === '404') {
return console.log(chalk.red.bold("Container '" + name + "' not found."));
}
};
throw err;
});
});
}).call(this);
exports.getSubShellCommand = function(command) {
var os;
os = require('os');
if (os.platform() === 'win32') {
return {
program: 'cmd.exe',
args: ['/s', '/c', command]
};
} else {
return {
program: '/bin/sh',
args: ['-c', command]
};
}
};

View File

@ -15,119 +15,115 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var CONFIGURATION_SCHEMA;
(function() {
var CONFIGURATION_SCHEMA;
CONFIGURATION_SCHEMA = {
mapper: [
{
template: {
hostname: '{{hostname}}',
persistentLogging: '{{persistentLogging}}'
CONFIGURATION_SCHEMA = {
mapper: [
{
template: {
hostname: '{{hostname}}',
persistentLogging: '{{persistentLogging}}'
},
domain: [['config_json', 'hostname'], ['config_json', 'persistentLogging']]
}, {
template: {
wifi: {
ssid: '{{networkSsid}}'
},
domain: [['config_json', 'hostname'], ['config_json', 'persistentLogging']]
}, {
template: {
wifi: {
ssid: '{{networkSsid}}'
},
'wifi-security': {
psk: '{{networkKey}}'
}
},
domain: [['system_connections', 'resin-sample', 'wifi'], ['system_connections', 'resin-sample', 'wifi-security']]
}
],
files: {
system_connections: {
fileset: true,
type: 'ini',
location: {
path: 'system-connections',
partition: {
primary: 1
}
'wifi-security': {
psk: '{{networkKey}}'
}
},
config_json: {
type: 'json',
location: {
path: 'config.json',
partition: {
primary: 1
}
domain: [['system_connections', 'resin-sample', 'wifi'], ['system_connections', 'resin-sample', 'wifi-security']]
}
],
files: {
system_connections: {
fileset: true,
type: 'ini',
location: {
path: 'system-connections',
partition: {
primary: 1
}
}
},
config_json: {
type: 'json',
location: {
path: 'config.json',
partition: {
primary: 1
}
}
}
};
}
};
module.exports = {
signature: 'local configure <target>',
description: '(Re)configure a resinOS drive or image',
help: 'Use this command to configure or reconfigure a resinOS drive or image.\n\nExamples:\n\n $ resin local configure /dev/sdc\n $ resin local configure path/to/image.img',
root: true,
action: function(params, options, done) {
var Promise, _, denymount, inquirer, reconfix, umount;
_ = require('lodash');
Promise = require('bluebird');
umount = Promise.promisifyAll(require('umount'));
inquirer = require('inquirer');
reconfix = require('reconfix');
denymount = Promise.promisify(require('denymount'));
return umount.isMountedAsync(params.target).then(function(isMounted) {
if (!isMounted) {
return;
}
return umount.umountAsync(params.target);
}).then(function() {
return denymount(params.target, function(cb) {
return reconfix.readConfiguration(CONFIGURATION_SCHEMA, params.target).then(function(data) {
data.persistentLogging = data.persistentLogging || false;
return inquirer.prompt([
{
message: 'Network SSID',
type: 'input',
name: 'networkSsid',
"default": data.networkSsid
}, {
message: 'Network Key',
type: 'input',
name: 'networkKey',
"default": data.networkKey
}, {
message: 'Do you want to set advanced settings?',
type: 'confirm',
name: 'advancedSettings',
"default": false
}, {
message: 'Device Hostname',
type: 'input',
name: 'hostname',
"default": data.hostname,
when: function(answers) {
return answers.advancedSettings;
}
}, {
message: 'Do you want to enable persistent logging?',
type: 'confirm',
name: 'persistentLogging',
"default": data.persistentLogging,
when: function(answers) {
return answers.advancedSettings;
}
module.exports = {
signature: 'local configure <target>',
description: '(Re)configure a resinOS drive or image',
help: 'Use this command to configure or reconfigure a resinOS drive or image.\n\nExamples:\n\n $ resin local configure /dev/sdc\n $ resin local configure path/to/image.img',
root: true,
action: function(params, options, done) {
var Promise, _, denymount, inquirer, reconfix, umount;
_ = require('lodash');
Promise = require('bluebird');
umount = Promise.promisifyAll(require('umount'));
inquirer = require('inquirer');
reconfix = require('reconfix');
denymount = Promise.promisify(require('denymount'));
return umount.isMountedAsync(params.target).then(function(isMounted) {
if (!isMounted) {
return;
}
return umount.umountAsync(params.target);
}).then(function() {
return denymount(params.target, function(cb) {
return reconfix.readConfiguration(CONFIGURATION_SCHEMA, params.target).then(function(data) {
data.persistentLogging = data.persistentLogging || false;
return inquirer.prompt([
{
message: 'Network SSID',
type: 'input',
name: 'networkSsid',
"default": data.networkSsid
}, {
message: 'Network Key',
type: 'input',
name: 'networkKey',
"default": data.networkKey
}, {
message: 'Do you want to set advanced settings?',
type: 'confirm',
name: 'advancedSettings',
"default": false
}, {
message: 'Device Hostname',
type: 'input',
name: 'hostname',
"default": data.hostname,
when: function(answers) {
return answers.advancedSettings;
}
]).then(function(answers) {
return _.merge(data, answers);
});
}).then(function(answers) {
return reconfix.writeConfiguration(CONFIGURATION_SCHEMA, answers, params.target);
}).asCallback(cb);
});
}).then(function() {
return console.log('Done!');
}).asCallback(done);
}
};
}).call(this);
}, {
message: 'Do you want to enable persistent logging?',
type: 'confirm',
name: 'persistentLogging',
"default": data.persistentLogging,
when: function(answers) {
return answers.advancedSettings;
}
}
]).then(function(answers) {
return _.merge(data, answers);
});
}).then(function(answers) {
return reconfix.writeConfiguration(CONFIGURATION_SCHEMA, answers, params.target);
}).asCallback(cb);
});
}).then(function() {
return console.log('Done!');
}).asCallback(done);
}
};

View File

@ -15,115 +15,111 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function() {
module.exports = {
signature: 'local flash <image>',
description: 'Flash an image to a drive',
help: 'Use this command to flash a resinOS image to a drive.\n\nExamples:\n\n $ resin local flash path/to/resinos.img\n $ resin local flash path/to/resinos.img --drive /dev/disk2\n $ resin local flash path/to/resinos.img --drive /dev/disk2 --yes',
options: [
{
signature: 'yes',
boolean: true,
description: 'confirm non-interactively',
alias: 'y'
}, {
signature: 'drive',
parameter: 'drive',
description: 'drive',
alias: 'd'
}
],
root: true,
action: function(params, options, done) {
var Promise, _, chalk, drivelist, form, fs, imageWrite, os, umount, visuals;
_ = require('lodash');
os = require('os');
Promise = require('bluebird');
umount = Promise.promisifyAll(require('umount'));
fs = Promise.promisifyAll(require('fs'));
drivelist = Promise.promisifyAll(require('drivelist'));
chalk = require('chalk');
visuals = require('resin-cli-visuals');
form = require('resin-cli-form');
require('babel-register')({
only: /etcher-image-write|bmapflash/,
presets: ['es2015'],
compact: true
});
imageWrite = require('etcher-image-write');
return form.run([
{
message: 'Select drive',
type: 'drive',
name: 'drive'
}, {
message: 'This will erase the selected drive. Are you sure?',
type: 'confirm',
name: 'yes',
"default": false
}
], {
override: {
drive: options.drive,
yes: options.yes || void 0
}
}).then(function(answers) {
if (answers.yes !== true) {
console.log(chalk.red.bold('Aborted image flash'));
process.exit(0);
}
return drivelist.listAsync().then(function(drives) {
var selectedDrive;
selectedDrive = _.find(drives, {
device: answers.drive
});
if (selectedDrive == null) {
throw new Error("Drive not found: " + answers.drive);
}
return selectedDrive;
});
}).then(function(selectedDrive) {
var progressBars;
progressBars = {
write: new visuals.Progress('Flashing'),
check: new visuals.Progress('Validating')
};
return umount.umountAsync(selectedDrive.device).then(function() {
return Promise.props({
imageSize: fs.statAsync(params.image).get('size'),
imageStream: Promise.resolve(fs.createReadStream(params.image)),
driveFileDescriptor: fs.openAsync(selectedDrive.raw, 'rs+')
});
}).then(function(results) {
return imageWrite.write({
fd: results.driveFileDescriptor,
device: selectedDrive.raw,
size: selectedDrive.size
}, {
stream: results.imageStream,
size: results.imageSize
}, {
check: true
});
}).then(function(writer) {
return new Promise(function(resolve, reject) {
writer.on('progress', function(state) {
return progressBars[state.type].update(state);
});
writer.on('error', reject);
return writer.on('done', resolve);
});
}).then(function() {
var removedrive;
if ((os.platform() === 'win32') && (selectedDrive.mountpoint != null)) {
removedrive = Promise.promisifyAll(require('removedrive'));
return removedrive.ejectAsync(selectedDrive.mountpoint);
}
return umount.umountAsync(selectedDrive.device);
});
}).asCallback(done);
module.exports = {
signature: 'local flash <image>',
description: 'Flash an image to a drive',
help: 'Use this command to flash a resinOS image to a drive.\n\nExamples:\n\n $ resin local flash path/to/resinos.img\n $ resin local flash path/to/resinos.img --drive /dev/disk2\n $ resin local flash path/to/resinos.img --drive /dev/disk2 --yes',
options: [
{
signature: 'yes',
boolean: true,
description: 'confirm non-interactively',
alias: 'y'
}, {
signature: 'drive',
parameter: 'drive',
description: 'drive',
alias: 'd'
}
};
}).call(this);
],
root: true,
action: function(params, options, done) {
var Promise, _, chalk, drivelist, form, fs, imageWrite, os, umount, visuals;
_ = require('lodash');
os = require('os');
Promise = require('bluebird');
umount = Promise.promisifyAll(require('umount'));
fs = Promise.promisifyAll(require('fs'));
drivelist = Promise.promisifyAll(require('drivelist'));
chalk = require('chalk');
visuals = require('resin-cli-visuals');
form = require('resin-cli-form');
require('babel-register')({
only: /etcher-image-write|bmapflash/,
presets: ['es2015'],
compact: true
});
imageWrite = require('etcher-image-write');
return form.run([
{
message: 'Select drive',
type: 'drive',
name: 'drive'
}, {
message: 'This will erase the selected drive. Are you sure?',
type: 'confirm',
name: 'yes',
"default": false
}
], {
override: {
drive: options.drive,
yes: options.yes || void 0
}
}).then(function(answers) {
if (answers.yes !== true) {
console.log(chalk.red.bold('Aborted image flash'));
process.exit(0);
}
return drivelist.listAsync().then(function(drives) {
var selectedDrive;
selectedDrive = _.find(drives, {
device: answers.drive
});
if (selectedDrive == null) {
throw new Error("Drive not found: " + answers.drive);
}
return selectedDrive;
});
}).then(function(selectedDrive) {
var progressBars;
progressBars = {
write: new visuals.Progress('Flashing'),
check: new visuals.Progress('Validating')
};
return umount.umountAsync(selectedDrive.device).then(function() {
return Promise.props({
imageSize: fs.statAsync(params.image).get('size'),
imageStream: Promise.resolve(fs.createReadStream(params.image)),
driveFileDescriptor: fs.openAsync(selectedDrive.raw, 'rs+')
});
}).then(function(results) {
return imageWrite.write({
fd: results.driveFileDescriptor,
device: selectedDrive.raw,
size: selectedDrive.size
}, {
stream: results.imageStream,
size: results.imageSize
}, {
check: true
});
}).then(function(writer) {
return new Promise(function(resolve, reject) {
writer.on('progress', function(state) {
return progressBars[state.type].update(state);
});
writer.on('error', reject);
return writer.on('done', resolve);
});
}).then(function() {
var removedrive;
if ((os.platform() === 'win32') && (selectedDrive.mountpoint != null)) {
removedrive = Promise.promisifyAll(require('removedrive'));
return removedrive.ejectAsync(selectedDrive.mountpoint);
}
return umount.umountAsync(selectedDrive.device);
});
}).asCallback(done);
}
};

View File

@ -15,22 +15,18 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
exports.configure = require('./configure');
(function() {
exports.configure = require('./configure');
exports.flash = require('./flash');
exports.flash = require('./flash');
exports.logs = require('./logs');
exports.logs = require('./logs');
exports.promote = require('./promote');
exports.promote = require('./promote');
exports.scan = require('./scan');
exports.scan = require('./scan');
exports.ssh = require('./ssh');
exports.ssh = require('./ssh');
exports.push = require('./push');
exports.push = require('./push');
exports.stop = require('./stop');
}).call(this);
exports.stop = require('./stop');

View File

@ -15,55 +15,51 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function() {
module.exports = {
signature: 'local logs [deviceIp]',
description: 'Get or attach to logs of a running container on a resinOS device',
help: '\nExamples:\n\n $ resin local logs\n $ resin local logs -f\n $ resin local logs 192.168.1.10\n $ resin local logs 192.168.1.10 -f\n $ resin local logs 192.168.1.10 -f --app-name myapp',
options: [
{
signature: 'follow',
boolean: true,
description: 'follow log',
alias: 'f'
}, {
signature: 'app-name',
parameter: 'name',
description: 'name of container to get logs from',
alias: 'a'
}
],
root: true,
action: function(params, options, done) {
var Promise, forms, pipeContainerStream, ref, selectContainerFromDevice;
Promise = require('bluebird');
forms = require('resin-sync').forms;
ref = require('./common'), selectContainerFromDevice = ref.selectContainerFromDevice, pipeContainerStream = ref.pipeContainerStream;
return Promise["try"](function() {
if (params.deviceIp == null) {
return forms.selectLocalResinOsDevice();
}
return params.deviceIp;
}).then((function(_this) {
return function(deviceIp) {
_this.deviceIp = deviceIp;
if (options['app-name'] == null) {
return selectContainerFromDevice(_this.deviceIp);
}
return options['app-name'];
};
})(this)).then((function(_this) {
return function(appName) {
return pipeContainerStream({
deviceIp: _this.deviceIp,
name: appName,
outStream: process.stdout,
follow: options['follow']
});
};
})(this));
module.exports = {
signature: 'local logs [deviceIp]',
description: 'Get or attach to logs of a running container on a resinOS device',
help: '\nExamples:\n\n $ resin local logs\n $ resin local logs -f\n $ resin local logs 192.168.1.10\n $ resin local logs 192.168.1.10 -f\n $ resin local logs 192.168.1.10 -f --app-name myapp',
options: [
{
signature: 'follow',
boolean: true,
description: 'follow log',
alias: 'f'
}, {
signature: 'app-name',
parameter: 'name',
description: 'name of container to get logs from',
alias: 'a'
}
};
}).call(this);
],
root: true,
action: function(params, options, done) {
var Promise, forms, pipeContainerStream, ref, selectContainerFromDevice;
Promise = require('bluebird');
forms = require('resin-sync').forms;
ref = require('./common'), selectContainerFromDevice = ref.selectContainerFromDevice, pipeContainerStream = ref.pipeContainerStream;
return Promise["try"](function() {
if (params.deviceIp == null) {
return forms.selectLocalResinOsDevice();
}
return params.deviceIp;
}).then((function(_this) {
return function(deviceIp) {
_this.deviceIp = deviceIp;
if (options['app-name'] == null) {
return selectContainerFromDevice(_this.deviceIp);
}
return options['app-name'];
};
})(this)).then((function(_this) {
return function(appName) {
return pipeContainerStream({
deviceIp: _this.deviceIp,
name: appName,
outStream: process.stdout,
follow: options['follow']
});
};
})(this));
}
};

View File

@ -15,51 +15,47 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function() {
module.exports = {
signature: 'local promote [deviceIp]',
description: 'Promote a resinOS device',
help: 'Warning: \'resin promote\' requires an openssh-compatible client to be correctly\ninstalled in your shell environment. For more information (including Windows\nsupport) please check the README here: https://github.com/resin-io/resin-cli\n\nUse this command to promote your device.\n\nPromoting a device will provision it onto the Resin platform,\nconverting it from an unmanaged device to a managed device.\n\nExamples:\n\n $ resin local promote\n $ resin local promote --port 22222\n $ resin local promote --verbose',
options: [
{
signature: 'verbose',
boolean: true,
description: 'increase verbosity',
alias: 'v'
}, {
signature: 'port',
parameter: 'port',
description: 'ssh port number (default: 22222)',
alias: 'p'
}
],
root: true,
action: function(params, options, done) {
var Promise, _, child_process, forms, getSubShellCommand, verbose;
child_process = require('child_process');
Promise = require('bluebird');
_ = require('lodash');
forms = require('resin-sync').forms;
getSubShellCommand = require('./common').getSubShellCommand;
if (options.port == null) {
options.port = 22222;
}
verbose = options.verbose ? '-vvv' : '';
return Promise["try"](function() {
return params.deviceIp != null ? params.deviceIp : params.deviceIp = forms.selectLocalResinOsDevice();
}).then(function(deviceIp) {
var command, subShellCommand;
_.assign(options, {
deviceIp: deviceIp
});
command = "ssh " + verbose + " -t -p " + options.port + " -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ControlMaster=no root@" + options.deviceIp + " -- \"resin-provision interactive\"";
subShellCommand = getSubShellCommand(command);
return child_process.spawn(subShellCommand.program, subShellCommand.args, {
stdio: 'inherit'
});
}).nodeify(done);
module.exports = {
signature: 'local promote [deviceIp]',
description: 'Promote a resinOS device',
help: 'Warning: \'resin promote\' requires an openssh-compatible client to be correctly\ninstalled in your shell environment. For more information (including Windows\nsupport) please check the README here: https://github.com/resin-io/resin-cli\n\nUse this command to promote your device.\n\nPromoting a device will provision it onto the Resin platform,\nconverting it from an unmanaged device to a managed device.\n\nExamples:\n\n $ resin local promote\n $ resin local promote --port 22222\n $ resin local promote --verbose',
options: [
{
signature: 'verbose',
boolean: true,
description: 'increase verbosity',
alias: 'v'
}, {
signature: 'port',
parameter: 'port',
description: 'ssh port number (default: 22222)',
alias: 'p'
}
};
}).call(this);
],
root: true,
action: function(params, options, done) {
var Promise, _, child_process, forms, getSubShellCommand, verbose;
child_process = require('child_process');
Promise = require('bluebird');
_ = require('lodash');
forms = require('resin-sync').forms;
getSubShellCommand = require('./common').getSubShellCommand;
if (options.port == null) {
options.port = 22222;
}
verbose = options.verbose ? '-vvv' : '';
return Promise["try"](function() {
return params.deviceIp != null ? params.deviceIp : params.deviceIp = forms.selectLocalResinOsDevice();
}).then(function(deviceIp) {
var command, subShellCommand;
_.assign(options, {
deviceIp: deviceIp
});
command = "ssh " + verbose + " -t -p " + options.port + " -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ControlMaster=no root@" + options.deviceIp + " -- \"resin-provision interactive\"";
subShellCommand = getSubShellCommand(command);
return child_process.spawn(subShellCommand.program, subShellCommand.args, {
stdio: 'inherit'
});
}).nodeify(done);
}
};

View File

@ -15,21 +15,17 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var _, resinPush, resinPushHelp;
(function() {
var _, resinPush, resinPushHelp;
_ = require('lodash');
_ = require('lodash');
resinPush = require('resin-sync').capitano('resin-toolbox');
resinPush = require('resin-sync').capitano('resin-toolbox');
resinPushHelp = 'Warning: \'resin local push\' requires an openssh-compatible client and \'rsync\' to\nbe correctly installed in your shell environment. For more information (including\nWindows support) please check the README here: https://github.com/resin-io/resin-cli\n\nUse this command to push your local changes to a container on a LAN-accessible resinOS device on the fly.\n\nIf `Dockerfile` or any file in the \'build-triggers\' list is changed,\na new container will be built and run on your device.\nIf not, changes will simply be synced with `rsync` into the application container.\n\nAfter every \'resin local push\' the updated settings will be saved in\n\'<source>/.resin-sync.yml\' and will be used in later invocations. You can\nalso change any option by editing \'.resin-sync.yml\' directly.\n\nHere is an example \'.resin-sync.yml\' :\n\n $ cat $PWD/.resin-sync.yml\n destination: \'/usr/src/app\'\n before: \'echo Hello\'\n after: \'echo Done\'\n ignore:\n - .git\n - node_modules/\n\nCommand line options have precedence over the ones saved in \'.resin-sync.yml\'.\n\nIf \'.gitignore\' is found in the source directory then all explicitly listed files will be\nexcluded when using rsync to update the container. You can choose to change this default behavior with the\n\'--skip-gitignore\' option.\n\nExamples:\n\n $ resin local push\n $ resin local push --app-name test-server --build-triggers package.json,requirements.txt\n $ resin local push --force-build\n $ resin local push --force-build --skip-logs\n $ resin local push --ignore lib/\n $ resin local push --verbose false\n $ resin local push 192.168.2.10 --source . --destination /usr/src/app\n $ resin local push 192.168.2.10 -s /home/user/myResinProject -d /usr/src/app --before \'echo Hello\' --after \'echo Done\'';
resinPushHelp = 'Warning: \'resin local push\' requires an openssh-compatible client and \'rsync\' to\nbe correctly installed in your shell environment. For more information (including\nWindows support) please check the README here: https://github.com/resin-io/resin-cli\n\nUse this command to push your local changes to a container on a LAN-accessible resinOS device on the fly.\n\nIf `Dockerfile` or any file in the \'build-triggers\' list is changed,\na new container will be built and run on your device.\nIf not, changes will simply be synced with `rsync` into the application container.\n\nAfter every \'resin local push\' the updated settings will be saved in\n\'<source>/.resin-sync.yml\' and will be used in later invocations. You can\nalso change any option by editing \'.resin-sync.yml\' directly.\n\nHere is an example \'.resin-sync.yml\' :\n\n $ cat $PWD/.resin-sync.yml\n destination: \'/usr/src/app\'\n before: \'echo Hello\'\n after: \'echo Done\'\n ignore:\n - .git\n - node_modules/\n\nCommand line options have precedence over the ones saved in \'.resin-sync.yml\'.\n\nIf \'.gitignore\' is found in the source directory then all explicitly listed files will be\nexcluded when using rsync to update the container. You can choose to change this default behavior with the\n\'--skip-gitignore\' option.\n\nExamples:\n\n $ resin local push\n $ resin local push --app-name test-server --build-triggers package.json,requirements.txt\n $ resin local push --force-build\n $ resin local push --force-build --skip-logs\n $ resin local push --ignore lib/\n $ resin local push --verbose false\n $ resin local push 192.168.2.10 --source . --destination /usr/src/app\n $ resin local push 192.168.2.10 -s /home/user/myResinProject -d /usr/src/app --before \'echo Hello\' --after \'echo Done\'';
module.exports = _.assign(resinPush, {
signature: 'local push [deviceIp]',
help: resinPushHelp,
primary: true,
root: true
});
}).call(this);
module.exports = _.assign(resinPush, {
signature: 'local push [deviceIp]',
help: resinPushHelp,
primary: true,
root: true
});

View File

@ -15,102 +15,98 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var dockerInfoProperties, dockerVersionProperties;
(function() {
var dockerInfoProperties, dockerVersionProperties;
dockerInfoProperties = ['Containers', 'ContainersRunning', 'ContainersPaused', 'ContainersStopped', 'Images', 'Driver', 'SystemTime', 'KernelVersion', 'OperatingSystem', 'Architecture'];
dockerInfoProperties = ['Containers', 'ContainersRunning', 'ContainersPaused', 'ContainersStopped', 'Images', 'Driver', 'SystemTime', 'KernelVersion', 'OperatingSystem', 'Architecture'];
dockerVersionProperties = ['Version', 'ApiVersion'];
dockerVersionProperties = ['Version', 'ApiVersion'];
module.exports = {
signature: 'local scan',
description: 'Scan for resinOS devices in your local network',
help: '\nExamples:\n\n $ resin local scan\n $ resin local scan --timeout 120\n $ resin local scan --verbose',
options: [
{
signature: 'verbose',
boolean: true,
description: 'Display full info',
alias: 'v'
}, {
signature: 'timeout',
parameter: 'timeout',
description: 'Scan timeout in seconds',
alias: 't'
}
],
primary: true,
root: true,
action: function(params, options, done) {
var Docker, Promise, SpinnerPromise, _, discover, dockerPort, dockerTimeout, prettyjson, ref;
Promise = require('bluebird');
_ = require('lodash');
prettyjson = require('prettyjson');
Docker = require('docker-toolbelt');
discover = require('resin-sync').discover;
SpinnerPromise = require('resin-cli-visuals').SpinnerPromise;
ref = require('./common'), dockerPort = ref.dockerPort, dockerTimeout = ref.dockerTimeout;
if (options.timeout != null) {
options.timeout *= 1000;
}
module.exports = {
signature: 'local scan',
description: 'Scan for resinOS devices in your local network',
help: '\nExamples:\n\n $ resin local scan\n $ resin local scan --timeout 120\n $ resin local scan --verbose',
options: [
{
signature: 'verbose',
boolean: true,
description: 'Display full info',
alias: 'v'
}, {
signature: 'timeout',
parameter: 'timeout',
description: 'Scan timeout in seconds',
alias: 't'
}
],
primary: true,
root: true,
action: function(params, options, done) {
var Docker, Promise, SpinnerPromise, _, discover, dockerPort, dockerTimeout, prettyjson, ref;
Promise = require('bluebird');
_ = require('lodash');
prettyjson = require('prettyjson');
Docker = require('docker-toolbelt');
discover = require('resin-sync').discover;
SpinnerPromise = require('resin-cli-visuals').SpinnerPromise;
ref = require('./common'), dockerPort = ref.dockerPort, dockerTimeout = ref.dockerTimeout;
if (options.timeout != null) {
options.timeout *= 1000;
}
return Promise["try"](function() {
return new SpinnerPromise({
promise: discover.discoverLocalResinOsDevices(options.timeout),
startMessage: 'Scanning for local resinOS devices..',
stopMessage: 'Reporting scan results'
});
}).filter(function(arg) {
var address;
address = arg.address;
return Promise["try"](function() {
return new SpinnerPromise({
promise: discover.discoverLocalResinOsDevices(options.timeout),
startMessage: 'Scanning for local resinOS devices..',
stopMessage: 'Reporting scan results'
});
}).filter(function(arg) {
var address;
address = arg.address;
return Promise["try"](function() {
var docker;
docker = new Docker({
host: address,
port: dockerPort,
timeout: dockerTimeout
});
return docker.pingAsync();
})["return"](true).catchReturn(false);
}).tap(function(devices) {
if (_.isEmpty(devices)) {
throw new Error('Could not find any resinOS devices in the local network');
}
}).map(function(arg) {
var address, docker, host;
host = arg.host, address = arg.address;
var docker;
docker = new Docker({
host: address,
port: dockerPort,
timeout: dockerTimeout
});
return Promise.props({
dockerInfo: docker.infoAsync().catchReturn('Could not get Docker info'),
dockerVersion: docker.versionAsync().catchReturn('Could not get Docker version')
}).then(function(arg1) {
var dockerInfo, dockerVersion;
dockerInfo = arg1.dockerInfo, dockerVersion = arg1.dockerVersion;
if (!options.verbose) {
if (_.isObject(dockerInfo)) {
dockerInfo = _.pick(dockerInfo, dockerInfoProperties);
}
if (_.isObject(dockerVersion)) {
dockerVersion = _.pick(dockerVersion, dockerVersionProperties);
}
return docker.pingAsync();
})["return"](true).catchReturn(false);
}).tap(function(devices) {
if (_.isEmpty(devices)) {
throw new Error('Could not find any resinOS devices in the local network');
}
}).map(function(arg) {
var address, docker, host;
host = arg.host, address = arg.address;
docker = new Docker({
host: address,
port: dockerPort,
timeout: dockerTimeout
});
return Promise.props({
dockerInfo: docker.infoAsync().catchReturn('Could not get Docker info'),
dockerVersion: docker.versionAsync().catchReturn('Could not get Docker version')
}).then(function(arg1) {
var dockerInfo, dockerVersion;
dockerInfo = arg1.dockerInfo, dockerVersion = arg1.dockerVersion;
if (!options.verbose) {
if (_.isObject(dockerInfo)) {
dockerInfo = _.pick(dockerInfo, dockerInfoProperties);
}
return {
host: host,
address: address,
dockerInfo: dockerInfo,
dockerVersion: dockerVersion
};
});
}).then(function(devicesInfo) {
return console.log(prettyjson.render(devicesInfo, {
noColor: true
}));
}).nodeify(done);
}
};
}).call(this);
if (_.isObject(dockerVersion)) {
dockerVersion = _.pick(dockerVersion, dockerVersionProperties);
}
}
return {
host: host,
address: address,
dockerInfo: dockerInfo,
dockerVersion: dockerVersion
};
});
}).then(function(devicesInfo) {
return console.log(prettyjson.render(devicesInfo, {
noColor: true
}));
}).nodeify(done);
}
};

View File

@ -15,80 +15,76 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function() {
module.exports = {
signature: 'local ssh [deviceIp]',
description: 'Get a shell into a resinOS device',
help: 'Warning: \'resin local ssh\' requires an openssh-compatible client to be correctly\ninstalled in your shell environment. For more information (including Windows\nsupport) please check the README here: https://github.com/resin-io/resin-cli\n\nUse this command to get a shell into the running application container of\nyour device.\n\nThe \'--host\' option will get you a shell into the Host OS of the resinOS device.\nNo option will return a list of containers to enter or you can explicitly select\none by passing its name to the --container option\n\nExamples:\n\n $ resin local ssh\n $ resin local ssh --host\n $ resin local ssh --container chaotic_water\n $ resin local ssh --container chaotic_water --port 22222\n $ resin local ssh --verbose',
options: [
{
signature: 'verbose',
boolean: true,
description: 'increase verbosity',
alias: 'v'
}, {
signature: 'host',
boolean: true,
description: 'get a shell into the host OS',
alias: 's'
}, {
signature: 'container',
parameter: 'container',
"default": null,
description: 'name of container to access',
alias: 'c'
}, {
signature: 'port',
parameter: 'port',
description: 'ssh port number (default: 22222)',
alias: 'p'
}
],
root: true,
action: function(params, options, done) {
var Promise, _, child_process, forms, getSubShellCommand, ref, selectContainerFromDevice, verbose;
child_process = require('child_process');
Promise = require('bluebird');
_ = require('lodash');
forms = require('resin-sync').forms;
ref = require('./common'), selectContainerFromDevice = ref.selectContainerFromDevice, getSubShellCommand = ref.getSubShellCommand;
if (options.host === true && (options.container != null)) {
throw new Error('Please pass either --host or --container option');
}
if (options.port == null) {
options.port = 22222;
}
verbose = options.verbose ? '-vvv' : '';
return Promise["try"](function() {
if (params.deviceIp == null) {
return forms.selectLocalResinOsDevice();
}
return params.deviceIp;
}).then(function(deviceIp) {
_.assign(options, {
deviceIp: deviceIp
});
if (options.host) {
return;
}
if (options.container == null) {
return selectContainerFromDevice(deviceIp);
}
return options.container;
}).then(function(container) {
var command, shellCmd, subShellCommand;
command = "ssh " + verbose + " -t -p " + options.port + " -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ControlMaster=no root@" + options.deviceIp;
if (!options.host) {
shellCmd = '/bin/sh -c $"\'if [ -e /bin/bash ]; then exec /bin/bash; else exec /bin/sh; fi\'"';
command += " docker exec -ti " + container + " " + shellCmd;
}
subShellCommand = getSubShellCommand(command);
return child_process.spawn(subShellCommand.program, subShellCommand.args, {
stdio: 'inherit'
});
}).nodeify(done);
module.exports = {
signature: 'local ssh [deviceIp]',
description: 'Get a shell into a resinOS device',
help: 'Warning: \'resin local ssh\' requires an openssh-compatible client to be correctly\ninstalled in your shell environment. For more information (including Windows\nsupport) please check the README here: https://github.com/resin-io/resin-cli\n\nUse this command to get a shell into the running application container of\nyour device.\n\nThe \'--host\' option will get you a shell into the Host OS of the resinOS device.\nNo option will return a list of containers to enter or you can explicitly select\none by passing its name to the --container option\n\nExamples:\n\n $ resin local ssh\n $ resin local ssh --host\n $ resin local ssh --container chaotic_water\n $ resin local ssh --container chaotic_water --port 22222\n $ resin local ssh --verbose',
options: [
{
signature: 'verbose',
boolean: true,
description: 'increase verbosity',
alias: 'v'
}, {
signature: 'host',
boolean: true,
description: 'get a shell into the host OS',
alias: 's'
}, {
signature: 'container',
parameter: 'container',
"default": null,
description: 'name of container to access',
alias: 'c'
}, {
signature: 'port',
parameter: 'port',
description: 'ssh port number (default: 22222)',
alias: 'p'
}
};
}).call(this);
],
root: true,
action: function(params, options, done) {
var Promise, _, child_process, forms, getSubShellCommand, ref, selectContainerFromDevice, verbose;
child_process = require('child_process');
Promise = require('bluebird');
_ = require('lodash');
forms = require('resin-sync').forms;
ref = require('./common'), selectContainerFromDevice = ref.selectContainerFromDevice, getSubShellCommand = ref.getSubShellCommand;
if (options.host === true && (options.container != null)) {
throw new Error('Please pass either --host or --container option');
}
if (options.port == null) {
options.port = 22222;
}
verbose = options.verbose ? '-vvv' : '';
return Promise["try"](function() {
if (params.deviceIp == null) {
return forms.selectLocalResinOsDevice();
}
return params.deviceIp;
}).then(function(deviceIp) {
_.assign(options, {
deviceIp: deviceIp
});
if (options.host) {
return;
}
if (options.container == null) {
return selectContainerFromDevice(deviceIp);
}
return options.container;
}).then(function(container) {
var command, shellCmd, subShellCommand;
command = "ssh " + verbose + " -t -p " + options.port + " -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ControlMaster=no root@" + options.deviceIp;
if (!options.host) {
shellCmd = '/bin/sh -c $"\'if [ -e /bin/bash ]; then exec /bin/bash; else exec /bin/sh; fi\'"';
command += " docker exec -ti " + container + " " + shellCmd;
}
subShellCommand = getSubShellCommand(command);
return child_process.spawn(subShellCommand.program, subShellCommand.args, {
stdio: 'inherit'
});
}).nodeify(done);
}
};

View File

@ -15,67 +15,63 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function() {
module.exports = {
signature: 'local stop [deviceIp]',
description: 'Stop a running container on a resinOS device',
help: '\nExamples:\n\n $ resin local stop\n $ resin local stop --app-name myapp\n $ resin local stop --all\n $ resin local stop 192.168.1.10\n $ resin local stop 192.168.1.10 --app-name myapp',
options: [
{
signature: 'all',
boolean: true,
description: 'stop all containers'
}, {
signature: 'app-name',
parameter: 'name',
description: 'name of container to stop',
alias: 'a'
}
],
root: true,
action: function(params, options, done) {
var Promise, ResinLocalDockerUtils, chalk, config, filterOutSupervisorContainer, forms, ref, ref1, selectContainerFromDevice;
Promise = require('bluebird');
chalk = require('chalk');
ref = require('resin-sync'), forms = ref.forms, config = ref.config, ResinLocalDockerUtils = ref.ResinLocalDockerUtils;
ref1 = require('./common'), selectContainerFromDevice = ref1.selectContainerFromDevice, filterOutSupervisorContainer = ref1.filterOutSupervisorContainer;
return Promise["try"](function() {
if (params.deviceIp == null) {
return forms.selectLocalResinOsDevice();
}
return params.deviceIp;
}).then((function(_this) {
return function(deviceIp) {
var ref2, ref3, ymlConfig;
_this.deviceIp = deviceIp;
_this.docker = new ResinLocalDockerUtils(_this.deviceIp);
if (options.all) {
return _this.docker.docker.listContainersAsync({
all: false
}).filter(filterOutSupervisorContainer).then(function(containers) {
return Promise.map(containers, function(arg) {
var Id, Names;
Names = arg.Names, Id = arg.Id;
console.log(chalk.yellow.bold("* Stopping container " + Names[0]));
return _this.docker.stopContainer(Id);
});
});
}
ymlConfig = config.load();
_this.appName = (ref2 = options['app-name']) != null ? ref2 : (ref3 = ymlConfig['local_resinos']) != null ? ref3['app-name'] : void 0;
return _this.docker.checkForRunningContainer(_this.appName).then(function(isRunning) {
if (!isRunning) {
return selectContainerFromDevice(_this.deviceIp, true);
}
console.log(chalk.yellow.bold("* Stopping container " + _this.appName));
return _this.appName;
}).then(function(runningContainerName) {
return _this.docker.stopContainer(runningContainerName);
});
};
})(this));
module.exports = {
signature: 'local stop [deviceIp]',
description: 'Stop a running container on a resinOS device',
help: '\nExamples:\n\n $ resin local stop\n $ resin local stop --app-name myapp\n $ resin local stop --all\n $ resin local stop 192.168.1.10\n $ resin local stop 192.168.1.10 --app-name myapp',
options: [
{
signature: 'all',
boolean: true,
description: 'stop all containers'
}, {
signature: 'app-name',
parameter: 'name',
description: 'name of container to stop',
alias: 'a'
}
};
}).call(this);
],
root: true,
action: function(params, options, done) {
var Promise, ResinLocalDockerUtils, chalk, config, filterOutSupervisorContainer, forms, ref, ref1, selectContainerFromDevice;
Promise = require('bluebird');
chalk = require('chalk');
ref = require('resin-sync'), forms = ref.forms, config = ref.config, ResinLocalDockerUtils = ref.ResinLocalDockerUtils;
ref1 = require('./common'), selectContainerFromDevice = ref1.selectContainerFromDevice, filterOutSupervisorContainer = ref1.filterOutSupervisorContainer;
return Promise["try"](function() {
if (params.deviceIp == null) {
return forms.selectLocalResinOsDevice();
}
return params.deviceIp;
}).then((function(_this) {
return function(deviceIp) {
var ref2, ref3, ymlConfig;
_this.deviceIp = deviceIp;
_this.docker = new ResinLocalDockerUtils(_this.deviceIp);
if (options.all) {
return _this.docker.docker.listContainersAsync({
all: false
}).filter(filterOutSupervisorContainer).then(function(containers) {
return Promise.map(containers, function(arg) {
var Id, Names;
Names = arg.Names, Id = arg.Id;
console.log(chalk.yellow.bold("* Stopping container " + Names[0]));
return _this.docker.stopContainer(Id);
});
});
}
ymlConfig = config.load();
_this.appName = (ref2 = options['app-name']) != null ? ref2 : (ref3 = ymlConfig['local_resinos']) != null ? ref3['app-name'] : void 0;
return _this.docker.checkForRunningContainer(_this.appName).then(function(isRunning) {
if (!isRunning) {
return selectContainerFromDevice(_this.deviceIp, true);
}
console.log(chalk.yellow.bold("* Stopping container " + _this.appName));
return _this.appName;
}).then(function(runningContainerName) {
return _this.docker.stopContainer(runningContainerName);
});
};
})(this));
}
};

View File

@ -15,45 +15,41 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function() {
module.exports = {
signature: 'logs <uuid>',
description: 'show device logs',
help: 'Use this command to show logs for a specific device.\n\nBy default, the command prints all log messages and exit.\n\nTo continuously stream output, and see new logs in real time, use the `--tail` option.\n\nNote that for now you need to provide the whole UUID for this command to work correctly.\n\nThis is due to some technical limitations that we plan to address soon.\n\nExamples:\n\n $ resin logs 23c73a1\n $ resin logs 23c73a1',
options: [
{
signature: 'tail',
description: 'continuously stream output',
boolean: true,
alias: 't'
}
],
permission: 'user',
primary: true,
action: function(params, options, done) {
var _, moment, printLine, promise, resin;
_ = require('lodash');
resin = require('resin-sdk-preconfigured');
moment = require('moment');
printLine = function(line) {
var timestamp;
timestamp = moment(line.timestamp).format('DD.MM.YY HH:mm:ss (ZZ)');
return console.log(timestamp + " " + line.message);
};
promise = resin.logs.history(params.uuid).each(printLine);
if (!options.tail) {
return promise["catch"](done)["finally"](function() {
return process.exit(0);
});
}
return promise.then(function() {
return resin.logs.subscribe(params.uuid).then(function(logs) {
logs.on('line', printLine);
return logs.on('error', done);
});
})["catch"](done);
module.exports = {
signature: 'logs <uuid>',
description: 'show device logs',
help: 'Use this command to show logs for a specific device.\n\nBy default, the command prints all log messages and exit.\n\nTo continuously stream output, and see new logs in real time, use the `--tail` option.\n\nNote that for now you need to provide the whole UUID for this command to work correctly.\n\nThis is due to some technical limitations that we plan to address soon.\n\nExamples:\n\n $ resin logs 23c73a1\n $ resin logs 23c73a1',
options: [
{
signature: 'tail',
description: 'continuously stream output',
boolean: true,
alias: 't'
}
};
}).call(this);
],
permission: 'user',
primary: true,
action: function(params, options, done) {
var _, moment, printLine, promise, resin;
_ = require('lodash');
resin = require('resin-sdk-preconfigured');
moment = require('moment');
printLine = function(line) {
var timestamp;
timestamp = moment(line.timestamp).format('DD.MM.YY HH:mm:ss (ZZ)');
return console.log(timestamp + " " + line.message);
};
promise = resin.logs.history(params.uuid).each(printLine);
if (!options.tail) {
return promise["catch"](done)["finally"](function() {
return process.exit(0);
});
}
return promise.then(function() {
return resin.logs.subscribe(params.uuid).then(function(logs) {
logs.on('line', printLine);
return logs.on('error', done);
});
})["catch"](done);
}
};

View File

@ -15,34 +15,30 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function() {
exports.set = {
signature: 'note <|note>',
description: 'set a device note',
help: 'Use this command to set or update a device note.\n\nIf note command isn\'t passed, the tool attempts to read from `stdin`.\n\nTo view the notes, use $ resin device <uuid>.\n\nExamples:\n\n $ resin note "My useful note" --device 7cf02a6\n $ cat note.txt | resin note --device 7cf02a6',
options: [
{
signature: 'device',
parameter: 'device',
description: 'device uuid',
alias: ['d', 'dev'],
required: 'You have to specify a device'
}
],
permission: 'user',
action: function(params, options, done) {
var Promise, _, resin;
Promise = require('bluebird');
_ = require('lodash');
resin = require('resin-sdk-preconfigured');
return Promise["try"](function() {
if (_.isEmpty(params.note)) {
throw new Error('Missing note content');
}
return resin.models.device.note(options.device, params.note);
}).nodeify(done);
exports.set = {
signature: 'note <|note>',
description: 'set a device note',
help: 'Use this command to set or update a device note.\n\nIf note command isn\'t passed, the tool attempts to read from `stdin`.\n\nTo view the notes, use $ resin device <uuid>.\n\nExamples:\n\n $ resin note "My useful note" --device 7cf02a6\n $ cat note.txt | resin note --device 7cf02a6',
options: [
{
signature: 'device',
parameter: 'device',
description: 'device uuid',
alias: ['d', 'dev'],
required: 'You have to specify a device'
}
};
}).call(this);
],
permission: 'user',
action: function(params, options, done) {
var Promise, _, resin;
Promise = require('bluebird');
_ = require('lodash');
resin = require('resin-sdk-preconfigured');
return Promise["try"](function() {
if (_.isEmpty(params.note)) {
throw new Error('Missing note content');
}
return resin.models.device.note(options.device, params.note);
}).nodeify(done);
}
};

View File

@ -15,180 +15,176 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var commandOptions, stepHandler;
(function() {
var commandOptions, stepHandler;
commandOptions = require('./command-options');
commandOptions = require('./command-options');
exports.download = {
signature: 'os download <type>',
description: 'download an unconfigured os image',
help: 'Use this command to download an unconfigured os image for a certain device type.\n\nExamples:\n\n $ resin os download parallella -o ../foo/bar/parallella.img',
permission: 'user',
options: [
{
signature: 'output',
description: 'output path',
parameter: 'output',
alias: 'o',
required: 'You have to specify an output location'
}
],
action: function(params, options, done) {
var fs, manager, rindle, unzip, visuals;
unzip = require('unzip2');
fs = require('fs');
rindle = require('rindle');
manager = require('resin-image-manager');
visuals = require('resin-cli-visuals');
console.info("Getting device operating system for " + params.type);
return manager.get(params.type).then(function(stream) {
var bar, output, spinner;
bar = new visuals.Progress('Downloading Device OS');
spinner = new visuals.Spinner('Downloading Device OS (size unknown)');
stream.on('progress', function(state) {
if (state != null) {
return bar.update(state);
} else {
return spinner.start();
}
});
stream.on('end', function() {
return spinner.stop();
});
if (stream.mime === 'application/zip') {
output = unzip.Extract({
path: options.output
});
} else {
output = fs.createWriteStream(options.output);
}
return rindle.wait(stream.pipe(output))["return"](options.output);
}).tap(function(output) {
return console.info('The image was downloaded successfully');
}).nodeify(done);
exports.download = {
signature: 'os download <type>',
description: 'download an unconfigured os image',
help: 'Use this command to download an unconfigured os image for a certain device type.\n\nExamples:\n\n $ resin os download parallella -o ../foo/bar/parallella.img',
permission: 'user',
options: [
{
signature: 'output',
description: 'output path',
parameter: 'output',
alias: 'o',
required: 'You have to specify the output location'
}
};
stepHandler = function(step) {
var _, bar, helpers, rindle, visuals;
_ = require('lodash');
],
action: function(params, options, done) {
var fs, manager, rindle, unzip, visuals;
unzip = require('unzip2');
fs = require('fs');
rindle = require('rindle');
manager = require('resin-image-manager');
visuals = require('resin-cli-visuals');
console.info("Getting device operating system for " + params.type);
return manager.get(params.type).then(function(stream) {
var bar, output, spinner;
bar = new visuals.Progress('Downloading Device OS');
spinner = new visuals.Spinner('Downloading Device OS (size unknown)');
stream.on('progress', function(state) {
if (state != null) {
return bar.update(state);
} else {
return spinner.start();
}
});
stream.on('end', function() {
return spinner.stop();
});
if (stream.mime === 'application/zip') {
output = unzip.Extract({
path: options.output
});
} else {
output = fs.createWriteStream(options.output);
}
return rindle.wait(stream.pipe(output))["return"](options.output);
}).tap(function(output) {
return console.info('The image was downloaded successfully');
}).nodeify(done);
}
};
stepHandler = function(step) {
var _, bar, helpers, rindle, visuals;
_ = require('lodash');
rindle = require('rindle');
visuals = require('resin-cli-visuals');
helpers = require('../utils/helpers');
step.on('stdout', _.bind(process.stdout.write, process.stdout));
step.on('stderr', _.bind(process.stderr.write, process.stderr));
step.on('state', function(state) {
if (state.operation.command === 'burn') {
return;
}
return console.log(helpers.stateToString(state));
});
bar = new visuals.Progress('Writing Device OS');
step.on('burn', _.bind(bar.update, bar));
return rindle.wait(step);
};
exports.configure = {
signature: 'os configure <image> <uuid>',
description: 'configure an os image',
help: 'Use this command to configure a previously download operating system image with a device.\n\nExamples:\n\n $ resin os configure ../path/rpi.img 7cf02a6',
permission: 'user',
options: [
{
signature: 'advanced',
description: 'show advanced commands',
boolean: true,
alias: 'v'
}
],
action: function(params, options, done) {
var _, form, helpers, init, resin;
_ = require('lodash');
resin = require('resin-sdk-preconfigured');
form = require('resin-cli-form');
init = require('resin-device-init');
helpers = require('../utils/helpers');
step.on('stdout', _.bind(process.stdout.write, process.stdout));
step.on('stderr', _.bind(process.stderr.write, process.stderr));
step.on('state', function(state) {
if (state.operation.command === 'burn') {
console.info('Configuring operating system image');
return resin.models.device.get(params.uuid).then(function(device) {
return helpers.getManifest(params.image, device.device_type).get('options').then(function(questions) {
var advancedGroup, override;
if (!options.advanced) {
advancedGroup = _.findWhere(questions, {
name: 'advanced',
isGroup: true
});
if (advancedGroup != null) {
override = helpers.getGroupDefaults(advancedGroup);
}
}
return form.run(questions, {
override: override
});
}).then(function(answers) {
return init.configure(params.image, params.uuid, answers).then(stepHandler);
});
}).nodeify(done);
}
};
exports.initialize = {
signature: 'os initialize <image>',
description: 'initialize an os image',
help: 'Use this command to initialize a previously configured operating system image.\n\nExamples:\n\n $ resin os initialize ../path/rpi.img --type \'raspberry-pi\'',
permission: 'user',
options: [
commandOptions.yes, {
signature: 'type',
description: 'device type',
parameter: 'type',
alias: 't',
required: 'You have to specify a device type'
}, {
signature: 'drive',
description: 'drive',
parameter: 'drive',
alias: 'd'
}
],
root: true,
action: function(params, options, done) {
var Promise, form, helpers, init, patterns, umount;
Promise = require('bluebird');
umount = Promise.promisifyAll(require('umount'));
form = require('resin-cli-form');
init = require('resin-device-init');
patterns = require('../utils/patterns');
helpers = require('../utils/helpers');
console.info('Initializing device');
return helpers.getManifest(params.image, options.type).then(function(manifest) {
var ref;
return (ref = manifest.initialization) != null ? ref.options : void 0;
}).then(function(questions) {
return form.run(questions, {
override: {
drive: options.drive
}
});
}).tap(function(answers) {
var message;
if (answers.drive == null) {
return;
}
return console.log(helpers.stateToString(state));
});
bar = new visuals.Progress('Writing Device OS');
step.on('burn', _.bind(bar.update, bar));
return rindle.wait(step);
};
exports.configure = {
signature: 'os configure <image> <uuid>',
description: 'configure an os image',
help: 'Use this command to configure a previously download operating system image with a device.\n\nExamples:\n\n $ resin os configure ../path/rpi.img 7cf02a6',
permission: 'user',
options: [
{
signature: 'advanced',
description: 'show advanced commands',
boolean: true,
alias: 'v'
message = "This will erase " + answers.drive + ". Are you sure?";
return patterns.confirm(options.yes, message)["return"](answers.drive).then(umount.umountAsync);
}).tap(function(answers) {
return init.initialize(params.image, options.type, answers).then(stepHandler);
}).then(function(answers) {
if (answers.drive == null) {
return;
}
],
action: function(params, options, done) {
var _, form, helpers, init, resin;
_ = require('lodash');
resin = require('resin-sdk-preconfigured');
form = require('resin-cli-form');
init = require('resin-device-init');
helpers = require('../utils/helpers');
console.info('Configuring operating system image');
return resin.models.device.get(params.uuid).then(function(device) {
return helpers.getManifest(params.image, device.device_type).get('options').then(function(questions) {
var advancedGroup, override;
if (!options.advanced) {
advancedGroup = _.findWhere(questions, {
name: 'advanced',
isGroup: true
});
if (advancedGroup != null) {
override = helpers.getGroupDefaults(advancedGroup);
}
}
return form.run(questions, {
override: override
});
}).then(function(answers) {
return init.configure(params.image, params.uuid, answers).then(stepHandler);
});
}).nodeify(done);
}
};
exports.initialize = {
signature: 'os initialize <image>',
description: 'initialize an os image',
help: 'Use this command to initialize a previously configured operating system image.\n\nExamples:\n\n $ resin os initialize ../path/rpi.img --type \'raspberry-pi\'',
permission: 'user',
options: [
commandOptions.yes, {
signature: 'type',
description: 'device type',
parameter: 'type',
alias: 't',
required: 'You have to specify a device type'
}, {
signature: 'drive',
description: 'drive',
parameter: 'drive',
alias: 'd'
}
],
root: true,
action: function(params, options, done) {
var Promise, form, helpers, init, patterns, umount;
Promise = require('bluebird');
umount = Promise.promisifyAll(require('umount'));
form = require('resin-cli-form');
init = require('resin-device-init');
patterns = require('../utils/patterns');
helpers = require('../utils/helpers');
console.info('Initializing device');
return helpers.getManifest(params.image, options.type).then(function(manifest) {
var ref;
return (ref = manifest.initialization) != null ? ref.options : void 0;
}).then(function(questions) {
return form.run(questions, {
override: {
drive: options.drive
}
});
}).tap(function(answers) {
var message;
if (answers.drive == null) {
return;
}
message = "This will erase " + answers.drive + ". Are you sure?";
return patterns.confirm(options.yes, message)["return"](answers.drive).then(umount.umountAsync);
}).tap(function(answers) {
return init.initialize(params.image, options.type, answers).then(stepHandler);
}).then(function(answers) {
if (answers.drive == null) {
return;
}
return umount.umountAsync(answers.drive).tap(function() {
return console.info("You can safely remove " + answers.drive + " now");
});
}).nodeify(done);
}
};
}).call(this);
return umount.umountAsync(answers.drive).tap(function() {
return console.info("You can safely remove " + answers.drive + " now");
});
}).nodeify(done);
}
};

View File

@ -15,18 +15,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function() {
exports.list = {
signature: 'settings',
description: 'print current settings',
help: 'Use this command to display detected settings\n\nExamples:\n\n $ resin settings',
action: function(params, options, done) {
var prettyjson, resin;
resin = require('resin-sdk-preconfigured');
prettyjson = require('prettyjson');
return resin.settings.getAll().then(prettyjson.render).then(console.log).nodeify(done);
}
};
}).call(this);
exports.list = {
signature: 'settings',
description: 'print current settings',
help: 'Use this command to display detected settings\n\nExamples:\n\n $ resin settings',
action: function(params, options, done) {
var prettyjson, resin;
resin = require('resin-sdk-preconfigured');
prettyjson = require('prettyjson');
return resin.settings.getAll().then(prettyjson.render).then(console.log).nodeify(done);
}
};

View File

@ -15,94 +15,90 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var getSubShellCommand;
(function() {
var getSubShellCommand;
getSubShellCommand = function(command) {
var os;
os = require('os');
if (os.platform() === 'win32') {
return {
program: 'cmd.exe',
args: ['/s', '/c', command]
};
} else {
return {
program: '/bin/sh',
args: ['-c', command]
};
}
};
getSubShellCommand = function(command) {
var os;
os = require('os');
if (os.platform() === 'win32') {
return {
program: 'cmd.exe',
args: ['/s', '/c', command]
};
} else {
return {
program: '/bin/sh',
args: ['-c', command]
};
module.exports = {
signature: 'ssh [uuid]',
description: '(beta) get a shell into the running app container of a device',
help: 'Warning: \'resin ssh\' requires an openssh-compatible client to be correctly\ninstalled in your shell environment. For more information (including Windows\nsupport) please check the README here: https://github.com/resin-io/resin-cli\n\nUse this command to get a shell into the running application container of\nyour device.\n\nExamples:\n\n $ resin ssh MyApp\n $ resin ssh 7cf02a6\n $ resin ssh 7cf02a6 --port 8080\n $ resin ssh 7cf02a6 -v',
permission: 'user',
primary: true,
options: [
{
signature: 'port',
parameter: 'port',
description: 'ssh gateway port',
alias: 'p'
}, {
signature: 'verbose',
boolean: true,
description: 'increase verbosity',
alias: 'v'
}
};
module.exports = {
signature: 'ssh [uuid]',
description: '(beta) get a shell into the running app container of a device',
help: 'Warning: \'resin ssh\' requires an openssh-compatible client to be correctly\ninstalled in your shell environment. For more information (including Windows\nsupport) please check the README here: https://github.com/resin-io/resin-cli\n\nUse this command to get a shell into the running application container of\nyour device.\n\nExamples:\n\n $ resin ssh MyApp\n $ resin ssh 7cf02a6\n $ resin ssh 7cf02a6 --port 8080\n $ resin ssh 7cf02a6 -v',
permission: 'user',
primary: true,
options: [
{
signature: 'port',
parameter: 'port',
description: 'ssh gateway port',
alias: 'p'
}, {
signature: 'verbose',
boolean: true,
description: 'increase verbosity',
alias: 'v'
],
action: function(params, options, done) {
var Promise, child_process, patterns, resin, settings, verbose;
child_process = require('child_process');
Promise = require('bluebird');
resin = require('resin-sdk-preconfigured');
settings = require('resin-settings-client');
patterns = require('../utils/patterns');
if (options.port == null) {
options.port = 22;
}
verbose = options.verbose ? '-vvv' : '';
return Promise["try"](function() {
if (!params.uuid) {
return false;
}
],
action: function(params, options, done) {
var Promise, child_process, patterns, resin, settings, verbose;
child_process = require('child_process');
Promise = require('bluebird');
resin = require('resin-sdk-preconfigured');
settings = require('resin-settings-client');
patterns = require('../utils/patterns');
if (options.port == null) {
options.port = 22;
return resin.models.device.has(params.uuid);
}).then(function(uuidExists) {
if (uuidExists) {
return params.uuid;
}
verbose = options.verbose ? '-vvv' : '';
return Promise["try"](function() {
if (!params.uuid) {
return false;
return patterns.inferOrSelectDevice();
}).then(function(uuid) {
console.info("Connecting with: " + uuid);
return resin.models.device.get(uuid);
}).then(function(device) {
if (!device.is_online) {
throw new Error('Device is not online');
}
return Promise.props({
username: resin.auth.whoami(),
uuid: device.uuid,
containerId: resin.models.device.getApplicationInfo(device.uuid).get('containerId')
}).then(function(arg) {
var containerId, username, uuid;
username = arg.username, uuid = arg.uuid, containerId = arg.containerId;
if (containerId == null) {
throw new Error('Did not find running application container');
}
return resin.models.device.has(params.uuid);
}).then(function(uuidExists) {
if (uuidExists) {
return params.uuid;
}
return patterns.inferOrSelectDevice();
}).then(function(uuid) {
console.info("Connecting with: " + uuid);
return resin.models.device.get(uuid);
}).then(function(device) {
if (!device.is_online) {
throw new Error('Device is not online');
}
return Promise.props({
username: resin.auth.whoami(),
uuid: device.uuid,
containerId: resin.models.device.getApplicationInfo(device.uuid).get('containerId')
}).then(function(arg) {
var containerId, username, uuid;
username = arg.username, uuid = arg.uuid, containerId = arg.containerId;
if (containerId == null) {
throw new Error('Did not find running application container');
}
return Promise["try"](function() {
var command, subShellCommand;
command = "ssh " + verbose + " -t -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ControlMaster=no -p " + options.port + " " + username + "@ssh." + (settings.get('proxyUrl')) + " enter " + uuid + " " + containerId;
subShellCommand = getSubShellCommand(command);
return child_process.spawn(subShellCommand.program, subShellCommand.args, {
stdio: 'inherit'
});
return Promise["try"](function() {
var command, subShellCommand;
command = "ssh " + verbose + " -t -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ControlMaster=no -p " + options.port + " " + username + "@ssh." + (settings.get('proxyUrl')) + " enter " + uuid + " " + containerId;
subShellCommand = getSubShellCommand(command);
return child_process.spawn(subShellCommand.program, subShellCommand.args, {
stdio: 'inherit'
});
});
}).nodeify(done);
}
};
}).call(this);
});
}).nodeify(done);
}
};

View File

@ -15,8 +15,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function() {
module.exports = require('resin-sync').capitano('resin-cli');
}).call(this);
module.exports = require('resin-sync').capitano('resin-cli');

View File

@ -15,50 +15,46 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function() {
exports.wizard = {
signature: 'quickstart [name]',
description: 'getting started with resin.io',
help: 'Use this command to run a friendly wizard to get started with resin.io.\n\nThe wizard will guide you through:\n\n - Create an application.\n - Initialise an SDCard with the resin.io operating system.\n - Associate an existing project directory with your resin.io application.\n - Push your project to your devices.\n\nExamples:\n\n $ resin quickstart\n $ resin quickstart MyApp',
primary: true,
action: function(params, options, done) {
var Promise, capitano, patterns, resin;
Promise = require('bluebird');
capitano = Promise.promisifyAll(require('capitano'));
resin = require('resin-sdk-preconfigured');
patterns = require('../utils/patterns');
return resin.auth.isLoggedIn().then(function(isLoggedIn) {
if (isLoggedIn) {
return;
}
console.info('Looks like you\'re not logged in yet!');
console.info('Lets go through a quick wizard to get you started.\n');
return capitano.runAsync('login');
}).then(function() {
if (params.name != null) {
return;
}
return patterns.selectOrCreateApplication().tap(function(applicationName) {
return resin.models.application.has(applicationName).then(function(hasApplication) {
if (hasApplication) {
return applicationName;
}
return capitano.runAsync("app create " + applicationName);
});
}).then(function(applicationName) {
return params.name = applicationName;
exports.wizard = {
signature: 'quickstart [name]',
description: 'getting started with resin.io',
help: 'Use this command to run a friendly wizard to get started with resin.io.\n\nThe wizard will guide you through:\n\n - Create an application.\n - Initialise an SDCard with the resin.io operating system.\n - Associate an existing project directory with your resin.io application.\n - Push your project to your devices.\n\nExamples:\n\n $ resin quickstart\n $ resin quickstart MyApp',
primary: true,
action: function(params, options, done) {
var Promise, capitano, patterns, resin;
Promise = require('bluebird');
capitano = Promise.promisifyAll(require('capitano'));
resin = require('resin-sdk-preconfigured');
patterns = require('../utils/patterns');
return resin.auth.isLoggedIn().then(function(isLoggedIn) {
if (isLoggedIn) {
return;
}
console.info('Looks like you\'re not logged in yet!');
console.info('Lets go through a quick wizard to get you started.\n');
return capitano.runAsync('login');
}).then(function() {
if (params.name != null) {
return;
}
return patterns.selectOrCreateApplication().tap(function(applicationName) {
return resin.models.application.has(applicationName).then(function(hasApplication) {
if (hasApplication) {
return applicationName;
}
return capitano.runAsync("app create " + applicationName);
});
}).then(function() {
return capitano.runAsync("device init --application " + params.name);
}).tap(patterns.awaitDevice).then(function(uuid) {
return capitano.runAsync("device " + uuid);
}).then(function() {
return resin.models.application.get(params.name);
}).then(function(application) {
return console.log("Your device is ready to start pushing some code!\n\nCheck our official documentation for more information:\n\n http://docs.resin.io/#/pages/introduction/introduction.md\n\nClone an example or go to an existing application directory and run:\n\n $ git remote add resin " + application.git_repository + "\n $ git push resin master");
}).nodeify(done);
}
};
}).call(this);
}).then(function(applicationName) {
return params.name = applicationName;
});
}).then(function() {
return capitano.runAsync("device init --application " + params.name);
}).tap(patterns.awaitDevice).then(function(uuid) {
return capitano.runAsync("device " + uuid);
}).then(function() {
return resin.models.application.get(params.name);
}).then(function(application) {
return console.log("Your device is ready to start pushing some code!\n\nCheck our official documentation for more information:\n\n http://docs.resin.io/#/pages/introduction/introduction.md\n\nClone an example or go to an existing application directory and run:\n\n $ git remote add resin " + application.git_repository + "\n $ git push resin master");
}).nodeify(done);
}
};

View File

@ -15,177 +15,173 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var Promise, _, actions, capitano, errors, events, plugins, resin, update;
(function() {
var Promise, _, actions, capitano, errors, events, plugins, resin, update;
_ = require('lodash');
_ = require('lodash');
Promise = require('bluebird');
Promise = require('bluebird');
capitano = Promise.promisifyAll(require('capitano'));
capitano = Promise.promisifyAll(require('capitano'));
resin = require('resin-sdk-preconfigured');
resin = require('resin-sdk-preconfigured');
actions = require('./actions');
actions = require('./actions');
errors = require('./errors');
errors = require('./errors');
events = require('./events');
events = require('./events');
plugins = require('./utils/plugins');
plugins = require('./utils/plugins');
update = require('./utils/update');
update = require('./utils/update');
capitano.permission('user', function(done) {
return resin.auth.isLoggedIn().then(function(isLoggedIn) {
if (!isLoggedIn) {
throw new Error('You have to log in to continue\n\nRun the following command to go through the login wizard:\n\n $ resin login');
}
}).nodeify(done);
});
capitano.permission('user', function(done) {
return resin.auth.isLoggedIn().then(function(isLoggedIn) {
if (!isLoggedIn) {
throw new Error('You have to log in to continue\n\nRun the following command to go through the login wizard:\n\n $ resin login');
}
}).nodeify(done);
});
capitano.command({
signature: '*',
action: function() {
return capitano.execute({
command: 'help'
});
}
});
capitano.command({
signature: '*',
action: function() {
return capitano.execute({
command: 'help'
capitano.globalOption({
signature: 'help',
boolean: true,
alias: 'h'
});
capitano.command(actions.info.version);
capitano.command(actions.help.help);
capitano.command(actions.wizard.wizard);
capitano.command(actions.auth.login);
capitano.command(actions.auth.logout);
capitano.command(actions.auth.signup);
capitano.command(actions.auth.whoami);
capitano.command(actions.app.create);
capitano.command(actions.app.list);
capitano.command(actions.app.remove);
capitano.command(actions.app.restart);
capitano.command(actions.app.info);
capitano.command(actions.device.list);
capitano.command(actions.device.supported);
capitano.command(actions.device.rename);
capitano.command(actions.device.init);
capitano.command(actions.device.remove);
capitano.command(actions.device.identify);
capitano.command(actions.device.reboot);
capitano.command(actions.device.shutdown);
capitano.command(actions.device.enableDeviceUrl);
capitano.command(actions.device.disableDeviceUrl);
capitano.command(actions.device.getDeviceUrl);
capitano.command(actions.device.hasDeviceUrl);
capitano.command(actions.device.register);
capitano.command(actions.device.move);
capitano.command(actions.device.info);
capitano.command(actions.notes.set);
capitano.command(actions.keys.list);
capitano.command(actions.keys.add);
capitano.command(actions.keys.info);
capitano.command(actions.keys.remove);
capitano.command(actions.env.list);
capitano.command(actions.env.add);
capitano.command(actions.env.rename);
capitano.command(actions.env.remove);
capitano.command(actions.os.download);
capitano.command(actions.os.configure);
capitano.command(actions.os.initialize);
capitano.command(actions.config.read);
capitano.command(actions.config.write);
capitano.command(actions.config.inject);
capitano.command(actions.config.reconfigure);
capitano.command(actions.config.generate);
capitano.command(actions.settings.list);
capitano.command(actions.logs);
capitano.command(actions.sync);
capitano.command(actions.ssh);
capitano.command(actions.local.configure);
capitano.command(actions.local.flash);
capitano.command(actions.local.logs);
capitano.command(actions.local.promote);
capitano.command(actions.local.push);
capitano.command(actions.local.ssh);
capitano.command(actions.local.scan);
capitano.command(actions.local.stop);
update.notify();
plugins.register(/^resin-plugin-(.+)$/).then(function() {
var cli;
cli = capitano.parse(process.argv);
return events.trackCommand(cli).then(function() {
var ref, ref1;
if ((ref = cli.global) != null ? ref.help : void 0) {
return capitano.executeAsync({
command: "help " + ((ref1 = cli.command) != null ? ref1 : '')
});
}
return capitano.executeAsync(cli);
});
capitano.globalOption({
signature: 'help',
boolean: true,
alias: 'h'
});
capitano.command(actions.info.version);
capitano.command(actions.help.help);
capitano.command(actions.wizard.wizard);
capitano.command(actions.auth.login);
capitano.command(actions.auth.logout);
capitano.command(actions.auth.signup);
capitano.command(actions.auth.whoami);
capitano.command(actions.app.create);
capitano.command(actions.app.list);
capitano.command(actions.app.remove);
capitano.command(actions.app.restart);
capitano.command(actions.app.info);
capitano.command(actions.device.list);
capitano.command(actions.device.supported);
capitano.command(actions.device.rename);
capitano.command(actions.device.init);
capitano.command(actions.device.remove);
capitano.command(actions.device.identify);
capitano.command(actions.device.reboot);
capitano.command(actions.device.shutdown);
capitano.command(actions.device.enableDeviceUrl);
capitano.command(actions.device.disableDeviceUrl);
capitano.command(actions.device.getDeviceUrl);
capitano.command(actions.device.hasDeviceUrl);
capitano.command(actions.device.register);
capitano.command(actions.device.move);
capitano.command(actions.device.info);
capitano.command(actions.notes.set);
capitano.command(actions.keys.list);
capitano.command(actions.keys.add);
capitano.command(actions.keys.info);
capitano.command(actions.keys.remove);
capitano.command(actions.env.list);
capitano.command(actions.env.add);
capitano.command(actions.env.rename);
capitano.command(actions.env.remove);
capitano.command(actions.os.download);
capitano.command(actions.os.configure);
capitano.command(actions.os.initialize);
capitano.command(actions.config.read);
capitano.command(actions.config.write);
capitano.command(actions.config.inject);
capitano.command(actions.config.reconfigure);
capitano.command(actions.config.generate);
capitano.command(actions.settings.list);
capitano.command(actions.logs);
capitano.command(actions.sync);
capitano.command(actions.ssh);
capitano.command(actions.local.configure);
capitano.command(actions.local.flash);
capitano.command(actions.local.logs);
capitano.command(actions.local.promote);
capitano.command(actions.local.push);
capitano.command(actions.local.ssh);
capitano.command(actions.local.scan);
capitano.command(actions.local.stop);
update.notify();
plugins.register(/^resin-plugin-(.+)$/).then(function() {
var cli;
cli = capitano.parse(process.argv);
return events.trackCommand(cli).then(function() {
var ref, ref1;
if ((ref = cli.global) != null ? ref.help : void 0) {
return capitano.executeAsync({
command: "help " + ((ref1 = cli.command) != null ? ref1 : '')
});
}
return capitano.executeAsync(cli);
});
})["catch"](errors.handle);
}).call(this);
})["catch"](errors.handle);

View File

@ -15,27 +15,23 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var chalk, errors, patterns;
(function() {
var chalk, errors, patterns;
chalk = require('chalk');
chalk = require('chalk');
errors = require('resin-cli-errors');
errors = require('resin-cli-errors');
patterns = require('./utils/patterns');
patterns = require('./utils/patterns');
exports.handle = function(error) {
var message;
message = errors.interpret(error);
if (message == null) {
return;
}
if (process.env.DEBUG) {
message = error.stack;
}
patterns.printErrorMessage(message);
return process.exit(error.exitCode || 1);
};
}).call(this);
exports.handle = function(error) {
var message;
message = errors.interpret(error);
if (message == null) {
return;
}
if (process.env.DEBUG) {
message = error.stack;
}
patterns.printErrorMessage(message);
return process.exit(error.exitCode || 1);
};

View File

@ -1,42 +1,39 @@
// Generated by CoffeeScript 1.12.4
(function() {
var Mixpanel, Promise, _, capitanoState, packageJSON, resin;
var Mixpanel, Promise, _, capitanoState, packageJSON, resin;
_ = require('lodash');
_ = require('lodash');
Mixpanel = require('mixpanel');
Mixpanel = require('mixpanel');
Promise = require('bluebird');
Promise = require('bluebird');
resin = require('resin-sdk-preconfigured');
resin = require('resin-sdk-preconfigured');
capitanoState = Promise.promisifyAll(require('capitano').state);
capitanoState = Promise.promisifyAll(require('capitano').state);
packageJSON = require('../package.json');
packageJSON = require('../package.json');
exports.getLoggerInstance = _.memoize(function() {
return resin.models.config.getMixpanelToken().then(Mixpanel.init);
});
exports.getLoggerInstance = _.memoize(function() {
return resin.models.config.getMixpanelToken().then(Mixpanel.init);
});
exports.trackCommand = function(capitanoCommand) {
return Promise.props({
resinUrl: resin.settings.get('resinUrl'),
username: resin.auth.whoami(),
mixpanel: exports.getLoggerInstance()
}).then(function(data) {
return capitanoState.getMatchCommandAsync(capitanoCommand.command).then(function(command) {
return data.mixpanel.track("[CLI] " + (command.signature.toString()), {
distinct_id: data.username,
argv: process.argv.join(' '),
version: packageJSON.version,
node: process.version,
arch: process.arch,
resinUrl: data.resinUrl,
platform: process.platform,
command: capitanoCommand
});
exports.trackCommand = function(capitanoCommand) {
return Promise.props({
resinUrl: resin.settings.get('resinUrl'),
username: resin.auth.whoami(),
mixpanel: exports.getLoggerInstance()
}).then(function(data) {
return capitanoState.getMatchCommandAsync(capitanoCommand.command).then(function(command) {
return data.mixpanel.track("[CLI] " + (command.signature.toString()), {
distinct_id: data.username,
argv: process.argv.join(' '),
version: packageJSON.version,
node: process.version,
arch: process.arch,
resinUrl: data.resinUrl,
platform: process.platform,
command: capitanoCommand
});
});
};
}).call(this);
});
};

View File

@ -15,71 +15,67 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var Promise, _, capitano, chalk, imagefs, os, president, resin, rindle;
(function() {
var Promise, _, capitano, chalk, imagefs, os, president, resin, rindle;
Promise = require('bluebird');
Promise = require('bluebird');
capitano = Promise.promisifyAll(require('capitano'));
capitano = Promise.promisifyAll(require('capitano'));
_ = require('lodash');
_ = require('lodash');
_.str = require('underscore.string');
_.str = require('underscore.string');
president = Promise.promisifyAll(require('president'));
president = Promise.promisifyAll(require('president'));
resin = require('resin-sdk-preconfigured');
resin = require('resin-sdk-preconfigured');
imagefs = require('resin-image-fs');
imagefs = require('resin-image-fs');
rindle = require('rindle');
rindle = require('rindle');
os = require('os');
os = require('os');
chalk = require('chalk');
chalk = require('chalk');
exports.getGroupDefaults = function(group) {
return _.chain(group).get('options').map(function(question) {
return [question.name, question["default"]];
}).object().value();
};
exports.getGroupDefaults = function(group) {
return _.chain(group).get('options').map(function(question) {
return [question.name, question["default"]];
}).object().value();
};
exports.stateToString = function(state) {
var percentage, result;
percentage = _.str.lpad(state.percentage, 3, '0') + '%';
result = (chalk.blue(percentage)) + " " + (chalk.cyan(state.operation.command));
switch (state.operation.command) {
case 'copy':
return result + " " + state.operation.from.path + " -> " + state.operation.to.path;
case 'replace':
return result + " " + state.operation.file.path + ", " + state.operation.copy + " -> " + state.operation.replace;
case 'run-script':
return result + " " + state.operation.script;
default:
throw new Error("Unsupported operation: " + state.operation.type);
}
};
exports.stateToString = function(state) {
var percentage, result;
percentage = _.str.lpad(state.percentage, 3, '0') + '%';
result = (chalk.blue(percentage)) + " " + (chalk.cyan(state.operation.command));
switch (state.operation.command) {
case 'copy':
return result + " " + state.operation.from.path + " -> " + state.operation.to.path;
case 'replace':
return result + " " + state.operation.file.path + ", " + state.operation.copy + " -> " + state.operation.replace;
case 'run-script':
return result + " " + state.operation.script;
default:
throw new Error("Unsupported operation: " + state.operation.type);
}
};
exports.sudo = function(command, message) {
command = _.union(_.take(process.argv, 2), command);
console.log(message);
if (os.platform() !== 'win32') {
console.log('Type your computer password to continue');
}
return president.executeAsync(command);
};
exports.sudo = function(command, message) {
command = _.union(_.take(process.argv, 2), command);
console.log(message);
if (os.platform() !== 'win32') {
console.log('Type your computer password to continue');
}
return president.executeAsync(command);
};
exports.getManifest = function(image, deviceType) {
return imagefs.read({
image: image,
partition: {
primary: 1
},
path: '/device-type.json'
}).then(rindle.extractAsync).then(JSON.parse)["catch"](function() {
return resin.models.device.getManifestBySlug(deviceType);
});
};
}).call(this);
exports.getManifest = function(image, deviceType) {
return imagefs.read({
image: image,
partition: {
primary: 1
},
path: '/device-type.json'
}).then(rindle.extractAsync).then(JSON.parse)["catch"](function() {
return resin.models.device.getManifestBySlug(deviceType);
});
};

View File

@ -1,11 +1,8 @@
// Generated by CoffeeScript 1.12.4
(function() {
exports.gettingStarted = 'Run the following command to get a device started with Resin.io\n\n $ resin quickstart';
exports.gettingStarted = 'Run the following command to get a device started with Resin.io\n\n $ resin quickstart';
exports.reachingOut = 'If you need help, or just want to say hi, don\'t hesitate in reaching out at:\n\n GitHub: https://github.com/resin-io/resin-cli/issues/new\n Gitter: https://gitter.im/resin-io/chat';
exports.reachingOut = 'If you need help, or just want to say hi, don\'t hesitate in reaching out at:\n\n GitHub: https://github.com/resin-io/resin-cli/issues/new\n Gitter: https://gitter.im/resin-io/chat';
exports.getHelp = 'If you need help, don\'t hesitate in contacting us at:\n\n GitHub: https://github.com/resin-io/resin-cli/issues/new\n Gitter: https://gitter.im/resin-io/chat';
exports.getHelp = 'If you need help, don\'t hesitate in contacting us at:\n\n GitHub: https://github.com/resin-io/resin-cli/issues/new\n Gitter: https://gitter.im/resin-io/chat';
exports.resinAsciiArt = '______ _ _\n| ___ \\ (_) (_)\n| |_/ /___ ___ _ _ __ _ ___\n| // _ \\/ __| | \'_ \\ | |/ _ \\\n| |\\ \\ __/\\__ \\ | | | |_| | (_) |\n\\_| \\_\\___||___/_|_| |_(_)_|\\___/';
}).call(this);
exports.resinAsciiArt = '______ _ _\n| ___ \\ (_) (_)\n| |_/ /___ ___ _ _ __ _ ___\n| // _ \\/ __| | \'_ \\ | |/ _ \\\n| |\\ \\ __/\\__ \\ | | | |_| | (_) |\n\\_| \\_\\___||___/_|_| |_(_)_|\\___/';

View File

@ -15,208 +15,204 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var Promise, _, chalk, form, messages, resin, validation, visuals,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
(function() {
var Promise, _, chalk, form, messages, resin, validation, visuals,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
_ = require('lodash');
_ = require('lodash');
Promise = require('bluebird');
Promise = require('bluebird');
form = require('resin-cli-form');
form = require('resin-cli-form');
visuals = require('resin-cli-visuals');
visuals = require('resin-cli-visuals');
resin = require('resin-sdk-preconfigured');
resin = require('resin-sdk-preconfigured');
chalk = require('chalk');
chalk = require('chalk');
validation = require('./validation');
validation = require('./validation');
messages = require('./messages');
messages = require('./messages');
exports.authenticate = function(options) {
return form.run([
{
message: 'Email:',
name: 'email',
type: 'input',
validate: validation.validateEmail
}, {
message: 'Password:',
name: 'password',
type: 'password'
}
], {
override: options
}).then(resin.auth.login).then(resin.auth.twoFactor.isPassed).then(function(isTwoFactorAuthPassed) {
if (isTwoFactorAuthPassed) {
return;
}
return form.ask({
message: 'Two factor auth challenge:',
name: 'code',
type: 'input'
}).then(resin.auth.twoFactor.challenge)["catch"](function(error) {
return resin.auth.logout().then(function() {
if (error.name === 'ResinRequestError' && error.statusCode === 401) {
throw new Error('Invalid two factor authentication code');
}
throw error;
});
});
});
};
exports.askLoginType = function() {
exports.authenticate = function(options) {
return form.run([
{
message: 'Email:',
name: 'email',
type: 'input',
validate: validation.validateEmail
}, {
message: 'Password:',
name: 'password',
type: 'password'
}
], {
override: options
}).then(resin.auth.login).then(resin.auth.twoFactor.isPassed).then(function(isTwoFactorAuthPassed) {
if (isTwoFactorAuthPassed) {
return;
}
return form.ask({
message: 'How would you like to login?',
name: 'loginType',
type: 'list',
choices: [
{
name: 'Web authorization (recommended)',
value: 'web'
}, {
name: 'Credentials',
value: 'credentials'
}, {
name: 'Authentication token',
value: 'token'
}, {
name: 'I don\'t have a Resin account!',
value: 'register'
message: 'Two factor auth challenge:',
name: 'code',
type: 'input'
}).then(resin.auth.twoFactor.challenge)["catch"](function(error) {
return resin.auth.logout().then(function() {
if (error.name === 'ResinRequestError' && error.statusCode === 401) {
throw new Error('Invalid two factor authentication code');
}
]
});
};
exports.selectDeviceType = function() {
return resin.models.device.getSupportedDeviceTypes().then(function(deviceTypes) {
return form.ask({
message: 'Device Type',
type: 'list',
choices: deviceTypes
throw error;
});
});
};
});
};
exports.confirm = function(yesOption, message) {
return Promise["try"](function() {
if (yesOption) {
return true;
}
return form.ask({
message: message,
type: 'confirm',
"default": false
});
}).then(function(confirmed) {
if (!confirmed) {
throw new Error('Aborted');
exports.askLoginType = function() {
return form.ask({
message: 'How would you like to login?',
name: 'loginType',
type: 'list',
choices: [
{
name: 'Web authorization (recommended)',
value: 'web'
}, {
name: 'Credentials',
value: 'credentials'
}, {
name: 'Authentication token',
value: 'token'
}, {
name: 'I don\'t have a Resin account!',
value: 'register'
}
]
});
};
exports.selectDeviceType = function() {
return resin.models.device.getSupportedDeviceTypes().then(function(deviceTypes) {
return form.ask({
message: 'Device Type',
type: 'list',
choices: deviceTypes
});
};
});
};
exports.selectApplication = function(filter) {
return resin.models.application.hasAny().then(function(hasAnyApplications) {
if (!hasAnyApplications) {
throw new Error('You don\'t have any applications');
}
return resin.models.application.getAll();
}).filter(filter || _.constant(true)).then(function(applications) {
exports.confirm = function(yesOption, message) {
return Promise["try"](function() {
if (yesOption) {
return true;
}
return form.ask({
message: message,
type: 'confirm',
"default": false
});
}).then(function(confirmed) {
if (!confirmed) {
throw new Error('Aborted');
}
});
};
exports.selectApplication = function(filter) {
return resin.models.application.hasAny().then(function(hasAnyApplications) {
if (!hasAnyApplications) {
throw new Error('You don\'t have any applications');
}
return resin.models.application.getAll();
}).filter(filter || _.constant(true)).then(function(applications) {
return form.ask({
message: 'Select an application',
type: 'list',
choices: _.map(applications, function(application) {
return {
name: application.app_name + " (" + application.device_type + ")",
value: application.app_name
};
})
});
});
};
exports.selectOrCreateApplication = function() {
return resin.models.application.hasAny().then(function(hasAnyApplications) {
if (!hasAnyApplications) {
return;
}
return resin.models.application.getAll().then(function(applications) {
applications = _.map(applications, function(application) {
return {
name: application.app_name + " (" + application.device_type + ")",
value: application.app_name
};
});
applications.unshift({
name: 'Create a new application',
value: null
});
return form.ask({
message: 'Select an application',
type: 'list',
choices: _.map(applications, function(application) {
return {
name: application.app_name + " (" + application.device_type + ")",
value: application.app_name
};
})
choices: applications
});
});
};
exports.selectOrCreateApplication = function() {
return resin.models.application.hasAny().then(function(hasAnyApplications) {
if (!hasAnyApplications) {
return;
}
return resin.models.application.getAll().then(function(applications) {
applications = _.map(applications, function(application) {
return {
name: application.app_name + " (" + application.device_type + ")",
value: application.app_name
};
});
applications.unshift({
name: 'Create a new application',
value: null
});
return form.ask({
message: 'Select an application',
type: 'list',
choices: applications
});
});
}).then(function(application) {
if (application != null) {
return application;
}
return form.ask({
message: 'Choose a Name for your new application',
type: 'input',
validate: validation.validateApplicationName
});
}).then(function(application) {
if (application != null) {
return application;
}
return form.ask({
message: 'Choose a Name for your new application',
type: 'input',
validate: validation.validateApplicationName
});
};
});
};
exports.awaitDevice = function(uuid) {
return resin.models.device.getName(uuid).then(function(deviceName) {
var poll, spinner;
spinner = new visuals.Spinner("Waiting for " + deviceName + " to come online");
poll = function() {
return resin.models.device.isOnline(uuid).then(function(isOnline) {
if (isOnline) {
spinner.stop();
console.info("The device **" + deviceName + "** is online!");
} else {
spinner.start();
return Promise.delay(3000).then(poll);
}
});
};
console.info("Waiting for " + deviceName + " to connect to resin...");
return poll()["return"](uuid);
});
};
exports.inferOrSelectDevice = function(preferredUuid) {
return resin.models.device.getAll().filter(function(device) {
return device.is_online;
}).then(function(onlineDevices) {
if (_.isEmpty(onlineDevices)) {
throw new Error('You don\'t have any devices online');
}
return form.ask({
message: 'Select a device',
type: 'list',
"default": indexOf.call(_.map(onlineDevices, 'uuid'), preferredUuid) >= 0 ? preferredUuid : onlineDevices[0].uuid,
choices: _.map(onlineDevices, function(device) {
return {
name: (device.name || 'Untitled') + " (" + (device.uuid.slice(0, 7)) + ")",
value: device.uuid
};
})
exports.awaitDevice = function(uuid) {
return resin.models.device.getName(uuid).then(function(deviceName) {
var poll, spinner;
spinner = new visuals.Spinner("Waiting for " + deviceName + " to come online");
poll = function() {
return resin.models.device.isOnline(uuid).then(function(isOnline) {
if (isOnline) {
spinner.stop();
console.info("The device **" + deviceName + "** is online!");
} else {
spinner.start();
return Promise.delay(3000).then(poll);
}
});
};
console.info("Waiting for " + deviceName + " to connect to resin...");
return poll()["return"](uuid);
});
};
exports.inferOrSelectDevice = function(preferredUuid) {
return resin.models.device.getAll().filter(function(device) {
return device.is_online;
}).then(function(onlineDevices) {
if (_.isEmpty(onlineDevices)) {
throw new Error('You don\'t have any devices online');
}
return form.ask({
message: 'Select a device',
type: 'list',
"default": indexOf.call(_.map(onlineDevices, 'uuid'), preferredUuid) >= 0 ? preferredUuid : onlineDevices[0].uuid,
choices: _.map(onlineDevices, function(device) {
return {
name: (device.name || 'Untitled') + " (" + (device.uuid.slice(0, 7)) + ")",
value: device.uuid
};
})
});
};
});
};
exports.printErrorMessage = function(message) {
console.error(chalk.red(message));
return console.error(chalk.red("\n" + messages.getHelp + "\n"));
};
}).call(this);
exports.printErrorMessage = function(message) {
console.error(chalk.red(message));
return console.error(chalk.red("\n" + messages.getHelp + "\n"));
};

View File

@ -15,30 +15,26 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var _, capitano, nplugm, patterns;
(function() {
var _, capitano, nplugm, patterns;
nplugm = require('nplugm');
nplugm = require('nplugm');
_ = require('lodash');
_ = require('lodash');
capitano = require('capitano');
capitano = require('capitano');
patterns = require('./patterns');
patterns = require('./patterns');
exports.register = function(regex) {
return nplugm.list(regex).map(function(plugin) {
var command;
command = require(plugin);
command.plugin = true;
if (!_.isArray(command)) {
return capitano.command(command);
}
return _.each(command, capitano.command);
})["catch"](function(error) {
return patterns.printErrorMessage(error.message);
});
};
}).call(this);
exports.register = function(regex) {
return nplugm.list(regex).map(function(plugin) {
var command;
command = require(plugin);
command.plugin = true;
if (!_.isArray(command)) {
return capitano.command(command);
}
return _.each(command, capitano.command);
})["catch"](function(error) {
return patterns.printErrorMessage(error.message);
});
};

View File

@ -15,37 +15,33 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var isRoot, notifier, packageJSON, updateNotifier;
(function() {
var isRoot, notifier, packageJSON, updateNotifier;
updateNotifier = require('update-notifier');
updateNotifier = require('update-notifier');
isRoot = require('is-root');
isRoot = require('is-root');
packageJSON = require('../../package.json');
packageJSON = require('../../package.json');
if (!isRoot()) {
notifier = updateNotifier({
pkg: packageJSON,
updateCheckInterval: 0
});
}
if (!isRoot()) {
notifier = updateNotifier({
pkg: packageJSON,
updateCheckInterval: 0
});
exports.hasAvailableUpdate = function() {
return notifier != null;
};
exports.notify = function() {
if (!exports.hasAvailableUpdate()) {
return;
}
exports.hasAvailableUpdate = function() {
return notifier != null;
};
exports.notify = function() {
if (!exports.hasAvailableUpdate()) {
return;
}
notifier.notify({
defer: false
});
if (notifier.update != null) {
return console.log('Notice that you might need administrator privileges depending on your setup\n');
}
};
}).call(this);
notifier.notify({
defer: false
});
if (notifier.update != null) {
return console.log('Notice that you might need administrator privileges depending on your setup\n');
}
};

View File

@ -15,31 +15,27 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var validEmail;
(function() {
var validEmail;
validEmail = require('valid-email');
validEmail = require('valid-email');
exports.validateEmail = function(input) {
if (!validEmail(input)) {
return 'Email is not valid';
}
return true;
};
exports.validateEmail = function(input) {
if (!validEmail(input)) {
return 'Email is not valid';
}
return true;
};
exports.validatePassword = function(input) {
if (input.length < 8) {
return 'Password should be 8 characters long';
}
return true;
};
exports.validatePassword = function(input) {
if (input.length < 8) {
return 'Password should be 8 characters long';
}
return true;
};
exports.validateApplicationName = function(input) {
if (input.length < 4) {
return 'The application name should be at least 4 characters';
}
return true;
};
}).call(this);
exports.validateApplicationName = function(input) {
if (input.length < 4) {
return 'The application name should be at least 4 characters';
}
return true;
};

View File

@ -705,6 +705,10 @@ comma delimited paths to ignore when syncing
do not parse excluded/included files from .gitignore
#### --skip-restart
do not restart container after syncing
#### --before, -b &#60;command&#62;
execute a command before syncing

View File

@ -16,7 +16,7 @@ OPTIONS =
gulp.task 'coffee', [ 'lint' ], ->
gulp.src(OPTIONS.files.app)
.pipe(coffee(header: true))
.pipe(coffee(bare: true, header: true))
.pipe(gulp.dest(OPTIONS.directories.build))
gulp.task 'lint', ->

View File

@ -32,7 +32,7 @@ exports.download =
description: 'output path'
parameter: 'output'
alias: 'o'
required: 'You have to specify an output location'
required: 'You have to specify the output location'
]
action: (params, options, done) ->
unzip = require('unzip2')

View File

@ -36,9 +36,9 @@
"babel-preset-es2015": "^6.16.0",
"babel-register": "^6.16.3",
"bluebird": "^3.3.3",
"capitano": "~1.7.0",
"capitano": "^1.7.0",
"chalk": "^1.1.3",
"coffee-script": "~1.12.2",
"coffee-script": "~1.12.4",
"columnify": "^1.5.2",
"denymount": "^2.2.0",
"docker-toolbelt": "^1.3.3",
@ -53,7 +53,7 @@
"nplugm": "^3.0.0",
"president": "^2.0.1",
"prettyjson": "^1.1.3",
"reconfix": "0.0.3",
"reconfix": "^0.0.3",
"resin-cli-auth": "^1.0.0",
"resin-cli-errors": "^1.2.0",
"resin-cli-form": "^1.4.1",
@ -62,7 +62,7 @@
"resin-device-config": "^3.0.0",
"resin-device-init": "^2.1.0",
"resin-image-fs": "^2.1.2",
"resin-image-manager": "^4.0.0",
"resin-image-manager": "resin-io/resin-image-manager#36-versioned-downloads",
"resin-sdk-preconfigured": "^0.1.0",
"resin-settings-client": "^3.5.0",
"resin-sync": "^7.0.0",
@ -73,6 +73,6 @@
"underscore.string": "^3.1.1",
"unzip2": "^0.2.5",
"update-notifier": "^0.6.1",
"valid-email": "0.0.2"
"valid-email": "^0.0.2"
}
}