Compare commits

...

40 Commits

Author SHA1 Message Date
b29ce3ee04 Resin CLI v0.8.1 2015-04-17 15:09:40 -04:00
2b4394f3ce Merge pull request #21 from resin-io/fix/progress-context
Bind progress update function to avoid context issues
2015-04-17 14:45:17 -04:00
60f704eaa9 Merge pull request #20 from resin-io/fix/elevate-lodash
Add lodash dependency to lib/elevate.coffee
2015-04-17 14:44:50 -04:00
caa4fcf754 Bind progress update function to avoid context issues 2015-04-17 10:11:02 -04:00
c4d1e4244e Upgrade Nplugm to v2.2.0 2015-04-17 10:10:35 -04:00
a6dc155028 Add lodash dependency to lib/elevate.coffee
Depedency was missing and thus elevating functions threw errors.
2015-04-17 09:22:21 -04:00
9c65d11e66 Add documentation anchor support 2015-04-16 11:11:51 -04:00
26f50e7a74 Merge pull request #16 from resin-io/documentation/single-page
Implement Single Page documentation
2015-04-16 09:51:00 -04:00
e4773da1d7 Implement Single Page documentation 2015-04-16 09:49:54 -04:00
dfd8086f63 Resin CLI v0.8.0 2015-04-08 08:37:07 -04:00
ec513c61ad Merge pull request #10 from resin-io/fix/login
Fix bug with login with token
2015-04-08 08:35:57 -04:00
a96ab487ba Fix bug with login with token
The commit was merged from an older branch, in which settings was
still part of the SDK.
2015-04-08 08:25:27 -04:00
cd28c985ce Merge pull request #9 from resin-io/feature/version
Remove bundled node version from version command
2015-04-07 10:56:18 -04:00
727af42ad4 Merge pull request #8 from resin-io/feature/login-with-token
Login with token
2015-04-07 08:12:12 -04:00
e96d411f3e Merge pull request #7 from resin-io/feature/rpi-bundle
Mock local Raspberry Pi bundle
2015-04-07 08:11:43 -04:00
4a7d3d5945 Mock local Raspberry Pi bundle 2015-04-07 08:10:26 -04:00
03f05305cf Fix tiny text issue 2015-04-07 08:07:06 -04:00
af6e9ef85d Merge pull request #6 from resin-io/feature/elevate
Move windosu elevate logic to another module
2015-04-07 08:05:23 -04:00
8533a4a303 Remove bundled node version from version command 2015-04-06 17:18:00 -04:00
85f9234c74 Add .resinconf to gitignore 2015-04-06 17:05:13 -04:00
064afd6705 Fetch TOKEN_URL from the resin sdk 2015-04-06 17:05:13 -04:00
978ff91f87 Remove tab query from preferences token url constant
Tab queries were removed from the web frontend.
2015-04-06 17:04:43 -04:00
5cebbce7bb Update login command documentation 2015-04-06 17:04:03 -04:00
1cd0f02db5 Attempt to open a browser to the token location automatically 2015-04-06 17:04:03 -04:00
77695bb505 Allow login with token 2015-04-06 17:02:53 -04:00
4e4428fdbb Move windosu elevate logic to another module 2015-04-06 16:49:53 -04:00
6e978d74dd Merge pull request #5 from resin-io/feature/hound-config
Add .hound.yml
2015-04-06 10:19:13 -04:00
58974af77b Add .hound.yml 2015-04-06 10:08:49 -04:00
11a0eae7a0 Merge pull request #4 from resin-io/feature/sudo-update
Elevate update command permissions if necessary
2015-04-02 12:53:45 -04:00
2a4ba895e5 Elevate privileges of update command if necessary 2015-04-01 12:51:04 -04:00
19c019076e "resin-cli" "0.7.0" 2015-03-31 13:17:32 -04:00
dfa18d3cb3 Merge pull request #3 from resin-io/fix/selfupdate
Use child_process to trigger self update
2015-03-31 13:15:58 -04:00
782c92885d Use child_process to trigger self update
Using the NPM API led to weird issues.

See https://github.com/npm/npm/issues/7723.
2015-03-24 08:44:02 -04:00
a14dfa6cf1 Fix long line lint warning 2015-03-23 18:32:28 -04:00
f3b6f9d117 Add missing example to device init 2015-03-23 08:25:45 -04:00
63b2b3feb6 Upgrade resin-vcs to 1.1.0 2015-03-23 08:24:29 -04:00
9237dd25ac "resin-cli" "0.6.0" 2015-03-23 08:18:13 -04:00
df9c4ce2fd Reference applications and devices by name 2015-03-23 08:17:55 -04:00
fa5a7abbbf Merge pull request #2 from resin-io/feature/whoami
Reimplement whoami command
2015-03-20 08:55:26 -04:00
cd8bb7882e Reimplement whoami command 2015-03-19 15:57:43 -04:00
74 changed files with 1355 additions and 917 deletions

1
.gitignore vendored
View File

@ -32,3 +32,4 @@ bin/node
release/build
npm-shrinkwrap.json
.resinconf

5
.hound.yml Normal file
View File

@ -0,0 +1,5 @@
coffee_script:
config_file: coffeelint.json
java_script:
enabled: false

View File

@ -50,7 +50,7 @@
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 <id> instead.\n\nExamples:\n\n $ resin apps',
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',
action: function(params, options, done) {
return resin.models.application.getAll(function(error, applications) {
@ -64,12 +64,12 @@
};
exports.info = {
signature: 'app <id>',
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 91',
help: 'Use this command to show detailed information for a single application.\n\nExamples:\n\n $ resin app MyApp',
permission: 'user',
action: function(params, options, done) {
return resin.models.application.get(params.id, function(error, application) {
return resin.models.application.get(params.name, function(error, application) {
if (error != null) {
return done(error);
}
@ -80,32 +80,32 @@
};
exports.restart = {
signature: 'app restart <id>',
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 91',
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) {
return resin.models.application.restart(params.id, done);
return resin.models.application.restart(params.name, done);
}
};
exports.remove = {
signature: 'app rm <id>',
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 91\n $ resin app rm 91 --yes',
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) {
return visuals.patterns.remove('application', options.yes, function(callback) {
return resin.models.application.remove(params.id, callback);
return resin.models.application.remove(params.name, callback);
}, done);
}
};
exports.associate = {
signature: 'app associate <id>',
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 91\n $ resin app associate 91 --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\nExamples:\n\n $ resin app associate MyApp\n $ resin app associate MyApp --project my/app/directory',
permission: 'user',
action: function(params, options, done) {
var currentDirectory;
@ -114,7 +114,7 @@
function(callback) {
return vcs.initialize(currentDirectory, callback);
}, function(callback) {
return resin.models.application.get(params.id, callback);
return resin.models.application.get(params.name, callback);
}, function(application, callback) {
return vcs.addRemote(currentDirectory, application.git_repository, callback);
}
@ -144,10 +144,15 @@
}, function(applicationName, callback) {
return exports.create.action({
name: applicationName
}, options, callback);
}, function(applicationId, callback) {
}, options, function(error) {
if (error != null) {
return callback(error);
}
return callback(null, applicationName);
});
}, function(applicationName, callback) {
return exports.associate.action({
id: applicationId
name: applicationName
}, options, callback);
}
], done);

View File

@ -1,5 +1,7 @@
(function() {
var _, async, resin, url, visuals;
var TOKEN_URL, _, async, open, resin, settings, url, visuals;
open = require('open');
_ = require('lodash-contrib');
@ -9,45 +11,49 @@
resin = require('resin-sdk');
settings = require('resin-settings-client');
visuals = require('resin-cli-visuals');
exports.login = {
signature: 'login',
description: 'login to resin.io',
help: 'Use this command to login to your resin.io account.\nYou need to login before you can use most of the commands this tool provides.\n\nYou can pass your credentials as `--username` and `--password` options, or you can omit the\ncredentials, in which case the tool will present you with an interactive login form.\n\nExamples:\n\n $ resin login --username <username> --password <password>\n $ resin login',
options: [
{
signature: 'username',
parameter: 'username',
description: 'user name',
alias: 'u'
}, {
signature: 'password',
parameter: 'password',
description: 'user password',
alias: 'p'
}
],
exports.whoami = {
signature: 'whoami',
description: 'whoami',
help: 'Use this command to get the logged in user name.\n\nExamples:\n\n $ resin whoami',
permission: 'user',
action: function(params, options, done) {
var hasOptionCredentials;
hasOptionCredentials = !_.isEmpty(options);
if (hasOptionCredentials) {
if (!options.username) {
return done(new Error('Missing username'));
return resin.auth.whoami(function(error, username) {
if (error != null) {
return done(error);
}
if (!options.password) {
return done(new Error('Missing password'));
}
}
console.log(username);
return done();
});
}
};
TOKEN_URL = url.resolve(settings.get('remoteUrl'), '/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 (hasOptionCredentials) {
return callback(null, options);
} else {
return visuals.widgets.login(callback);
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();
});
}, function(callback) {
if (params.token != null) {
return callback(null, params.token);
}
}, function(credentials, callback) {
return resin.auth.login(credentials, callback);
return visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback);
}, function(token, callback) {
return resin.auth.loginWithToken(token, done);
}
], done);
}

View File

@ -13,7 +13,7 @@
exports.optionalApplication = {
signature: 'application',
parameter: 'application',
description: 'application id',
description: 'application name',
alias: ['a', 'app']
};

View File

@ -20,7 +20,7 @@
exports.list = {
signature: 'devices',
description: 'list all devices',
help: 'Use this command to list all devices that belong to a certain application.\n\nExamples:\n\n $ resin devices --application 91',
help: 'Use this command to list all devices that belong to a certain application.\n\nExamples:\n\n $ resin devices --application MyApp',
options: [commandOptions.application],
permission: 'user',
action: function(params, options, done) {
@ -35,12 +35,12 @@
};
exports.info = {
signature: 'device <id>',
signature: 'device <name>',
description: 'list a single device',
help: 'Use this command to show information about a single device.\n\nExamples:\n\n $ resin device 317',
help: 'Use this command to show information about a single device.\n\nExamples:\n\n $ resin device MyDevice',
permission: 'user',
action: function(params, options, done) {
return resin.models.device.get(params.id, function(error, device) {
return resin.models.device.get(params.name, function(error, device) {
if (error != null) {
return done(error);
}
@ -51,14 +51,14 @@
};
exports.remove = {
signature: 'device rm <id>',
signature: 'device rm <name>',
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 317\n $ resin device rm 317 --yes',
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 MyDevice\n $ resin device rm MyDevice --yes',
options: [commandOptions.yes],
permission: 'user',
action: function(params, options, done) {
return visuals.patterns.remove('device', options.yes, function(callback) {
return resin.models.device.remove(params.id, callback);
return resin.models.device.remove(params.name, callback);
}, done);
}
};
@ -74,19 +74,19 @@
};
exports.rename = {
signature: 'device rename <id> [name]',
signature: 'device rename <name> [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 317 MyPi\n $ resin device rename 317',
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 MyDevice MyPi\n $ resin device rename MyDevice',
permission: 'user',
action: function(params, options, done) {
return async.waterfall([
function(callback) {
if (!_.isEmpty(params.name)) {
return callback(null, params.name);
if (!_.isEmpty(params.newName)) {
return callback(null, params.newName);
}
return visuals.widgets.ask('How do you want to name this device?', null, callback);
}, function(name, callback) {
return resin.models.device.rename(params.id, name, callback);
}, function(newName, callback) {
return resin.models.device.rename(params.name, newName, callback);
}
], done);
}
@ -111,7 +111,7 @@
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 --application 91\n $ resin device init --application 91 --network ethernet\n $ resin device init /dev/disk2 --application 91 --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 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 91\n $ resin device init --application 91 --network ethernet\n $ resin device init /dev/disk2 --application 91 --network wifi --ssid MyNetwork --key secret',
options: [commandOptions.optionalApplication, commandOptions.network, commandOptions.wifiSsid, commandOptions.wifiKey],
permission: 'user',
action: function(params, options, done) {
@ -129,8 +129,10 @@
}
return visuals.patterns.selectDrive(callback);
}, function(device, callback) {
var message;
params.device = device;
return visuals.patterns.confirm(options.yes, "This will completely erase " + params.device + ". Are you sure you want to continue?", callback);
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) {
if (!confirmed) {
return done();

View File

@ -6,10 +6,9 @@
exports.version = {
signature: 'version',
description: 'output the version number',
help: 'Display the Resin CLI, as well as the bundled NodeJS version.',
help: 'Display the Resin CLI version.',
action: function() {
console.log(packageJSON.name + ": " + packageJSON.version);
return console.log("node: " + process.version);
return console.log(packageJSON.version);
}
};

View File

@ -8,12 +8,12 @@
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 <id>.\n\nExamples:\n\n $ resin note "My useful note" --device 317\n $ cat note.txt | resin note --device 317',
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 <name>.\n\nExamples:\n\n $ resin note "My useful note" --device MyDevice\n $ cat note.txt | resin note --device MyDevice',
options: [
{
signature: 'device',
parameter: 'device',
description: 'device id',
description: 'device name',
alias: ['d', 'dev'],
required: 'You have to specify a device'
}

View File

@ -1,10 +1,8 @@
(function() {
var _, async, commandOptions, diskio, fs, mkdirp, npm, os, packageJSON, path, progressStream, resin, updateActions, visuals;
var _, async, commandOptions, elevate, mkdirp, npm, os, packageJSON, path, resin, updateActions, visuals;
_ = require('lodash-contrib');
fs = require('fs');
os = require('os');
async = require('async');
@ -17,10 +15,6 @@
visuals = require('resin-cli-visuals');
progressStream = require('progress-stream');
diskio = require('diskio');
commandOptions = require('./command-options');
npm = require('../npm');
@ -29,6 +23,8 @@
updateActions = require('./update');
elevate = require('../elevate');
exports.download = {
signature: 'os download <id>',
description: 'download device OS',
@ -100,6 +96,8 @@
options: [commandOptions.yes],
permission: 'user',
action: function(params, options, done) {
var bundle;
bundle = require('../devices/raspberry-pi');
return async.waterfall([
function(callback) {
return npm.isUpdated(packageJSON.name, packageJSON.version, callback);
@ -128,37 +126,22 @@
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, error, imageFileSize, imageFileStream, progress;
var bar;
if (!confirmed) {
return done();
}
imageFileSize = fs.statSync(params.image).size;
if (imageFileSize === 0) {
error = new Error("Invalid OS image: " + params.image + ". The image is 0 bytes.");
return callback(error);
}
progress = progressStream({
length: imageFileSize,
time: 500
});
if (!options.quiet) {
bar = new visuals.widgets.Progress('Writing Device OS');
progress.on('progress', function(status) {
return bar.update(status);
});
}
imageFileStream = fs.createReadStream(params.image).pipe(progress);
return diskio.writeStream(params.device, imageFileStream, callback);
bar = new visuals.widgets.Progress('Writing Device OS');
params.progress = _.bind(bar.update, bar);
return bundle.write(params, callback);
}
], function(error) {
var resinWritePath, windosu;
var resinWritePath;
if (error == null) {
return done();
}
if (_.all([os.platform() === 'win32', error.code === 'EPERM' || error.code === 'EACCES', !options.fromScript])) {
windosu = require('windosu');
if (elevate.shouldElevate(error) && !options.fromScript) {
resinWritePath = "\"" + (path.join(__dirname, '..', '..', 'bin', 'resin-write')) + "\"";
return windosu.exec("\"" + process.argv[0] + "\" " + resinWritePath + " \"" + params.image + "\" \"" + params.device + "\"");
return elevate.run("\"" + process.argv[0] + "\" " + resinWritePath + " \"" + params.image + "\" \"" + params.device + "\"");
} else {
return done(error);
}

View File

@ -1,5 +1,11 @@
(function() {
var npm, packageJSON;
var _, child_process, npm, packageJSON, president;
_ = require('lodash');
child_process = require('child_process');
president = require('president');
npm = require('../npm');
@ -10,12 +16,34 @@
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.update(packageJSON.name, function(error, version) {
return npm.isUpdated(packageJSON.name, packageJSON.version, function(error, isUpdated) {
var command, onUpdate;
if (error != null) {
return done(error);
}
console.info("Upgraded " + packageJSON.name + " to v" + version + ".");
return done(null, version);
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);
});
});
}
};

View File

@ -0,0 +1,30 @@
(function() {
var diskio, fs, progressStream;
fs = require('fs');
progressStream = require('progress-stream');
diskio = require('diskio');
exports.name = 'Raspberry Pi';
exports.write = function(options, callback) {
var error, imageFileSize, imageFileStream, progress;
imageFileSize = fs.statSync(options.image).size;
if (imageFileSize === 0) {
error = new Error("Invalid OS image: " + options.image + ". The image is 0 bytes.");
return callback(error);
}
progress = progressStream({
length: imageFileSize,
time: 500
});
if (!options.quiet) {
progress.on('progress', options.progress);
}
imageFileStream = fs.createReadStream(options.image).pipe(progress);
return diskio.writeStream(options.device, imageFileStream, callback);
};
}).call(this);

25
build/elevate.js Normal file
View File

@ -0,0 +1,25 @@
(function() {
var _, isWindows, os, path;
_ = require('lodash');
os = require('os');
path = require('path');
isWindows = function() {
return os.platform() === 'win32';
};
exports.shouldElevate = function(error) {
return _.all([isWindows(), error.code === 'EPERM' || error.code === 'EACCES']);
};
exports.run = function(command) {
if (!isWindows()) {
return;
}
return require('windosu').exec(command);
};
}).call(this);

View File

@ -7,31 +7,6 @@
_ = require('lodash-contrib');
exports.update = 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.update([name], function(error, data) {
return callback(error, data);
});
}, function(data, callback) {
var error, newVersion;
if (_.isEmpty(data)) {
error = new Error('You are already running the latest version');
return callback(error);
}
newVersion = _.last(_.first(_.last(data)).split('@'));
return callback(null, newVersion);
}
], callback);
};
exports.getLatestVersion = function(name, callback) {
return async.waterfall([
function(callback) {

96
capitanodoc.json Normal file
View File

@ -0,0 +1,96 @@
{
"title": "Resin CLI Documentation",
"introduction": "This tool allows you to interact with the resin.io api from the comfort of your command line.\n\nTo get started download the CLI from npm.\n\n\t$ npm install resin-cli -g\n\nThen authenticate yourself:\n\n\t$ resin login\n\nNow you have access to all the commands referenced below.",
"categories": [
{
"title": "Application",
"files": [
"lib/actions/app.coffee"
]
},
{
"title": "Authentication",
"files": [
"lib/actions/auth.coffee"
]
},
{
"title": "Device",
"files": [
"lib/actions/device.coffee"
]
},
{
"title": "Drive",
"files": [
"lib/actions/drive.coffee"
]
},
{
"title": "Environment Variables",
"files": [
"lib/actions/environment-variables.coffee"
]
},
{
"title": "Examples",
"files": [
"lib/actions/examples.coffee"
]
},
{
"title": "Help",
"files": [
"lib/actions/help.coffee"
]
},
{
"title": "Information",
"files": [
"lib/actions/info.coffee"
]
},
{
"title": "Keys",
"files": [
"lib/actions/keys.coffee"
]
},
{
"title": "Logs",
"files": [
"lib/actions/logs.coffee"
]
},
{
"title": "Notes",
"files": [
"lib/actions/notes.coffee"
]
},
{
"title": "OS",
"files": [
"lib/actions/os.coffee"
]
},
{
"title": "Plugin",
"files": [
"lib/actions/plugin.coffee"
]
},
{
"title": "Preferences",
"files": [
"lib/actions/preferences.coffee"
]
},
{
"title": "Update",
"files": [
"lib/actions/update.coffee"
]
}
]
}

View File

@ -1,10 +0,0 @@
# app associate &#60;id&#62;
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.
Examples:
$ resin app associate 91
$ resin app associate 91 --project my/app/directory

View File

@ -1,21 +0,0 @@
# app create &#60;name&#62;
Use this command to create a new resin.io application.
You can specify the application type with the `--type` option.
Otherwise, an interactive dropdown will be shown for you to select from.
You can see a list of supported device types with
$ resin devices supported
Examples:
$ resin app create MyApp
$ resin app create MyApp --type raspberry-pi
## Options
### --type, -t &#60;type&#62;
application type

View File

@ -1,7 +0,0 @@
# app &#60;id&#62;
Use this command to show detailed information for a single application.
Examples:
$ resin app 91

View File

@ -1,13 +0,0 @@
# init
Use this command to initialise a directory as a resin application.
This command performs the following steps:
- Create a resin.io application.
- Initialize the current directory as a git repository.
- Add the corresponding git remote to the application.
Examples:
$ resin init
$ resin init --project my/app/directory

View File

@ -1,10 +0,0 @@
# apps
Use this command to list all your applications.
Notice this command only shows the most important bits of information for each app.
If you want detailed information, use resin app <id> instead.
Examples:
$ resin apps

View File

@ -1,17 +0,0 @@
# app rm &#60;id&#62;
Use this command to remove a resin.io application.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin app rm 91
$ resin app rm 91 --yes
## Options
### --yes, -y
confirm non interactively

View File

@ -1,7 +0,0 @@
# app restart &#60;id&#62;
Use this command to restart all devices that belongs to a certain application.
Examples:
$ resin app restart 91

View File

@ -1,22 +0,0 @@
# login
Use this command to login to your resin.io account.
You need to login before you can use most of the commands this tool provides.
You can pass your credentials as `--username` and `--password` options, or you can omit the
credentials, in which case the tool will present you with an interactive login form.
Examples:
$ resin login --username <username> --password <password>
$ resin login
## Options
### --username, -u &#60;username&#62;
user name
### --password, -p &#60;password&#62;
user password

View File

@ -1,7 +0,0 @@
# logout
Use this command to logout from your resin.io account.o
Examples:
$ resin logout

View File

@ -1,31 +0,0 @@
# signup
Use this command to signup for a resin.io account.
If signup is successful, you'll be logged in to your new user automatically.
Examples:
$ resin signup
Email: me@mycompany.com
Username: johndoe
Password: ***********
$ resin signup --email me@mycompany.com --username johndoe --password ***********
$ resin whoami
johndoe
## Options
### --email, -e &#60;email&#62;
user email
### --username, -u &#60;username&#62;
user name
### --password, -p &#60;user password&#62;
user password

View File

@ -1,7 +0,0 @@
# whoami
Use this command to find out the current logged in username.
Examples:
$ resin whoami

774
doc/cli.markdown Normal file
View File

@ -0,0 +1,774 @@
# Resin CLI Documentation
This tool allows you to interact with the resin.io api from the comfort of your command line.
To get started download the CLI from npm.
$ npm install resin-cli -g
Then authenticate yourself:
$ resin login
Now you have access to all the commands referenced below.
# Table of contents
- Application
- [app create &#60;name&#62;](#/pages/using/cli.md#app-create-60-name-62-)
- [apps](#/pages/using/cli.md#apps)
- [app &#60;name&#62;](#/pages/using/cli.md#app-60-name-62-)
- [app restart &#60;name&#62;](#/pages/using/cli.md#app-restart-60-name-62-)
- [app rm &#60;name&#62;](#/pages/using/cli.md#app-rm-60-name-62-)
- [app associate &#60;name&#62;](#/pages/using/cli.md#app-associate-60-name-62-)
- [init](#/pages/using/cli.md#init)
- Authentication
- [whoami](#/pages/using/cli.md#whoami)
- [login [token]](#/pages/using/cli.md#login-token-)
- [logout](#/pages/using/cli.md#logout)
- [signup](#/pages/using/cli.md#signup)
- Device
- [devices](#/pages/using/cli.md#devices)
- [device &#60;name&#62;](#/pages/using/cli.md#device-60-name-62-)
- [device rm &#60;name&#62;](#/pages/using/cli.md#device-rm-60-name-62-)
- [device identify &#60;uuid&#62;](#/pages/using/cli.md#device-identify-60-uuid-62-)
- [device rename &#60;name&#62; [newName]](#/pages/using/cli.md#device-rename-60-name-62-newname-)
- [devices supported](#/pages/using/cli.md#devices-supported)
- [device init [device]](#/pages/using/cli.md#device-init-device-)
- Drive
- [drives](#/pages/using/cli.md#drives)
- Environment Variables
- [envs](#/pages/using/cli.md#envs)
- [env rm &#60;id&#62;](#/pages/using/cli.md#env-rm-60-id-62-)
- [env add &#60;key&#62; [value]](#/pages/using/cli.md#env-add-60-key-62-value-)
- [env rename &#60;id&#62; &#60;value&#62;](#/pages/using/cli.md#env-rename-60-id-62-60-value-62-)
- Examples
- [examples](#/pages/using/cli.md#examples)
- [example &#60;id&#62;](#/pages/using/cli.md#example-60-id-62-)
- [example clone &#60;id&#62;](#/pages/using/cli.md#example-clone-60-id-62-)
- Help
- [help [command...]](#/pages/using/cli.md#help-command-)
- Information
- [version](#/pages/using/cli.md#version)
- Keys
- [keys](#/pages/using/cli.md#keys)
- [key &#60;id&#62;](#/pages/using/cli.md#key-60-id-62-)
- [key rm &#60;id&#62;](#/pages/using/cli.md#key-rm-60-id-62-)
- [key add &#60;name&#62; [path]](#/pages/using/cli.md#key-add-60-name-62-path-)
- Logs
- [logs &#60;uuid&#62;](#/pages/using/cli.md#logs-60-uuid-62-)
- Notes
- [note &#60;|note&#62;](#/pages/using/cli.md#note-60-note-62-)
- OS
- [os download &#60;id&#62;](#/pages/using/cli.md#os-download-60-id-62-)
- [os install &#60;image&#62; [device]](#/pages/using/cli.md#os-install-60-image-62-device-)
- Plugin
- [plugins](#/pages/using/cli.md#plugins)
- [plugin install &#60;name&#62;](#/pages/using/cli.md#plugin-install-60-name-62-)
- [plugin update &#60;name&#62;](#/pages/using/cli.md#plugin-update-60-name-62-)
- [plugin rm &#60;name&#62;](#/pages/using/cli.md#plugin-rm-60-name-62-)
- Preferences
- [preferences](#/pages/using/cli.md#preferences)
- Update
- [update](#/pages/using/cli.md#update)
# Application
## app create &#60;name&#62;
Use this command to create a new resin.io application.
You can specify the application type with the `--type` option.
Otherwise, an interactive dropdown will be shown for you to select from.
You can see a list of supported device types with
$ resin devices supported
Examples:
$ resin app create MyApp
$ resin app create MyApp --type raspberry-pi
### Options
#### --type, -t &#60;type&#62;
application type
## apps
Use this command to list all your applications.
Notice this command only shows the most important bits of information for each app.
If you want detailed information, use resin app <name> instead.
Examples:
$ resin apps
## app &#60;name&#62;
Use this command to show detailed information for a single application.
Examples:
$ resin app MyApp
## app restart &#60;name&#62;
Use this command to restart all devices that belongs to a certain application.
Examples:
$ resin app restart MyApp
## app rm &#60;name&#62;
Use this command to remove a resin.io application.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin app rm MyApp
$ resin app rm MyApp --yes
### Options
#### --yes, -y
confirm non interactively
## app associate &#60;name&#62;
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.
Examples:
$ resin app associate MyApp
$ resin app associate MyApp --project my/app/directory
## init
Use this command to initialise a directory as a resin application.
This command performs the following steps:
- Create a resin.io application.
- Initialize the current directory as a git repository.
- Add the corresponding git remote to the application.
Examples:
$ resin init
$ resin init --project my/app/directory
# Authentication
## whoami
Use this command to find out the current logged in username.
Examples:
$ resin whoami
## login [token]
Use this command to login to your resin.io account.
To login, you need your token, which is accesible from the preferences page:
https://staging.resin.io/preferences
Examples:
$ resin login
$ resin login "eyJ0eXAiOiJKV1Qi..."
## logout
Use this command to logout from your resin.io account.o
Examples:
$ resin logout
## signup
Use this command to signup for a resin.io account.
If signup is successful, you'll be logged in to your new user automatically.
Examples:
$ resin signup
Email: me@mycompany.com
Username: johndoe
Password: ***********
$ resin signup --email me@mycompany.com --username johndoe --password ***********
$ resin whoami
johndoe
### Options
#### --email, -e &#60;email&#62;
user email
#### --username, -u &#60;username&#62;
user name
#### --password, -p &#60;user password&#62;
user password
# Device
## devices
Use this command to list all devices that belong to a certain application.
Examples:
$ resin devices --application MyApp
### Options
#### --application, --a,app, --a,app &#60;application&#62;
application name
## device &#60;name&#62;
Use this command to show information about a single device.
Examples:
$ resin device MyDevice
## device rm &#60;name&#62;
Use this command to remove a device from resin.io.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin device rm MyDevice
$ resin device rm MyDevice --yes
### Options
#### --yes, -y
confirm non interactively
## device identify &#60;uuid&#62;
Use this command to identify a device.
In the Raspberry Pi, the ACT led is blinked several times.
Examples:
$ resin device identify 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828
## device rename &#60;name&#62; [newName]
Use this command to rename a device.
If you omit the name, you'll get asked for it interactively.
Examples:
$ resin device rename MyDevice MyPi
$ resin device rename MyDevice
## devices supported
Use this command to get the list of all supported devices
Examples:
$ resin devices supported
## device init [device]
Use this command to download the OS image of a certain application and write it to an SD Card.
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.
You may have to unmount the device before attempting this operation.
You need to configure the network type and other settings:
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.
You can omit network related options to be asked about them interactively.
Examples:
$ resin device init
$ resin device init --application 91
$ resin device init --application 91 --network ethernet
$ resin device init /dev/disk2 --application 91 --network wifi --ssid MyNetwork --key secret
### Options
#### --application, --a,app, --a,app &#60;application&#62;
application name
#### --network, -n &#60;network&#62;
network type
#### --ssid, -s &#60;ssid&#62;
wifi ssid, if network is wifi
#### --key, -k &#60;key&#62;
wifi key, if network is wifi
# Drive
## drives
Use this command to list all drives that are connected to your machine.
Examples:
$ resin drives
# Environment Variables
## envs
Use this command to list all environment variables for a particular application.
Notice we will support per-device environment variables soon.
This command lists all custom environment variables set on the devices running
the application. 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
### Options
#### --application, --a,app, --a,app &#60;application&#62;
application name
#### --verbose, -v
show private environment variables
## env rm &#60;id&#62;
Use this command to remove an environment variable from an application.
Don't remove resin specific variables, as things might not work as expected.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin env rm 215
$ resin env rm 215 --yes
### Options
#### --yes, -y
confirm non interactively
## env add &#60;key&#62; [value]
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.
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
### Options
#### --application, --a,app, --a,app &#60;application&#62;
application name
## env rename &#60;id&#62; &#60;value&#62;
Use this command to rename an enviroment variable from an application.
Examples:
$ resin env rename 376 emacs
# Examples
## examples
Use this command to list available example applications from resin.io
Example:
$ resin examples
## example &#60;id&#62;
Use this command to show information of a single example application
Example:
$ resin example 3
## example clone &#60;id&#62;
Use this command to clone an example application to the current directory
This command outputs information about the cloning process.
Use `--quiet` to remove that output.
Example:
$ resin example clone 3
# Help
## help [command...]
Get detailed help for an specific command.
Examples:
$ resin help apps
$ resin help os download
# Information
## version
Display the Resin CLI version.
# Keys
## keys
Use this command to list all your SSH keys.
Examples:
$ resin keys
## key &#60;id&#62;
Use this command to show information about a single SSH key.
Examples:
$ resin key 17
## key rm &#60;id&#62;
Use this command to remove a SSH key from resin.io.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin key rm 17
$ resin key rm 17 --yes
### Options
#### --yes, -y
confirm non interactively
## key add &#60;name&#62; [path]
Use this command to associate a new SSH key with your account.
If `path` is omitted, the command will attempt
to read the SSH key from stdin.
Examples:
$ resin key add Main ~/.ssh/id_rsa.pub
$ cat ~/.ssh/id_rsa.pub | resin key add Main
# Logs
## logs &#60;uuid&#62;
Use this command to show logs for a specific device.
By default, the command prints all log messages and exit.
To limit the output to the n last lines, use the `--num` option along with a number.
This is similar to doing `resin logs <uuid> | tail -n X`.
To continuously stream output, and see new logs in real time, use the `--tail` option.
Note that for now you need to provide the whole UUID for this command to work correctly,
and the tool won't notice if you're using an invalid UUID.
This is due to some technical limitations that we plan to address soon.
Examples:
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828 --num 20
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828 --tail
### Options
#### --num, -n &#60;num&#62;
number of lines to display
#### --tail, -t
continuously stream output
# Notes
## note &#60;|note&#62;
Use this command to set or update a device note.
If note command isn't passed, the tool attempts to read from `stdin`.
To view the notes, use $ resin device <name>.
Examples:
$ resin note "My useful note" --device MyDevice
$ cat note.txt | resin note --device MyDevice
### Options
#### --device, --d,dev, --d,dev &#60;device&#62;
device name
# OS
## os download &#60;id&#62;
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 91 --output ~/MyResinOS.zip
$ resin os download 91 --network ethernet --output ~/MyResinOS.zip
$ resin os download 91 --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip
$ resin os download 91 --network ethernet --output ~/MyResinOS.zip
### Options
#### --network, -n &#60;network&#62;
network type
#### --ssid, -s &#60;ssid&#62;
wifi ssid, if network is wifi
#### --key, -k &#60;key&#62;
wifi key, if network is wifi
#### --output, -o &#60;output&#62;
output file
## os install &#60;image&#62; [device]
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.
You may have to unmount the device before attempting this operation.
See the `drives` command to get a list of all connected devices to your machine and their respective ids.
In Mac OS X:
$ sudo diskutil unmountDisk /dev/xxx
In GNU/Linux:
$ sudo umount /dev/xxx
Examples:
$ resin os install rpi.iso /dev/disk2
### Options
#### --yes, -y
confirm non interactively
# Plugin
## plugins
Use this command to list all the installed resin plugins.
Examples:
$ resin plugins
## plugin install &#60;name&#62;
Use this command to install a resin plugin
Use `--quiet` to prevent information logging.
Examples:
$ resin plugin install hello
## plugin update &#60;name&#62;
Use this command to update a resin plugin
Use `--quiet` to prevent information logging.
Examples:
$ resin plugin update hello
## plugin rm &#60;name&#62;
Use this command to remove a resin.io plugin.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin plugin rm hello
$ resin plugin rm hello --yes
### Options
#### --yes, -y
confirm non interactively
# Preferences
## preferences
Use this command to open the preferences form.
In the future, we will allow changing all preferences directly from the terminal.
For now, we open your default web browser and point it to the web based preferences form.
Examples:
$ resin preferences
# Update
## update
Use this command to update the Resin CLI
This command outputs information about the update process.
Use `--quiet` to remove that output.
The Resin CLI checks for updates once per day.
Major updates require a manual update with this update command,
while minor updates are applied automatically.
Examples:
$ resin update

View File

@ -1,9 +0,0 @@
# device identify &#60;uuid&#62;
Use this command to identify a device.
In the Raspberry Pi, the ACT led is blinked several times.
Examples:
$ resin device identify 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828

View File

@ -1,7 +0,0 @@
# device &#60;id&#62;
Use this command to show information about a single device.
Examples:
$ resin device 317

View File

@ -1,49 +0,0 @@
# device init [device]
Use this command to download the OS image of a certain application and write it to an SD Card.
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.
You may have to unmount the device before attempting this operation.
You need to configure the network type and other settings:
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.
You can omit network related options to be asked about them interactively.
Examples:
$ resin device init --application 91
$ resin device init --application 91 --network ethernet
$ resin device init /dev/disk2 --application 91 --network wifi --ssid MyNetwork --key secret
## Options
### --application, --a,app, --a,app &#60;application&#62;
application id
### --network, -n &#60;network&#62;
network type
### --ssid, -s &#60;ssid&#62;
wifi ssid, if network is wifi
### --key, -k &#60;key&#62;
wifi key, if network is wifi

View File

@ -1,13 +0,0 @@
# devices
Use this command to list all devices that belong to a certain application.
Examples:
$ resin devices --application 91
## Options
### --application, --a,app, --a,app &#60;application&#62;
application id

View File

@ -1,17 +0,0 @@
# device rm &#60;id&#62;
Use this command to remove a device from resin.io.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin device rm 317
$ resin device rm 317 --yes
## Options
### --yes, -y
confirm non interactively

View File

@ -1,10 +0,0 @@
# device rename &#60;id&#62; [name]
Use this command to rename a device.
If you omit the name, you'll get asked for it interactively.
Examples:
$ resin device rename 317 MyPi
$ resin device rename 317

View File

@ -1,7 +0,0 @@
# devices supported
Use this command to get the list of all supported devices
Examples:
$ resin devices supported

View File

@ -1,7 +0,0 @@
# drives
Use this command to list all drives that are connected to your machine.
Examples:
$ resin drives

View File

@ -1,22 +0,0 @@
# env add &#60;key&#62; [value]
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.
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
## Options
### --application, --a,app, --a,app &#60;application&#62;
application id

View File

@ -1,23 +0,0 @@
# envs
Use this command to list all environment variables for a particular application.
Notice we will support per-device environment variables soon.
This command lists all custom environment variables set on the devices running
the application. 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
## Options
### --application, --a,app, --a,app &#60;application&#62;
application id
### --verbose, -v
show private environment variables

View File

@ -1,19 +0,0 @@
# env rm &#60;id&#62;
Use this command to remove an environment variable from an application.
Don't remove resin specific variables, as things might not work as expected.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin env rm 215
$ resin env rm 215 --yes
## Options
### --yes, -y
confirm non interactively

View File

@ -1,7 +0,0 @@
# env rename &#60;id&#62; &#60;value&#62;
Use this command to rename an enviroment variable from an application.
Examples:
$ resin env rename 376 emacs

View File

@ -1,10 +0,0 @@
# example clone &#60;id&#62;
Use this command to clone an example application to the current directory
This command outputs information about the cloning process.
Use `--quiet` to remove that output.
Example:
$ resin example clone 3

View File

@ -1,7 +0,0 @@
# example &#60;id&#62;
Use this command to show information of a single example application
Example:
$ resin example 3

View File

@ -1,7 +0,0 @@
# examples
Use this command to list available example applications from resin.io
Example:
$ resin examples

View File

@ -1,8 +0,0 @@
# help [command...]
Get detailed help for an specific command.
Examples:
$ resin help apps
$ resin help os download

View File

@ -1,3 +0,0 @@
# version
Display the Resin CLI, as well as the bundled NodeJS version.

View File

@ -1,11 +0,0 @@
# key add &#60;name&#62; [path]
Use this command to associate a new SSH key with your account.
If `path` is omitted, the command will attempt
to read the SSH key from stdin.
Examples:
$ resin key add Main ~/.ssh/id_rsa.pub
$ cat ~/.ssh/id_rsa.pub | resin key add Main

View File

@ -1,7 +0,0 @@
# key &#60;id&#62;
Use this command to show information about a single SSH key.
Examples:
$ resin key 17

View File

@ -1,7 +0,0 @@
# keys
Use this command to list all your SSH keys.
Examples:
$ resin keys

View File

@ -1,17 +0,0 @@
# key rm &#60;id&#62;
Use this command to remove a SSH key from resin.io.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin key rm 17
$ resin key rm 17 --yes
## Options
### --yes, -y
confirm non interactively

View File

@ -1,18 +0,0 @@
# note &#60;|note&#62;
Use this command to set or update a device note.
If note command isn't passed, the tool attempts to read from `stdin`.
To view the notes, use $ resin device <id>.
Examples:
$ resin note "My useful note" --device 317
$ cat note.txt | resin note --device 317
## Options
### --device, --d,dev, --d,dev &#60;device&#62;
device id

View File

@ -1,39 +0,0 @@
# os download &#60;id&#62;
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 91 --output ~/MyResinOS.zip
$ resin os download 91 --network ethernet --output ~/MyResinOS.zip
$ resin os download 91 --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip
$ resin os download 91 --network ethernet --output ~/MyResinOS.zip
## Options
### --network, -n &#60;network&#62;
network type
### --ssid, -s &#60;ssid&#62;
wifi ssid, if network is wifi
### --key, -k &#60;key&#62;
wifi key, if network is wifi
### --output, -o &#60;output&#62;
output file

View File

@ -1,34 +0,0 @@
# os install &#60;image&#62; [device]
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.
You may have to unmount the device before attempting this operation.
See the `drives` command to get a list of all connected devices to your machine and their respective ids.
In Mac OS X:
$ sudo diskutil unmountDisk /dev/xxx
In GNU/Linux:
$ sudo umount /dev/xxx
Examples:
$ resin os install rpi.iso /dev/disk2
## Options
### --yes, -y
confirm non interactively

View File

@ -1,9 +0,0 @@
# plugin install &#60;name&#62;
Use this command to install a resin plugin
Use `--quiet` to prevent information logging.
Examples:
$ resin plugin install hello

View File

@ -1,7 +0,0 @@
# plugins
Use this command to list all the installed resin plugins.
Examples:
$ resin plugins

View File

@ -1,17 +0,0 @@
# plugin rm &#60;name&#62;
Use this command to remove a resin.io plugin.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin plugin rm hello
$ resin plugin rm hello --yes
## Options
### --yes, -y
confirm non interactively

View File

@ -1,9 +0,0 @@
# plugin update &#60;name&#62;
Use this command to update a resin plugin
Use `--quiet` to prevent information logging.
Examples:
$ resin plugin update hello

View File

@ -1,10 +0,0 @@
# preferences
Use this command to open the preferences form.
In the future, we will allow changing all preferences directly from the terminal.
For now, we open your default web browser and point it to the web based preferences form.
Examples:
$ resin preferences

View File

@ -1,15 +0,0 @@
# update
Use this command to update the Resin CLI
This command outputs information about the update process.
Use `--quiet` to remove that output.
The Resin CLI checks for updates once per day.
Major updates require a manual update with this update command,
while minor updates are applied automatically.
Examples:
$ resin update

View File

@ -1,20 +0,0 @@
mkdirp = require('mkdirp')
fs = require('fs')
path = require('path')
capitano = require('capitano')
markdown = require('./markdown')
capitano.command
signature: 'markdown <file> <output>'
description: 'file to markdown'
action: (params, options, done) ->
mkdirp.sync(params.output)
action = require(params.file)
for actionName, actionCommand of action
output = path.join(params.output, "#{actionName}.markdown")
fs.writeFileSync(output, markdown.command(actionCommand))
return done()
capitano.run(process.argv)

View File

@ -1,24 +0,0 @@
_ = require('lodash')
ent = require('ent')
utils = require('./utils')
exports.option = (option) ->
result = utils.parseSignature(option)
exports.command = (command) ->
result = """
# #{ent.encode(command.signature)}
#{command.help}\n
"""
if not _.isEmpty(command.options)
result += '\n## Options'
for option in command.options
result += """
\n\n### #{utils.parseSignature(option)}
#{option.description}
"""
return result

View File

@ -0,0 +1,45 @@
_ = require('lodash')
capitanodoc = require('../../capitanodoc.json')
markdown = require('./markdown')
result = {}
result.title = capitanodoc.title
result.introduction = capitanodoc.introduction
result.categories = []
for commandCategory in capitanodoc.categories
category = {}
category.title = commandCategory.title
category.commands = []
for file in commandCategory.files
actions = require(file)
for actionName, actionCommand of actions
category.commands.push(_.omit(actionCommand, 'action'))
result.categories.push(category)
result.toc = _.cloneDeep(result.categories)
result.toc = _.map result.toc, (category) ->
category.commands = _.map category.commands, (command) ->
return {
signature: command.signature
# TODO: Make anchor prefix a configurable setting
# in capitanodoc.json
anchor: '#/pages/using/cli.md#' + command.signature
.replace(/\s/g,'-')
.replace(/</g, '60-')
.replace(/>/g, '-62-')
.replace(/\[/g, '')
.replace(/\]/g, '-')
.replace(/--/g, '-')
.replace(/\.\.\./g, '')
.replace(/\|/g, '')
.toLowerCase()
}
return category
console.log(markdown.display(result))

View File

@ -0,0 +1,66 @@
_ = require('lodash')
ent = require('ent')
utils = require('./utils')
exports.command = (command) ->
result = """
## #{ent.encode(command.signature)}
#{command.help}\n
"""
if not _.isEmpty(command.options)
result += '\n### Options'
for option in command.options
result += """
\n\n#### #{utils.parseSignature(option)}
#{option.description}
"""
result += '\n'
return result
exports.category = (category) ->
result = """
# #{category.title}\n
"""
for command in category.commands
result += '\n' + exports.command(command)
return result
exports.toc = (toc) ->
result = '''
# Table of contents\n
'''
for category in toc
result += """
\n- #{category.title}\n\n
"""
for command in category.commands
result += """
\t- [#{ent.encode(command.signature)}](#{command.anchor})\n
"""
return result
exports.display = (doc) ->
result = """
# #{doc.title}
#{doc.introduction}
#{exports.toc(doc.toc)}
"""
for category in doc.categories
result += '\n' + exports.category(category)
return result

View File

@ -55,7 +55,7 @@ exports.list =
Use this command to list all your applications.
Notice this command only shows the most important bits of information for each app.
If you want detailed information, use resin app <id> instead.
If you want detailed information, use resin app <name> instead.
Examples:
@ -75,18 +75,18 @@ exports.list =
return done()
exports.info =
signature: 'app <id>'
signature: 'app <name>'
description: 'list a single application'
help: '''
Use this command to show detailed information for a single application.
Examples:
$ resin app 91
$ resin app MyApp
'''
permission: 'user'
action: (params, options, done) ->
resin.models.application.get params.id, (error, application) ->
resin.models.application.get params.name, (error, application) ->
return done(error) if error?
console.log visuals.widgets.table.vertical application, [
'id'
@ -98,21 +98,21 @@ exports.info =
return done()
exports.restart =
signature: 'app restart <id>'
signature: 'app restart <name>'
description: 'restart an application'
help: '''
Use this command to restart all devices that belongs to a certain application.
Examples:
$ resin app restart 91
$ resin app restart MyApp
'''
permission: 'user'
action: (params, options, done) ->
resin.models.application.restart(params.id, done)
resin.models.application.restart(params.name, done)
exports.remove =
signature: 'app rm <id>'
signature: 'app rm <name>'
description: 'remove an application'
help: '''
Use this command to remove a resin.io application.
@ -122,18 +122,18 @@ exports.remove =
Examples:
$ resin app rm 91
$ resin app rm 91 --yes
$ resin app rm MyApp
$ resin app rm MyApp --yes
'''
options: [ commandOptions.yes ]
permission: 'user'
action: (params, options, done) ->
visuals.patterns.remove 'application', options.yes, (callback) ->
resin.models.application.remove(params.id, callback)
resin.models.application.remove(params.name, callback)
, done
exports.associate =
signature: 'app associate <id>'
signature: 'app associate <name>'
description: 'associate a resin project'
help: '''
Use this command to associate a project directory with a resin application.
@ -142,8 +142,8 @@ exports.associate =
Examples:
$ resin app associate 91
$ resin app associate 91 --project my/app/directory
$ resin app associate MyApp
$ resin app associate MyApp --project my/app/directory
'''
permission: 'user'
action: (params, options, done) ->
@ -155,7 +155,7 @@ exports.associate =
vcs.initialize(currentDirectory, callback)
(callback) ->
resin.models.application.get(params.id, callback)
resin.models.application.get(params.name, callback)
(application, callback) ->
vcs.addRemote(currentDirectory, application.git_repository, callback)
@ -193,9 +193,14 @@ exports.init =
visuals.widgets.ask('What is the name of your application?', currentDirectoryBasename, callback)
(applicationName, callback) ->
exports.create.action(name: applicationName, options, callback)
(applicationId, callback) ->
exports.associate.action(id: applicationId, options, callback)
# TODO: Make resin.models.application.create return
# the whole application instead of just the id
exports.create.action name: applicationName, options, (error) ->
return callback(error) if error?
return callback(null, applicationName)
(applicationName, callback) ->
exports.associate.action(name: applicationName, options, callback)
], done)

View File

@ -1,62 +1,73 @@
open = require('open')
_ = require('lodash-contrib')
url = require('url')
async = require('async')
resin = require('resin-sdk')
settings = require('resin-settings-client')
visuals = require('resin-cli-visuals')
exports.login =
signature: 'login'
description: 'login to resin.io'
exports.whoami =
signature: 'whoami'
description: 'whoami'
help: '''
Use this command to login to your resin.io account.
You need to login before you can use most of the commands this tool provides.
You can pass your credentials as `--username` and `--password` options, or you can omit the
credentials, in which case the tool will present you with an interactive login form.
Use this command to get the logged in user name.
Examples:
$ resin login --username <username> --password <password>
$ resin login
$ resin whoami
'''
options: [
{
signature: 'username'
parameter: 'username'
description: 'user name'
alias: 'u'
}
{
signature: 'password'
parameter: 'password'
description: 'user password'
alias: 'p'
}
]
permission: 'user'
action: (params, options, done) ->
resin.auth.whoami (error, username) ->
return done(error) if error?
console.log(username)
return done()
TOKEN_URL = url.resolve(settings.get('remoteUrl'), '/preferences')
exports.login =
signature: 'login [token]'
description: 'login to resin.io'
help: """
Use this command to login to your resin.io account.
To login, you need your token, which is accesible from the preferences page:
#{TOKEN_URL}
Examples:
$ resin login
$ resin login "eyJ0eXAiOiJKV1Qi..."
"""
action: (params, options, done) ->
hasOptionCredentials = not _.isEmpty(options)
console.info """
To login to the Resin CLI, you need your unique token, which is accesible from
the preferences page at #{TOKEN_URL}
if hasOptionCredentials
Attempting to open a browser at that location...
"""
if not options.username
return done(new Error('Missing username'))
if not options.password
return done(new Error('Missing password'))
async.waterfall [
async.waterfall([
(callback) ->
if hasOptionCredentials
return callback(null, options)
else
return visuals.widgets.login(callback)
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()
(credentials, callback) ->
resin.auth.login(credentials, callback)
(callback) ->
return callback(null, params.token) if params.token?
visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback)
], done
(token, callback) ->
resin.auth.loginWithToken(token, done)
], done)
exports.logout =
signature: 'logout'

View File

@ -9,7 +9,7 @@ exports.yes =
exports.optionalApplication =
signature: 'application'
parameter: 'application'
description: 'application id'
description: 'application name'
alias: [ 'a', 'app' ]
exports.application = _.defaults

View File

@ -15,7 +15,7 @@ exports.list =
Examples:
$ resin devices --application 91
$ resin devices --application MyApp
'''
options: [ commandOptions.application ]
permission: 'user'
@ -35,18 +35,18 @@ exports.list =
return done()
exports.info =
signature: 'device <id>'
signature: 'device <name>'
description: 'list a single device'
help: '''
Use this command to show information about a single device.
Examples:
$ resin device 317
$ resin device MyDevice
'''
permission: 'user'
action: (params, options, done) ->
resin.models.device.get params.id, (error, device) ->
resin.models.device.get params.name, (error, device) ->
return done(error) if error?
console.log visuals.widgets.table.vertical device, [
'id'
@ -67,7 +67,7 @@ exports.info =
return done()
exports.remove =
signature: 'device rm <id>'
signature: 'device rm <name>'
description: 'remove a device'
help: '''
Use this command to remove a device from resin.io.
@ -77,14 +77,14 @@ exports.remove =
Examples:
$ resin device rm 317
$ resin device rm 317 --yes
$ resin device rm MyDevice
$ resin device rm MyDevice --yes
'''
options: [ commandOptions.yes ]
permission: 'user'
action: (params, options, done) ->
visuals.patterns.remove 'device', options.yes, (callback) ->
resin.models.device.remove(params.id, callback)
resin.models.device.remove(params.name, callback)
, done
exports.identify =
@ -104,7 +104,7 @@ exports.identify =
resin.models.device.identify(params.uuid, done)
exports.rename =
signature: 'device rename <id> [name]'
signature: 'device rename <name> [newName]'
description: 'rename a resin device'
help: '''
Use this command to rename a device.
@ -113,20 +113,20 @@ exports.rename =
Examples:
$ resin device rename 317 MyPi
$ resin device rename 317
$ resin device rename MyDevice MyPi
$ resin device rename MyDevice
'''
permission: 'user'
action: (params, options, done) ->
async.waterfall [
(callback) ->
if not _.isEmpty(params.name)
return callback(null, params.name)
if not _.isEmpty(params.newName)
return callback(null, params.newName)
visuals.widgets.ask('How do you want to name this device?', null, callback)
(name, callback) ->
resin.models.device.rename(params.id, name, callback)
(newName, callback) ->
resin.models.device.rename(params.name, newName, callback)
], done
@ -177,6 +177,7 @@ exports.init =
Examples:
$ resin device init
$ resin device init --application 91
$ resin device init --application 91 --network ethernet
$ resin device init /dev/disk2 --application 91 --network wifi --ssid MyNetwork --key secret
@ -205,7 +206,8 @@ exports.init =
(device, callback) ->
params.device = device
visuals.patterns.confirm(options.yes, "This will completely erase #{params.device}. Are you sure you want to continue?", callback)
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

View File

@ -4,8 +4,7 @@ exports.version =
signature: 'version'
description: 'output the version number'
help: '''
Display the Resin CLI, as well as the bundled NodeJS version.
Display the Resin CLI version.
'''
action: ->
console.log("#{packageJSON.name}: #{packageJSON.version}")
console.log("node: #{process.version}")
console.log(packageJSON.version)

View File

@ -9,17 +9,17 @@ exports.set =
If note command isn't passed, the tool attempts to read from `stdin`.
To view the notes, use $ resin device <id>.
To view the notes, use $ resin device <name>.
Examples:
$ resin note "My useful note" --device 317
$ cat note.txt | resin note --device 317
$ resin note "My useful note" --device MyDevice
$ cat note.txt | resin note --device MyDevice
'''
options: [
signature: 'device'
parameter: 'device'
description: 'device id'
description: 'device name'
alias: [ 'd', 'dev' ]
required: 'You have to specify a device'
]

View File

@ -1,17 +1,15 @@
_ = require('lodash-contrib')
fs = require('fs')
os = require('os')
async = require('async')
path = require('path')
mkdirp = require('mkdirp')
resin = require('resin-sdk')
visuals = require('resin-cli-visuals')
progressStream = require('progress-stream')
diskio = require('diskio')
commandOptions = require('./command-options')
npm = require('../npm')
packageJSON = require('../../package.json')
updateActions = require('./update')
elevate = require('../elevate')
exports.download =
signature: 'os download <id>'
@ -126,6 +124,9 @@ exports.install =
options: [ commandOptions.yes ]
permission: 'user'
action: (params, options, done) ->
bundle = require('../devices/raspberry-pi')
async.waterfall [
(callback) ->
@ -165,41 +166,17 @@ exports.install =
(confirmed, callback) ->
return done() if not confirmed
imageFileSize = fs.statSync(params.image).size
if imageFileSize is 0
error = new Error("Invalid OS image: #{params.image}. The image is 0 bytes.")
return callback(error)
progress = progressStream
length: imageFileSize
time: 500
if not options.quiet
bar = new visuals.widgets.Progress('Writing Device OS')
progress.on 'progress', (status) ->
bar.update(status)
imageFileStream = fs.createReadStream(params.image).pipe(progress)
diskio.writeStream(params.device, imageFileStream, callback)
bar = new visuals.widgets.Progress('Writing Device OS')
params.progress = _.bind(bar.update, bar)
bundle.write(params, callback)
], (error) ->
return done() if not error?
if _.all [
os.platform() is 'win32'
error.code is 'EPERM' or error.code is 'EACCES'
if elevate.shouldElevate(error) and not options.fromScript
# Prevent re-running resin-write infinitely
# If we have an EPERM or EACCES even after running
# windosu, we throw it as there is not much we can do
not options.fromScript
]
windosu = require('windosu')
# Need to escape every path to avoid errors
resinWritePath = "\"#{path.join(__dirname, '..', '..', 'bin', 'resin-write')}\""
windosu.exec("\"#{process.argv[0]}\" #{resinWritePath} \"#{params.image}\" \"#{params.device}\"")
elevate.run("\"#{process.argv[0]}\" #{resinWritePath} \"#{params.image}\" \"#{params.device}\"")
else
return done(error)

View File

@ -1,3 +1,6 @@
_ = require('lodash')
child_process = require('child_process')
president = require('president')
npm = require('../npm')
packageJSON = require('../../package.json')
@ -20,7 +23,36 @@ exports.update =
$ resin update
'''
action: (params, options, done) ->
npm.update packageJSON.name, (error, version) ->
npm.isUpdated packageJSON.name, packageJSON.version, (error, isUpdated) ->
return done(error) if error?
console.info("Upgraded #{packageJSON.name} to v#{version}.")
return done(null, version)
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 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)

View File

@ -0,0 +1,22 @@
fs = require('fs')
progressStream = require('progress-stream')
diskio = require('diskio')
exports.name = 'Raspberry Pi'
exports.write = (options, callback) ->
imageFileSize = fs.statSync(options.image).size
if imageFileSize is 0
error = new Error("Invalid OS image: #{options.image}. The image is 0 bytes.")
return callback(error)
progress = progressStream
length: imageFileSize
time: 500
if not options.quiet
progress.on('progress', options.progress)
imageFileStream = fs.createReadStream(options.image).pipe(progress)
diskio.writeStream(options.device, imageFileStream, callback)

16
lib/elevate.coffee Normal file
View File

@ -0,0 +1,16 @@
_ = require('lodash')
os = require('os')
path = require('path')
isWindows = ->
return os.platform() is 'win32'
exports.shouldElevate = (error) ->
return _.all [
isWindows()
error.code is 'EPERM' or error.code is 'EACCES'
]
exports.run = (command) ->
return if not isWindows()
require('windosu').exec(command)

View File

@ -2,34 +2,6 @@ npm = require('npm')
async = require('async')
_ = require('lodash-contrib')
exports.update = (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.update [ name ], (error, data) ->
return callback(error, data)
(data, callback) ->
if _.isEmpty(data)
error = new Error('You are already running the latest version')
return callback(error)
newVersion = _.last(_.first(_.last(data)).split('@'))
return callback(null, newVersion)
], callback)
exports.getLatestVersion = (name, callback) ->
async.waterfall([

View File

@ -1,6 +1,6 @@
{
"name": "resin-cli",
"version": "0.5.0",
"version": "0.8.1",
"description": "Git Push to your devices",
"main": "./lib/actions/index.coffee",
"homepage": "https://github.com/resin-io/resin-cli",
@ -20,7 +20,7 @@
"scripts": {
"prepublish": "gulp build",
"test": "gulp test",
"doc": "./scripts/extract-documentation.sh doc lib/actions"
"doc": "mkdir -p doc/ && coffee extras/capitanodoc/index.coffee > doc/cli.markdown"
},
"keywords": [
"resin",
@ -57,14 +57,15 @@
"lodash": "~2.4.1",
"lodash-contrib": "~241.4.14",
"mkdirp": "~0.5.0",
"nplugm": "^2.1.0",
"nplugm": "^2.2.0",
"npm": "^2.6.1",
"open": "0.0.5",
"president": "^1.0.0",
"progress-stream": "^0.5.0",
"resin-cli-visuals": "^0.1.0",
"resin-sdk": "^1.0.0",
"resin-sdk": "^1.2.0",
"resin-settings-client": "^1.0.0",
"resin-vcs": "^1.0.0",
"resin-vcs": "^1.1.0",
"underscore.string": "~2.4.0",
"update-notifier": "^0.3.1"
}

View File

@ -1,18 +0,0 @@
#!/bin/sh
OUTPUT=$1
INPUT=$2
for file in $INPUT/*.coffee; do
# Omit this unecessary files
if [ `basename "$file"` == 'index.coffee' ] || [ `basename "$file"` == 'command-options.coffee' ]; then
continue
fi
filename=`basename "${file%.*}"`
output=$OUTPUT/$filename
mkdir -p $output
./node_modules/coffee-script/bin/coffee extras/capitano-doc/index.coffee markdown "$file" "$output"
echo "[CapitanoDoc] Processed $file to $output"
done