mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-06-24 18:45:07 +00:00
Compare commits
63 Commits
Author | SHA1 | Date | |
---|---|---|---|
5619bdbb67 | |||
381e63bfc9 | |||
e779347ff2 | |||
8fa906dd48 | |||
7e5ecd634d | |||
29cf4c1e89 | |||
73736abdea | |||
9ab411bade | |||
ef33156de7 | |||
6d8fd6e547 | |||
bab90a8bf2 | |||
43f0288c6c | |||
47e6371e2e | |||
5e400ed335 | |||
56a78b57af | |||
2bfeb7f42c | |||
37e0f12f89 | |||
fdd0e4a966 | |||
38df7e0038 | |||
e9efb78280 | |||
0424d7b640 | |||
2b80c7c91f | |||
142e2c0a65 | |||
1ed9ae7d60 | |||
329bf25dbd | |||
e18ffba183 | |||
ae3f0b429d | |||
34736c4e9b | |||
806678ee5f | |||
1e70401bdd | |||
3c7615f20d | |||
054d5e4879 | |||
b04ed43bed | |||
c2bbb952c5 | |||
63a9e1859b | |||
68ef069e6a | |||
72d4b21cb4 | |||
e8b931680d | |||
218b407f30 | |||
773cc27145 | |||
1c76e2e15b | |||
e466cfd6ff | |||
992b04d521 | |||
5c16c86871 | |||
78af9bbb10 | |||
b78c48d89f | |||
1f8c610bb0 | |||
d220728380 | |||
db58e9986c | |||
2a5e66eca6 | |||
e7e8ec296c | |||
80e69c56d0 | |||
ce3c6aecff | |||
300f76ba83 | |||
a4e8a38bf4 | |||
9bb04f43a8 | |||
9b0c08bd46 | |||
679d48e86e | |||
4b6bf60531 | |||
d8ce6648e2 | |||
402bc2d3a8 | |||
f3e193be0f | |||
f5b461612b |
@ -3,6 +3,7 @@
|
||||
[](http://badge.fury.io/js/resin-cli)
|
||||
[](https://david-dm.org/resin-io/resin-cli.png)
|
||||
[](https://travis-ci.org/resin-io/resin-cli)
|
||||
[](https://ci.appveyor.com/project/jviotti/resin-cli)
|
||||
|
||||
The official Resin CLI tool.
|
||||
|
||||
|
27
appveyor.yml
Normal file
27
appveyor.yml
Normal file
@ -0,0 +1,27 @@
|
||||
# appveyor file
|
||||
# http://www.appveyor.com/docs/appveyor-yml
|
||||
|
||||
init:
|
||||
- git config --global core.autocrlf input
|
||||
|
||||
# what combinations to test
|
||||
environment:
|
||||
matrix:
|
||||
- nodejs_version: 0.10
|
||||
- nodejs_version: 0.11
|
||||
- nodejs_version: 0.12
|
||||
|
||||
install:
|
||||
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version)
|
||||
- npm -g install npm@2
|
||||
- set PATH=%APPDATA%\npm;%PATH%
|
||||
- npm install -g gulp
|
||||
- npm install
|
||||
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- node --version
|
||||
- npm --version
|
||||
- ps: gulp test
|
||||
- cmd: gulp test
|
@ -39,14 +39,13 @@
|
||||
if (options.type != null) {
|
||||
return callback(null, options.type);
|
||||
}
|
||||
return resin.models.device.getSupportedDeviceTypes(function(error, deviceTypes) {
|
||||
if (error != null) {
|
||||
return callback(error);
|
||||
}
|
||||
return visuals.widgets.select('Select a type', deviceTypes, callback);
|
||||
});
|
||||
return visuals.patterns.selectDeviceType(callback);
|
||||
}, function(type, callback) {
|
||||
return resin.models.application.create(params.name, type, callback);
|
||||
options.type = type;
|
||||
return resin.models.application.create(params.name, options.type, callback);
|
||||
}, function(applicationId, callback) {
|
||||
console.info("Application created: " + params.name + " (" + options.type + ", id " + applicationId + ")");
|
||||
return callback();
|
||||
}
|
||||
], done);
|
||||
}
|
||||
@ -110,13 +109,26 @@
|
||||
exports.associate = {
|
||||
signature: 'app associate <name>',
|
||||
description: 'associate a resin project',
|
||||
help: 'Use this command to associate a project directory with a resin application.\n\nThis command adds a \'resin\' git remote to the directory and runs git init if necessary.\n\nExamples:\n\n $ resin app associate MyApp\n $ resin app associate MyApp --project my/app/directory',
|
||||
help: 'Use this command to associate a project directory with a resin application.\n\nThis command adds a \'resin\' git remote to the directory and runs git init if necessary.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin app associate MyApp\n $ resin app associate MyApp --project my/app/directory',
|
||||
options: [commandOptions.yes],
|
||||
permission: 'user',
|
||||
action: function(params, options, done) {
|
||||
var currentDirectory;
|
||||
currentDirectory = process.cwd();
|
||||
return async.waterfall([
|
||||
function(callback) {
|
||||
return resin.models.application.has(params.name, callback);
|
||||
}, function(hasApp, callback) {
|
||||
var message;
|
||||
if (!hasApp) {
|
||||
return callback(new Error("Invalid application: " + params.name));
|
||||
}
|
||||
message = "Are you sure you want to associate " + currentDirectory + " with " + params.name + "?";
|
||||
return visuals.patterns.confirm(options.yes, message, callback);
|
||||
}, function(confirmed, callback) {
|
||||
if (!confirmed) {
|
||||
return done();
|
||||
}
|
||||
return vcs.initialize(currentDirectory, callback);
|
||||
}, function(callback) {
|
||||
return resin.models.application.get(params.name, callback);
|
||||
@ -145,7 +157,12 @@
|
||||
function(callback) {
|
||||
var currentDirectoryBasename;
|
||||
currentDirectoryBasename = path.basename(currentDirectory);
|
||||
return visuals.widgets.ask('What is the name of your application?', currentDirectoryBasename, callback);
|
||||
return visuals.form.ask({
|
||||
label: 'What is the name of your application?',
|
||||
name: 'application',
|
||||
type: 'text',
|
||||
value: currentDirectoryBasename
|
||||
}, callback);
|
||||
}, function(applicationName, callback) {
|
||||
return exports.create.action({
|
||||
name: applicationName
|
||||
|
@ -15,29 +15,32 @@
|
||||
|
||||
visuals = require('resin-cli-visuals');
|
||||
|
||||
TOKEN_URL = url.resolve(settings.get('remoteUrl'), '/preferences');
|
||||
TOKEN_URL = url.resolve(settings.get('dashboardUrl'), '/preferences');
|
||||
|
||||
exports.login = {
|
||||
signature: 'login [token]',
|
||||
description: 'login to resin.io',
|
||||
help: "Use this command to login to your resin.io account.\n\nTo login, you need your token, which is accesible from the preferences page:\n\n " + TOKEN_URL + "\n\nExamples:\n\n $ resin login\n $ resin login \"eyJ0eXAiOiJKV1Qi...\"",
|
||||
action: function(params, options, done) {
|
||||
console.info("To login to the Resin CLI, you need your unique token, which is accesible from\nthe preferences page at " + TOKEN_URL + "\n\nAttempting to open a browser at that location...");
|
||||
return async.waterfall([
|
||||
function(callback) {
|
||||
if (params.token != null) {
|
||||
return callback(null, params.token);
|
||||
}
|
||||
console.info("To login to the Resin CLI, you need your unique token, which is accesible from\nthe preferences page at " + TOKEN_URL + "\n\nAttempting to open a browser at that location...");
|
||||
return open(TOKEN_URL, function(error) {
|
||||
if (error != null) {
|
||||
console.error("Unable to open a web browser in the current environment.\nPlease visit " + TOKEN_URL + " manually.");
|
||||
}
|
||||
return callback();
|
||||
return visuals.patterns.loginWithToken(callback);
|
||||
});
|
||||
}, function(callback) {
|
||||
if (params.token != null) {
|
||||
return callback(null, params.token);
|
||||
}
|
||||
return visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback);
|
||||
}, function(token, callback) {
|
||||
return resin.auth.loginWithToken(token, done);
|
||||
return resin.auth.loginWithToken(token, callback);
|
||||
}, function(callback) {
|
||||
return resin.auth.whoami(callback);
|
||||
}, function(username, callback) {
|
||||
console.info("Successfully logged in as: " + username);
|
||||
return callback();
|
||||
}
|
||||
], done);
|
||||
}
|
||||
@ -94,7 +97,7 @@
|
||||
if (hasOptionCredentials) {
|
||||
return callback(null, options);
|
||||
}
|
||||
return visuals.widgets.register(callback);
|
||||
return visuals.patterns.register(callback);
|
||||
}, function(credentials, callback) {
|
||||
return resin.auth.register(credentials, function(error, token) {
|
||||
return callback(error, credentials);
|
||||
|
@ -21,6 +21,20 @@
|
||||
required: 'You have to specify an application'
|
||||
}, exports.optionalApplication);
|
||||
|
||||
exports.optionalDevice = {
|
||||
signature: 'device',
|
||||
parameter: 'device',
|
||||
description: 'device name',
|
||||
alias: 'd'
|
||||
};
|
||||
|
||||
exports.booleanDevice = {
|
||||
signature: 'device',
|
||||
description: 'device name',
|
||||
boolean: true,
|
||||
alias: 'd'
|
||||
};
|
||||
|
||||
exports.network = {
|
||||
signature: 'network',
|
||||
parameter: 'network',
|
||||
|
@ -1,5 +1,7 @@
|
||||
(function() {
|
||||
var _, async, capitano, commandOptions, osAction, path, resin, tmp, vcs, visuals;
|
||||
var _, async, capitano, commandOptions, fse, image, inject, manager, path, pine, registerDevice, resin, tmp, vcs, visuals;
|
||||
|
||||
fse = require('fs-extra');
|
||||
|
||||
capitano = require('capitano');
|
||||
|
||||
@ -15,14 +17,22 @@
|
||||
|
||||
vcs = require('resin-vcs');
|
||||
|
||||
manager = require('resin-image-manager');
|
||||
|
||||
image = require('resin-image');
|
||||
|
||||
inject = require('resin-config-inject');
|
||||
|
||||
registerDevice = require('resin-register-device');
|
||||
|
||||
pine = require('resin-pine');
|
||||
|
||||
tmp = require('tmp');
|
||||
|
||||
tmp.setGracefulCleanup();
|
||||
|
||||
commandOptions = require('./command-options');
|
||||
|
||||
osAction = require('./os');
|
||||
|
||||
exports.list = {
|
||||
signature: 'devices',
|
||||
description: 'list all devices',
|
||||
@ -41,7 +51,7 @@
|
||||
return done(error);
|
||||
}
|
||||
console.log(visuals.widgets.table.horizontal(devices, ['id', 'name', 'device_type', 'is_online', 'application_name', 'status', 'last_seen']));
|
||||
return done();
|
||||
return done(null, devices);
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -96,7 +106,11 @@
|
||||
if (!_.isEmpty(params.newName)) {
|
||||
return callback(null, params.newName);
|
||||
}
|
||||
return visuals.widgets.ask('How do you want to name this device?', null, callback);
|
||||
return visuals.form.ask({
|
||||
label: 'How do you want to name this device?',
|
||||
name: 'device',
|
||||
type: 'text'
|
||||
}, callback);
|
||||
}, function(newName, callback) {
|
||||
return resin.models.device.rename(params.name, newName, callback);
|
||||
}
|
||||
@ -159,10 +173,17 @@
|
||||
exports.init = {
|
||||
signature: 'device init [device]',
|
||||
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\nNote that this command requires admin privileges.\n\nIf `device` is omitted, you will be prompted to select a device interactively.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nYou can quiet the progress bar by passing the `--quiet` boolean option.\n\nYou may have to unmount the device before attempting this operation.\n\nYou need to configure the network type and other settings:\n\nEthernet:\n You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".\n\nWifi:\n You can setup the device OS to use wifi by setting the `--network` option to "wifi".\n If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.\n\nYou can omit network related options to be asked about them interactively.\n\nExamples:\n\n $ resin device init\n $ resin device init --application MyApp\n $ resin device init --application MyApp --network ethernet\n $ resin device init /dev/disk2 --application MyApp --network wifi --ssid MyNetwork --key secret',
|
||||
help: 'Use this command to download the OS image of a certain application and write it to an SD Card.\n\nNote that this command requires admin privileges.\n\nIf `device` is omitted, you will be prompted to select a device interactively.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nYou can quiet the progress bar and other logging information by passing the `--quiet` boolean option.\n\nYou need to configure the network type and other settings:\n\nEthernet:\n You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".\n\nWifi:\n You can setup the device OS to use wifi by setting the `--network` option to "wifi".\n If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.\n\nYou can omit network related options to be asked about them interactively.\n\nExamples:\n\n $ resin device init\n $ resin device init --application MyApp\n $ resin device init --application MyApp --network ethernet\n $ resin device init /dev/disk2 --application MyApp --network wifi --ssid MyNetwork --key secret',
|
||||
options: [commandOptions.optionalApplication, commandOptions.network, commandOptions.wifiSsid, commandOptions.wifiKey],
|
||||
permission: 'user',
|
||||
root: true,
|
||||
action: function(params, options, done) {
|
||||
var networkOptions;
|
||||
networkOptions = {
|
||||
network: options.network,
|
||||
wifiSsid: options.ssid,
|
||||
wifiKey: options.key
|
||||
};
|
||||
return async.waterfall([
|
||||
function(callback) {
|
||||
if (options.application != null) {
|
||||
@ -170,7 +191,12 @@
|
||||
}
|
||||
return vcs.getApplicationName(process.cwd(), callback);
|
||||
}, function(applicationName, callback) {
|
||||
params.name = applicationName;
|
||||
options.application = applicationName;
|
||||
return resin.models.application.has(options.application, callback);
|
||||
}, function(hasApplication, callback) {
|
||||
if (!hasApplication) {
|
||||
return callback(new Error("Invalid application: " + options.application));
|
||||
}
|
||||
if (params.device != null) {
|
||||
return callback(null, params.device);
|
||||
}
|
||||
@ -184,27 +210,81 @@
|
||||
if (!confirmed) {
|
||||
return done();
|
||||
}
|
||||
options.yes = confirmed;
|
||||
return tmp.file({
|
||||
prefix: 'resin-image-',
|
||||
postfix: '.img'
|
||||
}, callback);
|
||||
}, function(tmpPath, tmpFd, cleanupCallback, callback) {
|
||||
options.output = tmpPath;
|
||||
return osAction.download.action(params, options, function(error, outputFile) {
|
||||
if (networkOptions.network != null) {
|
||||
return callback();
|
||||
}
|
||||
return visuals.patterns.selectNetworkParameters(function(error, parameters) {
|
||||
if (error != null) {
|
||||
return callback(error);
|
||||
}
|
||||
return callback(null, outputFile, cleanupCallback);
|
||||
});
|
||||
}, function(outputFile, cleanupCallback, callback) {
|
||||
return capitano.run("os install " + outputFile + " " + params.device, function(error) {
|
||||
if (error != null) {
|
||||
return callback(error);
|
||||
}
|
||||
cleanupCallback();
|
||||
_.extend(networkOptions, parameters);
|
||||
return callback();
|
||||
});
|
||||
}, function(callback) {
|
||||
console.info("Checking application: " + options.application);
|
||||
return resin.models.application.get(options.application, callback);
|
||||
}, function(application, callback) {
|
||||
return async.parallel({
|
||||
manifest: function(callback) {
|
||||
console.info('Getting device manifest for the application');
|
||||
return resin.models.device.getManifestBySlug(application.device_type, callback);
|
||||
},
|
||||
config: function(callback) {
|
||||
console.info('Fetching application configuration');
|
||||
return resin.models.application.getConfiguration(options.application, networkOptions, callback);
|
||||
}
|
||||
}, callback);
|
||||
}, function(results, callback) {
|
||||
console.info('Associating the device');
|
||||
return registerDevice.register(pine, results.config, function(error, device) {
|
||||
if (error != null) {
|
||||
return callback(error);
|
||||
}
|
||||
results.config.deviceId = device.id;
|
||||
results.config.uuid = device.uuid;
|
||||
params.uuid = results.config.uuid;
|
||||
return callback(null, results);
|
||||
});
|
||||
}, function(results, callback) {
|
||||
var bar, spinner;
|
||||
console.info('Configuring device operating system image');
|
||||
if (process.env.DEBUG) {
|
||||
console.log(results.config);
|
||||
}
|
||||
bar = new visuals.widgets.Progress('Downloading Device OS');
|
||||
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)');
|
||||
return manager.configure(results.manifest, results.config, function(error, imagePath, removeCallback) {
|
||||
spinner.stop();
|
||||
return callback(error, imagePath, removeCallback);
|
||||
}, function(state) {
|
||||
if (state != null) {
|
||||
return bar.update(state);
|
||||
} else {
|
||||
return spinner.start();
|
||||
}
|
||||
});
|
||||
}, function(configuredImagePath, removeCallback, callback) {
|
||||
var bar;
|
||||
console.info('Attempting to write operating system image to drive');
|
||||
bar = new visuals.widgets.Progress('Writing Device OS');
|
||||
return image.write({
|
||||
device: params.device,
|
||||
image: configuredImagePath,
|
||||
progress: _.bind(bar.update, bar)
|
||||
}, function(error) {
|
||||
if (error != null) {
|
||||
return callback(error);
|
||||
}
|
||||
return callback(null, configuredImagePath, removeCallback);
|
||||
});
|
||||
}, function(temporalImagePath, removeCallback, callback) {
|
||||
console.info('Image written successfully');
|
||||
return removeCallback(callback);
|
||||
}, function(callback) {
|
||||
return resin.models.device.getByUUID(params.uuid, callback);
|
||||
}, function(device, callback) {
|
||||
console.info("Device created: " + device.name);
|
||||
return callback(null, device.name);
|
||||
}
|
||||
], done);
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
(function() {
|
||||
var _, commandOptions, resin, visuals;
|
||||
var _, async, commandOptions, resin, visuals;
|
||||
|
||||
async = require('async');
|
||||
|
||||
_ = require('lodash-contrib');
|
||||
|
||||
@ -12,9 +14,9 @@
|
||||
exports.list = {
|
||||
signature: 'envs',
|
||||
description: 'list all environment variables',
|
||||
help: 'Use this command to list all environment variables for a particular application.\nNotice we will support per-device environment variables soon.\n\nThis command lists all custom environment variables set on the devices running\nthe application. If you want to see all environment variables, including private\nones used by resin, use the verbose option.\n\nExample:\n\n $ resin envs --application 91\n $ resin envs --application 91 --verbose',
|
||||
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 MyDevice',
|
||||
options: [
|
||||
commandOptions.application, {
|
||||
commandOptions.optionalApplication, commandOptions.optionalDevice, {
|
||||
signature: 'verbose',
|
||||
description: 'show private environment variables',
|
||||
boolean: true,
|
||||
@ -23,28 +25,41 @@
|
||||
],
|
||||
permission: 'user',
|
||||
action: function(params, options, done) {
|
||||
return resin.models.environmentVariables.getAllByApplication(options.application, function(error, environmentVariables) {
|
||||
if (error != null) {
|
||||
return done(error);
|
||||
return async.waterfall([
|
||||
function(callback) {
|
||||
if (options.application != null) {
|
||||
return resin.models.environmentVariables.getAllByApplication(options.application, callback);
|
||||
} else if (options.device != null) {
|
||||
return resin.models.environmentVariables.device.getAll(options.device, callback);
|
||||
} else {
|
||||
return callback(new Error('You must specify an application or device'));
|
||||
}
|
||||
}, function(environmentVariables, callback) {
|
||||
var isSystemVariable;
|
||||
if (!options.verbose) {
|
||||
isSystemVariable = resin.models.environmentVariables.isSystemVariable;
|
||||
environmentVariables = _.reject(environmentVariables, isSystemVariable);
|
||||
}
|
||||
console.log(visuals.widgets.table.horizontal(environmentVariables, ['id', 'name', 'value']));
|
||||
return callback();
|
||||
}
|
||||
if (!options.verbose) {
|
||||
environmentVariables = _.reject(environmentVariables, resin.models.environmentVariables.isSystemVariable);
|
||||
}
|
||||
console.log(visuals.widgets.table.horizontal(environmentVariables, ['id', 'name', 'value']));
|
||||
return done();
|
||||
});
|
||||
], 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\nExamples:\n\n $ resin env rm 215\n $ resin env rm 215 --yes',
|
||||
options: [commandOptions.yes],
|
||||
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) {
|
||||
return visuals.patterns.remove('environment variable', options.yes, function(callback) {
|
||||
return resin.models.environmentVariables.remove(params.id, callback);
|
||||
if (options.device) {
|
||||
return resin.models.environmentVariables.device.remove(params.id, callback);
|
||||
} else {
|
||||
return resin.models.environmentVariables.remove(params.id, callback);
|
||||
}
|
||||
}, done);
|
||||
}
|
||||
};
|
||||
@ -52,8 +67,8 @@
|
||||
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\nYou need to pass the `--application` option.\n\nIf value is omitted, the tool will attempt to use the variable\'s value\nas defined in your host machine.\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 -a 91\n $ resin env add TERM -a 91',
|
||||
options: [commandOptions.application],
|
||||
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 MyDevice',
|
||||
options: [commandOptions.optionalApplication, commandOptions.optionalDevice],
|
||||
permission: 'user',
|
||||
action: function(params, options, done) {
|
||||
if (params.value == null) {
|
||||
@ -64,17 +79,28 @@
|
||||
console.info("Warning: using " + params.key + "=" + params.value + " from host environment");
|
||||
}
|
||||
}
|
||||
return resin.models.environmentVariables.create(options.application, params.key, params.value, done);
|
||||
if (options.application != null) {
|
||||
return resin.models.environmentVariables.create(options.application, params.key, params.value, done);
|
||||
} else if (options.device != null) {
|
||||
return resin.models.environmentVariables.device.create(options.device, params.key, params.value, done);
|
||||
} else {
|
||||
return done(new Error('You must specify an application or device'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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\nExamples:\n\n $ resin env rename 376 emacs',
|
||||
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) {
|
||||
return resin.models.environmentVariables.update(params.id, params.value, done);
|
||||
if (options.device) {
|
||||
return resin.models.environmentVariables.device.update(params.id, params.value, done);
|
||||
} else {
|
||||
return resin.models.environmentVariables.update(params.id, params.value, done);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -35,41 +35,43 @@
|
||||
}
|
||||
return example;
|
||||
});
|
||||
return console.log(visuals.widgets.table.horizontal(examplesData, ['id', 'display_name', 'repository', 'author']));
|
||||
return console.log(visuals.widgets.table.horizontal(examplesData, ['id', 'name', 'display_name', 'repository', 'author']));
|
||||
}
|
||||
};
|
||||
|
||||
exports.info = {
|
||||
signature: 'example <id>',
|
||||
signature: 'example <name>',
|
||||
description: 'list a single example application',
|
||||
help: 'Use this command to show information of a single example application\n\nExample:\n\n $ resin example 3',
|
||||
help: 'Use this command to show information of a single example application\n\nExample:\n\n $ resin example cimon',
|
||||
permission: 'user',
|
||||
action: function(params, options, done) {
|
||||
var example, id;
|
||||
id = params.id - 1;
|
||||
example = examplesData[id];
|
||||
var example;
|
||||
example = _.findWhere(examplesData, {
|
||||
name: params.name
|
||||
});
|
||||
if (example == null) {
|
||||
return done(new Error("Unknown example: " + id));
|
||||
return done(new Error("Unknown example: " + params.name));
|
||||
}
|
||||
example.id = id;
|
||||
if (example.author == null) {
|
||||
example.author = 'Unknown';
|
||||
}
|
||||
console.log(visuals.widgets.table.vertical(example, ['id', 'display_name', 'description', 'author', 'repository']));
|
||||
console.log(visuals.widgets.table.vertical(example, ['name', 'display_name', 'description', 'author', 'repository']));
|
||||
return done();
|
||||
}
|
||||
};
|
||||
|
||||
exports.clone = {
|
||||
signature: 'example clone <id>',
|
||||
signature: 'example clone <name>',
|
||||
description: 'clone an example application',
|
||||
help: 'Use this command to clone an example application to the current directory\n\nThis command outputs information about the cloning process.\nUse `--quiet` to remove that output.\n\nExample:\n\n $ resin example clone 3',
|
||||
help: 'Use this command to clone an example application to the current directory\n\nThis command outputs information about the cloning process.\nUse `--quiet` to remove that output.\n\nExample:\n\n $ resin example clone cimon',
|
||||
permission: 'user',
|
||||
action: function(params, options, done) {
|
||||
var currentDirectory, destination, example;
|
||||
example = examplesData[params.id - 1];
|
||||
example = _.findWhere(examplesData, {
|
||||
name: params.name
|
||||
});
|
||||
if (example == null) {
|
||||
return done(new Error("Unknown example: " + id));
|
||||
return done(new Error("Unknown example: " + params.name));
|
||||
}
|
||||
currentDirectory = process.cwd();
|
||||
destination = path.join(currentDirectory, example.name);
|
||||
|
@ -10,7 +10,6 @@
|
||||
logs: require('./logs'),
|
||||
notes: require('./notes'),
|
||||
preferences: require('./preferences'),
|
||||
os: require('./os'),
|
||||
help: require('./help'),
|
||||
examples: require('./examples'),
|
||||
plugin: require('./plugin'),
|
||||
|
@ -1,5 +1,7 @@
|
||||
(function() {
|
||||
var packageJSON;
|
||||
var packageJSON, settings;
|
||||
|
||||
settings = require('resin-settings-client');
|
||||
|
||||
packageJSON = require('../../package.json');
|
||||
|
||||
@ -13,4 +15,19 @@
|
||||
}
|
||||
};
|
||||
|
||||
exports.config = {
|
||||
signature: 'config',
|
||||
description: 'see your current configuration',
|
||||
help: 'See your current Resin CLI configuration.\n\nConfiguration lives in $HOME/.resin/config.',
|
||||
action: function(params, options, done) {
|
||||
var key, ref, value;
|
||||
ref = settings.get();
|
||||
for (key in ref) {
|
||||
value = ref[key];
|
||||
console.log(key + ": " + value);
|
||||
}
|
||||
return done();
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
@ -45,7 +45,6 @@
|
||||
if (error != null) {
|
||||
return done(error);
|
||||
}
|
||||
key.public_key = '\n' + visuals.helpers.chop(key.public_key, SSH_KEY_WIDTH);
|
||||
console.log(visuals.widgets.table.vertical(key, ['id', 'title', 'public_key']));
|
||||
return done();
|
||||
});
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
LOGS_HISTORY_COUNT = 200;
|
||||
|
||||
exports.logs = {
|
||||
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 limit the output to the n last lines, use the `--num` option along with a number.\nThis is similar to doing `resin logs <uuid> | tail -n X`.\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 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828\n $ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828 --num 20\n $ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828 --tail',
|
||||
|
@ -1,157 +0,0 @@
|
||||
(function() {
|
||||
var _, async, capitano, commandOptions, elevate, image, mkdirp, npm, os, packageJSON, path, resin, visuals;
|
||||
|
||||
capitano = require('capitano');
|
||||
|
||||
_ = require('lodash-contrib');
|
||||
|
||||
os = require('os');
|
||||
|
||||
async = require('async');
|
||||
|
||||
path = require('path');
|
||||
|
||||
mkdirp = require('mkdirp');
|
||||
|
||||
resin = require('resin-sdk');
|
||||
|
||||
image = require('resin-image');
|
||||
|
||||
visuals = require('resin-cli-visuals');
|
||||
|
||||
commandOptions = require('./command-options');
|
||||
|
||||
npm = require('../npm');
|
||||
|
||||
packageJSON = require('../../package.json');
|
||||
|
||||
elevate = require('../elevate');
|
||||
|
||||
exports.download = {
|
||||
signature: 'os download <name>',
|
||||
description: 'download device OS',
|
||||
help: 'Use this command to download the device OS configured to a specific network.\n\nEthernet:\n You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".\n\nWifi:\n You can setup the device OS to use wifi by setting the `--network` option to "wifi".\n If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.\n\nAlternatively, you can omit all kind of network configuration options to configure interactively.\n\nYou have to specify an output location with the `--output` option.\n\nExamples:\n\n $ resin os download MyApp --output ~/MyResinOS.zip\n $ resin os download MyApp --network ethernet --output ~/MyResinOS.zip\n $ resin os download MyApp --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip\n $ resin os download MyApp --network ethernet --output ~/MyResinOS.zip',
|
||||
options: [
|
||||
commandOptions.network, commandOptions.wifiSsid, commandOptions.wifiKey, {
|
||||
signature: 'output',
|
||||
parameter: 'output',
|
||||
description: 'output file',
|
||||
alias: 'o',
|
||||
required: 'You need to specify an output file'
|
||||
}
|
||||
],
|
||||
permission: 'user',
|
||||
action: function(params, options, done) {
|
||||
return resin.models.application.get(params.name, function(error, application) {
|
||||
var osParams;
|
||||
if (error != null) {
|
||||
return done(error);
|
||||
}
|
||||
osParams = {
|
||||
network: options.network,
|
||||
wifiSsid: options.ssid,
|
||||
wifiKey: options.key,
|
||||
appId: application.id
|
||||
};
|
||||
return async.waterfall([
|
||||
function(callback) {
|
||||
if (osParams.network != null) {
|
||||
return callback();
|
||||
}
|
||||
return visuals.patterns.selectNetworkParameters(function(error, parameters) {
|
||||
if (error != null) {
|
||||
return callback(error);
|
||||
}
|
||||
_.extend(osParams, parameters);
|
||||
return callback();
|
||||
});
|
||||
}, function(callback) {
|
||||
return mkdirp(path.dirname(options.output), _.unary(callback));
|
||||
}, function(callback) {
|
||||
var bar, spinner;
|
||||
console.info("Destination file: " + options.output + "\n");
|
||||
bar = new visuals.widgets.Progress('Downloading Device OS');
|
||||
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)');
|
||||
return resin.models.os.download(osParams, options.output, function(error) {
|
||||
spinner.stop();
|
||||
if (error != null) {
|
||||
return callback(error);
|
||||
}
|
||||
}, function(state) {
|
||||
if (state != null) {
|
||||
return bar.update(state);
|
||||
} else {
|
||||
return spinner.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
], function(error) {
|
||||
if (error != null) {
|
||||
return done(error);
|
||||
}
|
||||
console.info("\nFinished downloading " + options.output);
|
||||
return done(null, options.output);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.install = {
|
||||
signature: 'os install <image> [device]',
|
||||
description: 'write an operating system image to a device',
|
||||
help: 'Use this command to write an operating system image to a device.\n\nNote that this command requires admin privileges.\n\nIf `device` is omitted, you will be prompted to select a device interactively.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nYou can quiet the progress bar by passing the `--quiet` boolean option.\n\nExamples:\n\n $ resin os install rpi.iso /dev/disk2',
|
||||
options: [commandOptions.yes],
|
||||
permission: 'user',
|
||||
action: function(params, options, done) {
|
||||
return async.waterfall([
|
||||
function(callback) {
|
||||
return npm.isUpdated(packageJSON.name, packageJSON.version, callback);
|
||||
}, function(isUpdated, callback) {
|
||||
if (isUpdated) {
|
||||
return callback();
|
||||
}
|
||||
console.info('Resin CLI is outdated.\n\nIn order to avoid device compatibility issues, this command\nrequires that you have the Resin CLI updated.\n\nUpdating now...');
|
||||
return capitano.run('update', _.unary(callback));
|
||||
}, function(callback) {
|
||||
if (params.device != null) {
|
||||
return callback(null, params.device);
|
||||
}
|
||||
return visuals.patterns.selectDrive(function(error, device) {
|
||||
if (error != null) {
|
||||
return callback(error);
|
||||
}
|
||||
if (device == null) {
|
||||
return callback(new Error('No removable devices available'));
|
||||
}
|
||||
return callback(null, device);
|
||||
});
|
||||
}, function(device, callback) {
|
||||
var message;
|
||||
params.device = device;
|
||||
message = "This will completely erase " + params.device + ". Are you sure you want to continue?";
|
||||
return visuals.patterns.confirm(options.yes, message, callback);
|
||||
}, function(confirmed, callback) {
|
||||
var bar;
|
||||
if (!confirmed) {
|
||||
return done();
|
||||
}
|
||||
bar = new visuals.widgets.Progress('Writing Device OS');
|
||||
params.progress = _.bind(bar.update, bar);
|
||||
return image.write(params, callback);
|
||||
}
|
||||
], function(error) {
|
||||
var resinWritePath;
|
||||
if (error == null) {
|
||||
return done();
|
||||
}
|
||||
if (elevate.shouldElevate(error) && !options.fromScript) {
|
||||
resinWritePath = "\"" + (path.join(__dirname, '..', '..', 'bin', 'resin-write')) + "\"";
|
||||
return elevate.run("\"" + process.argv[0] + "\" " + resinWritePath + " \"" + params.image + "\" \"" + params.device + "\"");
|
||||
} else {
|
||||
return done(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
@ -1,13 +1,7 @@
|
||||
(function() {
|
||||
var _, child_process, npm, packageJSON, president;
|
||||
var packageJSON, selfupdate;
|
||||
|
||||
_ = require('lodash');
|
||||
|
||||
child_process = require('child_process');
|
||||
|
||||
president = require('president');
|
||||
|
||||
npm = require('../npm');
|
||||
selfupdate = require('selfupdate');
|
||||
|
||||
packageJSON = require('../../package.json');
|
||||
|
||||
@ -16,34 +10,12 @@
|
||||
description: 'update the resin cli',
|
||||
help: 'Use this command to update the Resin CLI\n\nThis command outputs information about the update process.\nUse `--quiet` to remove that output.\n\nThe Resin CLI checks for updates once per day.\n\nMajor updates require a manual update with this update command,\nwhile minor updates are applied automatically.\n\nExamples:\n\n $ resin update',
|
||||
action: function(params, options, done) {
|
||||
return npm.isUpdated(packageJSON.name, packageJSON.version, function(error, isUpdated) {
|
||||
var command, onUpdate;
|
||||
return selfupdate.update(packageJSON, function(error, version) {
|
||||
if (error != null) {
|
||||
return done(error);
|
||||
}
|
||||
if (isUpdated) {
|
||||
return done(new Error('You\'re already running the latest version.'));
|
||||
}
|
||||
onUpdate = function(error, stdout, stderr) {
|
||||
if (error != null) {
|
||||
return done(error);
|
||||
}
|
||||
if (!_.isEmpty(stderr)) {
|
||||
return done(new Error(stderr));
|
||||
}
|
||||
console.info("Upgraded " + packageJSON.name + ".");
|
||||
return done();
|
||||
};
|
||||
command = "npm install --global " + packageJSON.name;
|
||||
return child_process.exec(command, function(error, stdout, stderr) {
|
||||
if (error == null) {
|
||||
return onUpdate(null, stdout, stderr);
|
||||
}
|
||||
if (_.any([error.code === 3, error.code === 'EPERM', error.code === 'ACCES'])) {
|
||||
return president.execute(command, onUpdate);
|
||||
}
|
||||
return done(error);
|
||||
});
|
||||
console.info("Updated " + packageJSON.name + " to version " + version + ".");
|
||||
return done();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
23
build/app.js
23
build/app.js
@ -18,7 +18,10 @@
|
||||
update = require('./update');
|
||||
|
||||
capitano.permission('user', function(done) {
|
||||
return resin.auth.isLoggedIn(function(isLoggedIn) {
|
||||
return resin.auth.isLoggedIn(function(error, isLoggedIn) {
|
||||
if (error != null) {
|
||||
return done(error);
|
||||
}
|
||||
if (!isLoggedIn) {
|
||||
return done(new Error('You have to log in'));
|
||||
}
|
||||
@ -64,6 +67,8 @@
|
||||
|
||||
capitano.command(actions.info.version);
|
||||
|
||||
capitano.command(actions.info.config);
|
||||
|
||||
capitano.command(actions.help.help);
|
||||
|
||||
capitano.command(actions.auth.login);
|
||||
@ -78,8 +83,6 @@
|
||||
|
||||
capitano.command(actions.app.list);
|
||||
|
||||
capitano.command(actions.app.info);
|
||||
|
||||
capitano.command(actions.app.remove);
|
||||
|
||||
capitano.command(actions.app.restart);
|
||||
@ -88,6 +91,8 @@
|
||||
|
||||
capitano.command(actions.app.init);
|
||||
|
||||
capitano.command(actions.app.info);
|
||||
|
||||
capitano.command(actions.device.list);
|
||||
|
||||
capitano.command(actions.device.supported);
|
||||
@ -96,14 +101,14 @@
|
||||
|
||||
capitano.command(actions.device.init);
|
||||
|
||||
capitano.command(actions.device.await);
|
||||
|
||||
capitano.command(actions.device.info);
|
||||
|
||||
capitano.command(actions.device.remove);
|
||||
|
||||
capitano.command(actions.device.identify);
|
||||
|
||||
capitano.command(actions.device.await);
|
||||
|
||||
capitano.command(actions.drive.list);
|
||||
|
||||
capitano.command(actions.notes.set);
|
||||
@ -126,11 +131,7 @@
|
||||
|
||||
capitano.command(actions.env.remove);
|
||||
|
||||
capitano.command(actions.logs.logs);
|
||||
|
||||
capitano.command(actions.os.download);
|
||||
|
||||
capitano.command(actions.os.install);
|
||||
capitano.command(actions.logs);
|
||||
|
||||
capitano.command(actions.examples.list);
|
||||
|
||||
@ -164,7 +165,7 @@
|
||||
}, function(callback) {
|
||||
var cli;
|
||||
cli = capitano.parse(process.argv);
|
||||
if (cli.global.quiet) {
|
||||
if (cli.global.quiet || !process.stdout.isTTY) {
|
||||
console.info = _.noop;
|
||||
}
|
||||
if (cli.global.project != null) {
|
||||
|
38
build/npm.js
38
build/npm.js
@ -1,38 +0,0 @@
|
||||
(function() {
|
||||
var _, async, npm;
|
||||
|
||||
npm = require('npm');
|
||||
|
||||
async = require('async');
|
||||
|
||||
_ = require('lodash-contrib');
|
||||
|
||||
exports.getLatestVersion = function(name, callback) {
|
||||
return async.waterfall([
|
||||
function(callback) {
|
||||
var options;
|
||||
options = {
|
||||
loglevel: 'silent',
|
||||
global: true
|
||||
};
|
||||
return npm.load(options, _.unary(callback));
|
||||
}, function(callback) {
|
||||
return npm.commands.view([name], true, function(error, data) {
|
||||
var versions;
|
||||
versions = _.keys(data);
|
||||
return callback(error, _.first(versions));
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
exports.isUpdated = function(name, currentVersion, callback) {
|
||||
return exports.getLatestVersion(name, function(error, latestVersion) {
|
||||
if (error != null) {
|
||||
return callback(error);
|
||||
}
|
||||
return callback(null, currentVersion === latestVersion);
|
||||
});
|
||||
};
|
||||
|
||||
}).call(this);
|
@ -177,6 +177,9 @@ Use this command to associate a project directory with a resin application.
|
||||
|
||||
This command adds a 'resin' git remote to the directory and runs git init if necessary.
|
||||
|
||||
Notice this command asks for confirmation interactively.
|
||||
You can avoid this by passing the `--yes` boolean option.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin app associate MyApp
|
||||
|
@ -6,7 +6,6 @@ coffee = require('gulp-coffee')
|
||||
markedMan = require('gulp-marked-man')
|
||||
coffeelint = require('gulp-coffeelint')
|
||||
shell = require('gulp-shell')
|
||||
mochaNotifierReporter = require('mocha-notifier-reporter')
|
||||
packageJSON = require('./package.json')
|
||||
|
||||
OPTIONS =
|
||||
@ -30,7 +29,7 @@ gulp.task 'man', ->
|
||||
gulp.task 'test', ->
|
||||
gulp.src(OPTIONS.files.tests, read: false)
|
||||
.pipe(mocha({
|
||||
reporter: mochaNotifierReporter.decorate('landing')
|
||||
reporter: 'min'
|
||||
}))
|
||||
|
||||
gulp.task 'coffee', [ 'test', 'lint', 'json' ], ->
|
||||
|
@ -44,13 +44,15 @@ exports.create =
|
||||
return callback(new Error('You already have an application with that name!'))
|
||||
|
||||
return callback(null, options.type) if options.type?
|
||||
|
||||
resin.models.device.getSupportedDeviceTypes (error, deviceTypes) ->
|
||||
return callback(error) if error?
|
||||
visuals.widgets.select('Select a type', deviceTypes, callback)
|
||||
visuals.patterns.selectDeviceType(callback)
|
||||
|
||||
(type, callback) ->
|
||||
resin.models.application.create(params.name, type, callback)
|
||||
options.type = type
|
||||
resin.models.application.create(params.name, options.type, callback)
|
||||
|
||||
(applicationId, callback) ->
|
||||
console.info("Application created: #{params.name} (#{options.type}, id #{applicationId})")
|
||||
return callback()
|
||||
|
||||
], done)
|
||||
|
||||
@ -146,11 +148,15 @@ exports.associate =
|
||||
|
||||
This command adds a 'resin' git remote to the directory and runs git init if necessary.
|
||||
|
||||
Notice this command asks for confirmation interactively.
|
||||
You can avoid this by passing the `--yes` boolean option.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin app associate MyApp
|
||||
$ resin app associate MyApp --project my/app/directory
|
||||
'''
|
||||
options: [ commandOptions.yes ]
|
||||
permission: 'user'
|
||||
action: (params, options, done) ->
|
||||
currentDirectory = process.cwd()
|
||||
@ -158,6 +164,17 @@ exports.associate =
|
||||
async.waterfall [
|
||||
|
||||
(callback) ->
|
||||
resin.models.application.has(params.name, callback)
|
||||
|
||||
(hasApp, callback) ->
|
||||
if not hasApp
|
||||
return callback(new Error("Invalid application: #{params.name}"))
|
||||
|
||||
message = "Are you sure you want to associate #{currentDirectory} with #{params.name}?"
|
||||
visuals.patterns.confirm(options.yes, message, callback)
|
||||
|
||||
(confirmed, callback) ->
|
||||
return done() if not confirmed
|
||||
vcs.initialize(currentDirectory, callback)
|
||||
|
||||
(callback) ->
|
||||
@ -196,7 +213,12 @@ exports.init =
|
||||
|
||||
(callback) ->
|
||||
currentDirectoryBasename = path.basename(currentDirectory)
|
||||
visuals.widgets.ask('What is the name of your application?', currentDirectoryBasename, callback)
|
||||
visuals.form.ask
|
||||
label: 'What is the name of your application?'
|
||||
name: 'application'
|
||||
type: 'text'
|
||||
value: currentDirectoryBasename
|
||||
, callback
|
||||
|
||||
(applicationName, callback) ->
|
||||
|
||||
|
@ -6,7 +6,7 @@ resin = require('resin-sdk')
|
||||
settings = require('resin-settings-client')
|
||||
visuals = require('resin-cli-visuals')
|
||||
|
||||
TOKEN_URL = url.resolve(settings.get('remoteUrl'), '/preferences')
|
||||
TOKEN_URL = url.resolve(settings.get('dashboardUrl'), '/preferences')
|
||||
|
||||
exports.login =
|
||||
signature: 'login [token]'
|
||||
@ -25,30 +25,36 @@ exports.login =
|
||||
"""
|
||||
action: (params, options, done) ->
|
||||
|
||||
console.info """
|
||||
To login to the Resin CLI, you need your unique token, which is accesible from
|
||||
the preferences page at #{TOKEN_URL}
|
||||
|
||||
Attempting to open a browser at that location...
|
||||
"""
|
||||
|
||||
async.waterfall([
|
||||
|
||||
(callback) ->
|
||||
return callback(null, params.token) if params.token?
|
||||
|
||||
console.info """
|
||||
To login to the Resin CLI, you need your unique token, which is accesible from
|
||||
the preferences page at #{TOKEN_URL}
|
||||
|
||||
Attempting to open a browser at that location...
|
||||
"""
|
||||
|
||||
open TOKEN_URL, (error) ->
|
||||
if error?
|
||||
console.error """
|
||||
Unable to open a web browser in the current environment.
|
||||
Please visit #{TOKEN_URL} manually.
|
||||
"""
|
||||
return callback()
|
||||
|
||||
(callback) ->
|
||||
return callback(null, params.token) if params.token?
|
||||
visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback)
|
||||
visuals.patterns.loginWithToken(callback)
|
||||
|
||||
(token, callback) ->
|
||||
resin.auth.loginWithToken(token, done)
|
||||
resin.auth.loginWithToken(token, callback)
|
||||
|
||||
(callback) ->
|
||||
resin.auth.whoami(callback)
|
||||
|
||||
(username, callback) ->
|
||||
console.info("Successfully logged in as: #{username}")
|
||||
return callback()
|
||||
|
||||
], done)
|
||||
|
||||
@ -125,7 +131,7 @@ exports.signup =
|
||||
|
||||
(callback) ->
|
||||
return callback(null, options) if hasOptionCredentials
|
||||
visuals.widgets.register(callback)
|
||||
visuals.patterns.register(callback)
|
||||
|
||||
(credentials, callback) ->
|
||||
resin.auth.register credentials, (error, token) ->
|
||||
|
@ -16,6 +16,18 @@ exports.application = _.defaults
|
||||
required: 'You have to specify an application'
|
||||
, exports.optionalApplication
|
||||
|
||||
exports.optionalDevice =
|
||||
signature: 'device'
|
||||
parameter: 'device'
|
||||
description: 'device name'
|
||||
alias: 'd'
|
||||
|
||||
exports.booleanDevice =
|
||||
signature: 'device'
|
||||
description: 'device name'
|
||||
boolean: true
|
||||
alias: 'd'
|
||||
|
||||
exports.network =
|
||||
signature: 'network'
|
||||
parameter: 'network'
|
||||
|
@ -1,3 +1,4 @@
|
||||
fse = require('fs-extra')
|
||||
capitano = require('capitano')
|
||||
_ = require('lodash-contrib')
|
||||
path = require('path')
|
||||
@ -5,13 +6,17 @@ async = require('async')
|
||||
resin = require('resin-sdk')
|
||||
visuals = require('resin-cli-visuals')
|
||||
vcs = require('resin-vcs')
|
||||
manager = require('resin-image-manager')
|
||||
image = require('resin-image')
|
||||
inject = require('resin-config-inject')
|
||||
registerDevice = require('resin-register-device')
|
||||
pine = require('resin-pine')
|
||||
tmp = require('tmp')
|
||||
|
||||
# Cleanup the temporary files even when an uncaught exception occurs
|
||||
tmp.setGracefulCleanup()
|
||||
|
||||
commandOptions = require('./command-options')
|
||||
osAction = require('./os')
|
||||
|
||||
exports.list =
|
||||
signature: 'devices'
|
||||
@ -49,7 +54,7 @@ exports.list =
|
||||
'last_seen'
|
||||
]
|
||||
|
||||
return done()
|
||||
return done(null, devices)
|
||||
|
||||
exports.info =
|
||||
signature: 'device <name>'
|
||||
@ -140,7 +145,12 @@ exports.rename =
|
||||
(callback) ->
|
||||
if not _.isEmpty(params.newName)
|
||||
return callback(null, params.newName)
|
||||
visuals.widgets.ask('How do you want to name this device?', null, callback)
|
||||
|
||||
visuals.form.ask
|
||||
label: 'How do you want to name this device?'
|
||||
name: 'device'
|
||||
type: 'text'
|
||||
, callback
|
||||
|
||||
(newName, callback) ->
|
||||
resin.models.device.rename(params.name, newName, callback)
|
||||
@ -217,9 +227,7 @@ exports.init =
|
||||
Notice this command asks for confirmation interactively.
|
||||
You can avoid this by passing the `--yes` boolean option.
|
||||
|
||||
You can quiet the progress bar by passing the `--quiet` boolean option.
|
||||
|
||||
You may have to unmount the device before attempting this operation.
|
||||
You can quiet the progress bar and other logging information by passing the `--quiet` boolean option.
|
||||
|
||||
You need to configure the network type and other settings:
|
||||
|
||||
@ -246,8 +254,14 @@ exports.init =
|
||||
commandOptions.wifiKey
|
||||
]
|
||||
permission: 'user'
|
||||
root: true
|
||||
action: (params, options, done) ->
|
||||
|
||||
networkOptions =
|
||||
network: options.network
|
||||
wifiSsid: options.ssid
|
||||
wifiKey: options.key
|
||||
|
||||
async.waterfall([
|
||||
|
||||
(callback) ->
|
||||
@ -255,7 +269,13 @@ exports.init =
|
||||
vcs.getApplicationName(process.cwd(), callback)
|
||||
|
||||
(applicationName, callback) ->
|
||||
params.name = applicationName
|
||||
options.application = applicationName
|
||||
resin.models.application.has(options.application, callback)
|
||||
|
||||
(hasApplication, callback) ->
|
||||
if not hasApplication
|
||||
return callback(new Error("Invalid application: #{options.application}"))
|
||||
|
||||
return callback(null, params.device) if params.device?
|
||||
visuals.patterns.selectDrive(callback)
|
||||
|
||||
@ -266,27 +286,82 @@ exports.init =
|
||||
|
||||
(confirmed, callback) ->
|
||||
return done() if not confirmed
|
||||
options.yes = confirmed
|
||||
|
||||
tmp.file
|
||||
prefix: 'resin-image-'
|
||||
postfix: '.img'
|
||||
, callback
|
||||
|
||||
(tmpPath, tmpFd, cleanupCallback, callback) ->
|
||||
options.output = tmpPath
|
||||
|
||||
# TODO: Figure out how to make use of capitano.run()
|
||||
# here given the complexity of converting network
|
||||
# params object to string options
|
||||
osAction.download.action params, options, (error, outputFile) ->
|
||||
return callback() if networkOptions.network?
|
||||
visuals.patterns.selectNetworkParameters (error, parameters) ->
|
||||
return callback(error) if error?
|
||||
return callback(null, outputFile, cleanupCallback)
|
||||
|
||||
(outputFile, cleanupCallback, callback) ->
|
||||
capitano.run "os install #{outputFile} #{params.device}", (error) ->
|
||||
return callback(error) if error?
|
||||
cleanupCallback()
|
||||
_.extend(networkOptions, parameters)
|
||||
return callback()
|
||||
|
||||
(callback) ->
|
||||
console.info("Checking application: #{options.application}")
|
||||
resin.models.application.get(options.application, callback)
|
||||
|
||||
(application, callback) ->
|
||||
async.parallel
|
||||
|
||||
manifest: (callback) ->
|
||||
console.info('Getting device manifest for the application')
|
||||
resin.models.device.getManifestBySlug(application.device_type, callback)
|
||||
|
||||
config: (callback) ->
|
||||
console.info('Fetching application configuration')
|
||||
resin.models.application.getConfiguration(options.application, networkOptions, callback)
|
||||
|
||||
, callback
|
||||
|
||||
(results, callback) ->
|
||||
console.info('Associating the device')
|
||||
|
||||
registerDevice.register pine, results.config, (error, device) ->
|
||||
return callback(error) if error?
|
||||
|
||||
# Associate a device
|
||||
results.config.deviceId = device.id
|
||||
results.config.uuid = device.uuid
|
||||
|
||||
params.uuid = results.config.uuid
|
||||
|
||||
return callback(null, results)
|
||||
|
||||
(results, callback) ->
|
||||
console.info('Configuring device operating system image')
|
||||
|
||||
if process.env.DEBUG
|
||||
console.log(results.config)
|
||||
|
||||
bar = new visuals.widgets.Progress('Downloading Device OS')
|
||||
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)')
|
||||
|
||||
manager.configure results.manifest, results.config, (error, imagePath, removeCallback) ->
|
||||
spinner.stop()
|
||||
return callback(error, imagePath, removeCallback)
|
||||
, (state) ->
|
||||
if state?
|
||||
bar.update(state)
|
||||
else
|
||||
spinner.start()
|
||||
|
||||
(configuredImagePath, removeCallback, callback) ->
|
||||
console.info('Attempting to write operating system image to drive')
|
||||
|
||||
bar = new visuals.widgets.Progress('Writing Device OS')
|
||||
image.write
|
||||
device: params.device
|
||||
image: configuredImagePath
|
||||
progress: _.bind(bar.update, bar)
|
||||
, (error) ->
|
||||
return callback(error) if error?
|
||||
return callback(null, configuredImagePath, removeCallback)
|
||||
|
||||
(temporalImagePath, removeCallback, callback) ->
|
||||
console.info('Image written successfully')
|
||||
removeCallback(callback)
|
||||
|
||||
(callback) ->
|
||||
resin.models.device.getByUUID(params.uuid, callback)
|
||||
|
||||
(device, callback) ->
|
||||
console.info("Device created: #{device.name}")
|
||||
return callback(null, device.name)
|
||||
|
||||
], done)
|
||||
|
@ -1,3 +1,4 @@
|
||||
async = require('async')
|
||||
_ = require('lodash-contrib')
|
||||
resin = require('resin-sdk')
|
||||
visuals = require('resin-cli-visuals')
|
||||
@ -7,20 +8,22 @@ exports.list =
|
||||
signature: 'envs'
|
||||
description: 'list all environment variables'
|
||||
help: '''
|
||||
Use this command to list all environment variables for a particular application.
|
||||
Notice we will support per-device environment variables soon.
|
||||
Use this command to list all environment variables for
|
||||
a particular application or device.
|
||||
|
||||
This command lists all custom environment variables set on the devices running
|
||||
the application. If you want to see all environment variables, including private
|
||||
This command lists all custom environment variables.
|
||||
If you want to see all environment variables, including private
|
||||
ones used by resin, use the verbose option.
|
||||
|
||||
Example:
|
||||
|
||||
$ resin envs --application 91
|
||||
$ resin envs --application 91 --verbose
|
||||
$ resin envs --application MyApp
|
||||
$ resin envs --application MyApp --verbose
|
||||
$ resin envs --device MyDevice
|
||||
'''
|
||||
options: [
|
||||
commandOptions.application
|
||||
commandOptions.optionalApplication
|
||||
commandOptions.optionalDevice
|
||||
|
||||
{
|
||||
signature: 'verbose'
|
||||
@ -31,19 +34,31 @@ exports.list =
|
||||
]
|
||||
permission: 'user'
|
||||
action: (params, options, done) ->
|
||||
resin.models.environmentVariables.getAllByApplication options.application, (error, environmentVariables) ->
|
||||
return done(error) if error?
|
||||
async.waterfall([
|
||||
|
||||
if not options.verbose
|
||||
environmentVariables = _.reject(environmentVariables, resin.models.environmentVariables.isSystemVariable)
|
||||
(callback) ->
|
||||
if options.application?
|
||||
resin.models.environmentVariables.getAllByApplication(options.application, callback)
|
||||
else if options.device?
|
||||
resin.models.environmentVariables.device.getAll(options.device, callback)
|
||||
else
|
||||
return callback(new Error('You must specify an application or device'))
|
||||
|
||||
console.log visuals.widgets.table.horizontal environmentVariables, [
|
||||
'id'
|
||||
'name'
|
||||
'value'
|
||||
]
|
||||
(environmentVariables, callback) ->
|
||||
|
||||
return done()
|
||||
if not options.verbose
|
||||
isSystemVariable = resin.models.environmentVariables.isSystemVariable
|
||||
environmentVariables = _.reject(environmentVariables, isSystemVariable)
|
||||
|
||||
console.log visuals.widgets.table.horizontal environmentVariables, [
|
||||
'id'
|
||||
'name'
|
||||
'value'
|
||||
]
|
||||
|
||||
return callback()
|
||||
|
||||
], done)
|
||||
|
||||
exports.remove =
|
||||
signature: 'env rm <id>'
|
||||
@ -56,16 +71,25 @@ exports.remove =
|
||||
Notice this command asks for confirmation interactively.
|
||||
You can avoid this by passing the `--yes` boolean option.
|
||||
|
||||
If you want to eliminate a device environment variable, pass the `--device` boolean option.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin env rm 215
|
||||
$ resin env rm 215 --yes
|
||||
$ resin env rm 215 --device
|
||||
'''
|
||||
options: [ commandOptions.yes ]
|
||||
options: [
|
||||
commandOptions.yes
|
||||
commandOptions.booleanDevice
|
||||
]
|
||||
permission: 'user'
|
||||
action: (params, options, done) ->
|
||||
visuals.patterns.remove 'environment variable', options.yes, (callback) ->
|
||||
resin.models.environmentVariables.remove(params.id, callback)
|
||||
if options.device
|
||||
resin.models.environmentVariables.device.remove(params.id, callback)
|
||||
else
|
||||
resin.models.environmentVariables.remove(params.id, callback)
|
||||
, done
|
||||
|
||||
exports.add =
|
||||
@ -74,20 +98,25 @@ exports.add =
|
||||
help: '''
|
||||
Use this command to add an enviroment variable to an application.
|
||||
|
||||
You need to pass the `--application` option.
|
||||
|
||||
If value is omitted, the tool will attempt to use the variable's value
|
||||
as defined in your host machine.
|
||||
|
||||
Use the `--device` option if you want to assign the environment variable
|
||||
to a specific device.
|
||||
|
||||
If the value is grabbed from the environment, a warning message will be printed.
|
||||
Use `--quiet` to remove it.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin env add EDITOR vim -a 91
|
||||
$ resin env add TERM -a 91
|
||||
$ resin env add EDITOR vim --application MyApp
|
||||
$ resin env add TERM --application MyApp
|
||||
$ resin env add EDITOR vim --device MyDevice
|
||||
'''
|
||||
options: [ commandOptions.application ]
|
||||
options: [
|
||||
commandOptions.optionalApplication
|
||||
commandOptions.optionalDevice
|
||||
]
|
||||
permission: 'user'
|
||||
action: (params, options, done) ->
|
||||
if not params.value?
|
||||
@ -98,7 +127,12 @@ exports.add =
|
||||
else
|
||||
console.info("Warning: using #{params.key}=#{params.value} from host environment")
|
||||
|
||||
resin.models.environmentVariables.create(options.application, params.key, params.value, done)
|
||||
if options.application?
|
||||
resin.models.environmentVariables.create(options.application, params.key, params.value, done)
|
||||
else if options.device?
|
||||
resin.models.environmentVariables.device.create(options.device, params.key, params.value, done)
|
||||
else
|
||||
return done(new Error('You must specify an application or device'))
|
||||
|
||||
exports.rename =
|
||||
signature: 'env rename <id> <value>'
|
||||
@ -106,10 +140,17 @@ exports.rename =
|
||||
help: '''
|
||||
Use this command to rename an enviroment variable from an application.
|
||||
|
||||
Pass the `--device` boolean option if you want to rename a device environment variable.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin env rename 376 emacs
|
||||
$ resin env rename 376 emacs --device
|
||||
'''
|
||||
permission: 'user'
|
||||
options: [ commandOptions.booleanDevice ]
|
||||
action: (params, options, done) ->
|
||||
resin.models.environmentVariables.update(params.id, params.value, done)
|
||||
if options.device
|
||||
resin.models.environmentVariables.device.update(params.id, params.value, done)
|
||||
else
|
||||
resin.models.environmentVariables.update(params.id, params.value, done)
|
||||
|
@ -30,34 +30,33 @@ exports.list =
|
||||
|
||||
console.log visuals.widgets.table.horizontal examplesData, [
|
||||
'id'
|
||||
'name'
|
||||
'display_name'
|
||||
'repository'
|
||||
'author'
|
||||
]
|
||||
|
||||
exports.info =
|
||||
signature: 'example <id>'
|
||||
signature: 'example <name>'
|
||||
description: 'list a single example application'
|
||||
help: '''
|
||||
Use this command to show information of a single example application
|
||||
|
||||
Example:
|
||||
|
||||
$ resin example 3
|
||||
$ resin example cimon
|
||||
'''
|
||||
permission: 'user'
|
||||
action: (params, options, done) ->
|
||||
id = params.id - 1
|
||||
example = examplesData[id]
|
||||
example = _.findWhere(examplesData, name: params.name)
|
||||
|
||||
if not example?
|
||||
return done(new Error("Unknown example: #{id}"))
|
||||
return done(new Error("Unknown example: #{params.name}"))
|
||||
|
||||
example.id = id
|
||||
example.author ?= 'Unknown'
|
||||
|
||||
console.log visuals.widgets.table.vertical example, [
|
||||
'id'
|
||||
'name'
|
||||
'display_name'
|
||||
'description'
|
||||
'author'
|
||||
@ -67,7 +66,7 @@ exports.info =
|
||||
return done()
|
||||
|
||||
exports.clone =
|
||||
signature: 'example clone <id>'
|
||||
signature: 'example clone <name>'
|
||||
description: 'clone an example application'
|
||||
help: '''
|
||||
Use this command to clone an example application to the current directory
|
||||
@ -77,14 +76,14 @@ exports.clone =
|
||||
|
||||
Example:
|
||||
|
||||
$ resin example clone 3
|
||||
$ resin example clone cimon
|
||||
'''
|
||||
permission: 'user'
|
||||
action: (params, options, done) ->
|
||||
example = examplesData[params.id - 1]
|
||||
example = _.findWhere(examplesData, name: params.name)
|
||||
|
||||
if not example?
|
||||
return done(new Error("Unknown example: #{id}"))
|
||||
return done(new Error("Unknown example: #{params.name}"))
|
||||
|
||||
currentDirectory = process.cwd()
|
||||
destination = path.join(currentDirectory, example.name)
|
||||
|
@ -9,7 +9,6 @@ module.exports =
|
||||
logs: require('./logs')
|
||||
notes: require('./notes')
|
||||
preferences: require('./preferences')
|
||||
os: require('./os')
|
||||
help: require('./help')
|
||||
examples: require('./examples')
|
||||
plugin: require('./plugin')
|
||||
|
@ -1,3 +1,4 @@
|
||||
settings = require('resin-settings-client')
|
||||
packageJSON = require('../../package.json')
|
||||
|
||||
exports.version =
|
||||
@ -9,3 +10,16 @@ exports.version =
|
||||
action: (params, options, done) ->
|
||||
console.log(packageJSON.version)
|
||||
return done()
|
||||
|
||||
exports.config =
|
||||
signature: 'config'
|
||||
description: 'see your current configuration'
|
||||
help: '''
|
||||
See your current Resin CLI configuration.
|
||||
|
||||
Configuration lives in $HOME/.resin/config.
|
||||
'''
|
||||
action: (params, options, done) ->
|
||||
for key, value of settings.get()
|
||||
console.log("#{key}: #{value}")
|
||||
return done()
|
||||
|
@ -40,9 +40,6 @@ exports.info =
|
||||
action: (params, options, done) ->
|
||||
resin.models.key.get params.id, (error, key) ->
|
||||
return done(error) if error?
|
||||
|
||||
key.public_key = '\n' + visuals.helpers.chop(key.public_key, SSH_KEY_WIDTH)
|
||||
|
||||
console.log(visuals.widgets.table.vertical(key, [ 'id', 'title', 'public_key' ]))
|
||||
return done()
|
||||
|
||||
|
@ -3,7 +3,7 @@ resin = require('resin-sdk')
|
||||
|
||||
LOGS_HISTORY_COUNT = 200
|
||||
|
||||
exports.logs =
|
||||
module.exports =
|
||||
signature: 'logs <uuid>'
|
||||
description: 'show device logs'
|
||||
help: '''
|
||||
|
@ -1,171 +0,0 @@
|
||||
capitano = require('capitano')
|
||||
_ = require('lodash-contrib')
|
||||
os = require('os')
|
||||
async = require('async')
|
||||
path = require('path')
|
||||
mkdirp = require('mkdirp')
|
||||
resin = require('resin-sdk')
|
||||
image = require('resin-image')
|
||||
visuals = require('resin-cli-visuals')
|
||||
commandOptions = require('./command-options')
|
||||
npm = require('../npm')
|
||||
packageJSON = require('../../package.json')
|
||||
elevate = require('../elevate')
|
||||
|
||||
exports.download =
|
||||
signature: 'os download <name>'
|
||||
description: 'download device OS'
|
||||
help: '''
|
||||
Use this command to download the device OS configured to a specific network.
|
||||
|
||||
Ethernet:
|
||||
You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".
|
||||
|
||||
Wifi:
|
||||
You can setup the device OS to use wifi by setting the `--network` option to "wifi".
|
||||
If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.
|
||||
|
||||
Alternatively, you can omit all kind of network configuration options to configure interactively.
|
||||
|
||||
You have to specify an output location with the `--output` option.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin os download MyApp --output ~/MyResinOS.zip
|
||||
$ resin os download MyApp --network ethernet --output ~/MyResinOS.zip
|
||||
$ resin os download MyApp --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip
|
||||
$ resin os download MyApp --network ethernet --output ~/MyResinOS.zip
|
||||
'''
|
||||
options: [
|
||||
commandOptions.network
|
||||
commandOptions.wifiSsid
|
||||
commandOptions.wifiKey
|
||||
|
||||
{
|
||||
signature: 'output'
|
||||
parameter: 'output'
|
||||
description: 'output file'
|
||||
alias: 'o'
|
||||
required: 'You need to specify an output file'
|
||||
}
|
||||
]
|
||||
permission: 'user'
|
||||
action: (params, options, done) ->
|
||||
resin.models.application.get params.name, (error, application) ->
|
||||
return done(error) if error?
|
||||
|
||||
osParams =
|
||||
network: options.network
|
||||
wifiSsid: options.ssid
|
||||
wifiKey: options.key
|
||||
appId: application.id
|
||||
|
||||
async.waterfall [
|
||||
|
||||
(callback) ->
|
||||
return callback() if osParams.network?
|
||||
visuals.patterns.selectNetworkParameters (error, parameters) ->
|
||||
return callback(error) if error?
|
||||
_.extend(osParams, parameters)
|
||||
return callback()
|
||||
|
||||
(callback) ->
|
||||
|
||||
# We need to ensure this directory exists
|
||||
mkdirp(path.dirname(options.output), _.unary(callback))
|
||||
|
||||
(callback) ->
|
||||
console.info("Destination file: #{options.output}\n")
|
||||
|
||||
bar = new visuals.widgets.Progress('Downloading Device OS')
|
||||
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)')
|
||||
|
||||
resin.models.os.download osParams, options.output, (error) ->
|
||||
spinner.stop()
|
||||
return callback(error) if error?
|
||||
, (state) ->
|
||||
if state?
|
||||
bar.update(state)
|
||||
else
|
||||
spinner.start()
|
||||
|
||||
], (error) ->
|
||||
return done(error) if error?
|
||||
console.info("\nFinished downloading #{options.output}")
|
||||
return done(null, options.output)
|
||||
|
||||
exports.install =
|
||||
signature: 'os install <image> [device]'
|
||||
description: 'write an operating system image to a device'
|
||||
help: '''
|
||||
Use this command to write an operating system image to a device.
|
||||
|
||||
Note that this command requires admin privileges.
|
||||
|
||||
If `device` is omitted, you will be prompted to select a device interactively.
|
||||
|
||||
Notice this command asks for confirmation interactively.
|
||||
You can avoid this by passing the `--yes` boolean option.
|
||||
|
||||
You can quiet the progress bar by passing the `--quiet` boolean option.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin os install rpi.iso /dev/disk2
|
||||
'''
|
||||
options: [ commandOptions.yes ]
|
||||
permission: 'user'
|
||||
action: (params, options, done) ->
|
||||
|
||||
async.waterfall [
|
||||
|
||||
(callback) ->
|
||||
npm.isUpdated(packageJSON.name, packageJSON.version, callback)
|
||||
|
||||
(isUpdated, callback) ->
|
||||
return callback() if isUpdated
|
||||
|
||||
console.info '''
|
||||
Resin CLI is outdated.
|
||||
|
||||
In order to avoid device compatibility issues, this command
|
||||
requires that you have the Resin CLI updated.
|
||||
|
||||
Updating now...
|
||||
'''
|
||||
|
||||
capitano.run('update', _.unary(callback))
|
||||
|
||||
(callback) ->
|
||||
return callback(null, params.device) if params.device?
|
||||
|
||||
# TODO: See if we can reuse the drives action somehow here
|
||||
visuals.patterns.selectDrive (error, device) ->
|
||||
return callback(error) if error?
|
||||
|
||||
if not device?
|
||||
return callback(new Error('No removable devices available'))
|
||||
|
||||
return callback(null, device)
|
||||
|
||||
(device, callback) ->
|
||||
params.device = device
|
||||
message = "This will completely erase #{params.device}. Are you sure you want to continue?"
|
||||
visuals.patterns.confirm(options.yes, message, callback)
|
||||
|
||||
(confirmed, callback) ->
|
||||
return done() if not confirmed
|
||||
bar = new visuals.widgets.Progress('Writing Device OS')
|
||||
params.progress = _.bind(bar.update, bar)
|
||||
image.write(params, callback)
|
||||
|
||||
], (error) ->
|
||||
return done() if not error?
|
||||
|
||||
if elevate.shouldElevate(error) and not options.fromScript
|
||||
|
||||
# Need to escape every path to avoid errors
|
||||
resinWritePath = "\"#{path.join(__dirname, '..', '..', 'bin', 'resin-write')}\""
|
||||
elevate.run("\"#{process.argv[0]}\" #{resinWritePath} \"#{params.image}\" \"#{params.device}\"")
|
||||
else
|
||||
return done(error)
|
@ -1,7 +1,4 @@
|
||||
_ = require('lodash')
|
||||
child_process = require('child_process')
|
||||
president = require('president')
|
||||
npm = require('../npm')
|
||||
selfupdate = require('selfupdate')
|
||||
packageJSON = require('../../package.json')
|
||||
|
||||
exports.update =
|
||||
@ -23,36 +20,7 @@ exports.update =
|
||||
$ resin update
|
||||
'''
|
||||
action: (params, options, done) ->
|
||||
npm.isUpdated packageJSON.name, packageJSON.version, (error, isUpdated) ->
|
||||
selfupdate.update packageJSON, (error, version) ->
|
||||
return done(error) if error?
|
||||
|
||||
if isUpdated
|
||||
return done(new Error('You\'re already running the latest version.'))
|
||||
|
||||
onUpdate = (error, stdout, stderr) ->
|
||||
return done(error) if error?
|
||||
return done(new Error(stderr)) if not _.isEmpty(stderr)
|
||||
console.info("Upgraded #{packageJSON.name}.")
|
||||
return done()
|
||||
|
||||
command = "npm install --global #{packageJSON.name}"
|
||||
|
||||
# Attempting to self update using the NPM API was not considered safe.
|
||||
# A safer thing to do is to call npm as a child process
|
||||
# https://github.com/npm/npm/issues/7723
|
||||
child_process.exec command, (error, stdout, stderr) ->
|
||||
return onUpdate(null, stdout, stderr) if not error?
|
||||
|
||||
if _.any [
|
||||
|
||||
# 3 is equivalent to EACCES for NPM
|
||||
error.code is 3
|
||||
|
||||
error.code is 'EPERM'
|
||||
error.code is 'ACCES'
|
||||
]
|
||||
return president.execute(command, onUpdate)
|
||||
|
||||
return done(error)
|
||||
|
||||
|
||||
console.info("Updated #{packageJSON.name} to version #{version}.")
|
||||
return done()
|
||||
|
@ -8,7 +8,8 @@ plugins = require('./plugins')
|
||||
update = require('./update')
|
||||
|
||||
capitano.permission 'user', (done) ->
|
||||
resin.auth.isLoggedIn (isLoggedIn) ->
|
||||
resin.auth.isLoggedIn (error, isLoggedIn) ->
|
||||
return done(error) if error?
|
||||
if not isLoggedIn
|
||||
return done(new Error('You have to log in'))
|
||||
return done()
|
||||
@ -47,6 +48,7 @@ capitano.globalOption
|
||||
|
||||
# ---------- Info Module ----------
|
||||
capitano.command(actions.info.version)
|
||||
capitano.command(actions.info.config)
|
||||
|
||||
# ---------- Help Module ----------
|
||||
capitano.command(actions.help.help)
|
||||
@ -60,21 +62,21 @@ capitano.command(actions.auth.whoami)
|
||||
# ---------- App Module ----------
|
||||
capitano.command(actions.app.create)
|
||||
capitano.command(actions.app.list)
|
||||
capitano.command(actions.app.info)
|
||||
capitano.command(actions.app.remove)
|
||||
capitano.command(actions.app.restart)
|
||||
capitano.command(actions.app.associate)
|
||||
capitano.command(actions.app.init)
|
||||
capitano.command(actions.app.info)
|
||||
|
||||
# ---------- Device Module ----------
|
||||
capitano.command(actions.device.list)
|
||||
capitano.command(actions.device.supported)
|
||||
capitano.command(actions.device.rename)
|
||||
capitano.command(actions.device.init)
|
||||
capitano.command(actions.device.await)
|
||||
capitano.command(actions.device.info)
|
||||
capitano.command(actions.device.remove)
|
||||
capitano.command(actions.device.identify)
|
||||
capitano.command(actions.device.await)
|
||||
|
||||
# ---------- Drive Module ----------
|
||||
capitano.command(actions.drive.list)
|
||||
@ -98,11 +100,7 @@ capitano.command(actions.env.rename)
|
||||
capitano.command(actions.env.remove)
|
||||
|
||||
# ---------- Logs Module ----------
|
||||
capitano.command(actions.logs.logs)
|
||||
|
||||
# ---------- OS Module ----------
|
||||
capitano.command(actions.os.download)
|
||||
capitano.command(actions.os.install)
|
||||
capitano.command(actions.logs)
|
||||
|
||||
# ---------- Examples Module ----------
|
||||
capitano.command(actions.examples.list)
|
||||
@ -135,7 +133,7 @@ async.waterfall([
|
||||
(callback) ->
|
||||
cli = capitano.parse(process.argv)
|
||||
|
||||
if cli.global.quiet
|
||||
if cli.global.quiet or not process.stdout.isTTY
|
||||
console.info = _.noop
|
||||
|
||||
if cli.global.project?
|
||||
|
@ -1,29 +0,0 @@
|
||||
npm = require('npm')
|
||||
async = require('async')
|
||||
_ = require('lodash-contrib')
|
||||
|
||||
exports.getLatestVersion = (name, callback) ->
|
||||
async.waterfall([
|
||||
|
||||
(callback) ->
|
||||
options =
|
||||
|
||||
# TODO: There is no way to quiet npm install completely.
|
||||
# Some output is still shown once the module is updated
|
||||
# https://github.com/npm/npm/issues/2040
|
||||
loglevel: 'silent'
|
||||
global: true
|
||||
|
||||
npm.load(options, _.unary(callback))
|
||||
|
||||
(callback) ->
|
||||
npm.commands.view [ name ], true, (error, data) ->
|
||||
versions = _.keys(data)
|
||||
return callback(error, _.first(versions))
|
||||
|
||||
], callback)
|
||||
|
||||
exports.isUpdated = (name, currentVersion, callback) ->
|
||||
exports.getLatestVersion name, (error, latestVersion) ->
|
||||
return callback(error) if error?
|
||||
return callback(null, currentVersion is latestVersion)
|
@ -1,4 +1,4 @@
|
||||
.TH "RESIN" "1" "March 2015" "" ""
|
||||
.TH "RESIN" "1" "May 2015" "" ""
|
||||
.SH "NAME"
|
||||
\fBresin\fR \- tab completion for resin
|
||||
.SH DESCRIPTION
|
||||
|
@ -1,4 +1,4 @@
|
||||
.TH "RESIN\-PLUGINS" "1" "March 2015" "" ""
|
||||
.TH "RESIN\-PLUGINS" "1" "May 2015" "" ""
|
||||
.SH "NAME"
|
||||
\fBresin-plugins\fR \- Creating Resin CLI plugins
|
||||
.SH DESCRIPTION
|
||||
|
@ -1,4 +1,4 @@
|
||||
.TH "RESIN" "1" "March 2015" "" ""
|
||||
.TH "RESIN" "1" "May 2015" "" ""
|
||||
.SH "NAME"
|
||||
\fBresin\fR \- command line tool to interact with resin\.io
|
||||
.SH SYNOPSIS
|
||||
|
24
package.json
24
package.json
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "resin-cli",
|
||||
"version": "0.10.4",
|
||||
"version": "0.11.1",
|
||||
"description": "Git Push to your devices",
|
||||
"main": "./lib/actions/index.coffee",
|
||||
"main": "./build/actions/index.js",
|
||||
"homepage": "https://github.com/resin-io/resin-cli",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -42,29 +42,33 @@
|
||||
"gulp-shell": "^0.2.11",
|
||||
"gulp-util": "~3.0.1",
|
||||
"mocha": "~2.0.1",
|
||||
"mocha-notifier-reporter": "~0.1.0",
|
||||
"run-sequence": "~1.0.2",
|
||||
"sinon": "~1.12.1",
|
||||
"sinon-chai": "~2.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "~0.9.0",
|
||||
"capitano": "~1.5.0",
|
||||
"capitano": "~1.6.0",
|
||||
"coffee-script": "~1.8.0",
|
||||
"conf.js": "^0.1.1",
|
||||
"drivelist": "^1.2.1",
|
||||
"drivelist": "^1.2.2",
|
||||
"fs-extra": "^0.18.3",
|
||||
"lodash": "~2.4.1",
|
||||
"lodash-contrib": "~241.4.14",
|
||||
"mkdirp": "~0.5.0",
|
||||
"nplugm": "^2.2.0",
|
||||
"npm": "^2.6.1",
|
||||
"open": "0.0.5",
|
||||
"president": "^1.0.0",
|
||||
"resin-cli-visuals": "^0.1.0",
|
||||
"resin-sdk": "^1.4.1",
|
||||
"resin-image": "^1.1.1",
|
||||
"resin-settings-client": "^1.0.0",
|
||||
"resin-cli-visuals": "^0.2.0",
|
||||
"resin-config-inject": "^2.0.0",
|
||||
"resin-image": "^1.1.3",
|
||||
"resin-image-manager": "^1.1.0",
|
||||
"resin-pine": "^1.1.1",
|
||||
"resin-register-device": "^1.0.1",
|
||||
"resin-sdk": "^1.7.4",
|
||||
"resin-settings-client": "^1.2.0",
|
||||
"resin-vcs": "^1.2.0",
|
||||
"selfupdate": "^1.1.0",
|
||||
"tmp": "^0.0.25",
|
||||
"underscore.string": "~2.4.0",
|
||||
"update-notifier": "^0.3.1"
|
||||
|
Reference in New Issue
Block a user