Compare commits

...

150 Commits

Author SHA1 Message Date
5619bdbb67 Resin CLI v0.11.1 2015-06-15 10:09:10 -04:00
381e63bfc9 Merge pull request #70 from resin-io/refactor/new-visuals
Upgrade Resin CLI Visuals and use it's new capabilities
2015-06-12 09:47:30 -04:00
e779347ff2 Merge pull request #69 from resin-io/feature/no-chop-key
Don't chop SSH key
2015-06-11 12:48:16 -04:00
8fa906dd48 Upgrade Resin CLI Visuals and use it's new capabilities 2015-06-11 12:46:56 -04:00
7e5ecd634d HOTFIX: isLoggedIn now returns a possible error 2015-06-11 12:40:49 -04:00
29cf4c1e89 Don't chop SSH key 2015-06-11 08:08:45 -04:00
73736abdea Merge pull request #68 from resin-io/feature/config
Implement config command
2015-06-11 07:57:31 -04:00
9ab411bade Resin CLI v0.11.0 2015-06-10 12:52:28 -04:00
ef33156de7 Implement config command 2015-06-10 12:34:42 -04:00
6d8fd6e547 Merge pull request #66 from resin-io/feature/device-init-has-app
Check that the passed application exists before asking to choose device
2015-06-09 08:28:10 -04:00
bab90a8bf2 Merge pull request #65 from resin-io/fix/app-rm-help
Fix app commands order of definition. Closes #62.
2015-06-08 12:44:57 -04:00
43f0288c6c Check that the passed application exists before asking to choose device 2015-06-08 12:31:17 -04:00
47e6371e2e Merge pull request #64 from resin-io/feature/config-inject
Implement config injection
2015-06-05 12:06:54 -04:00
5e400ed335 Fix app commands order of definition. Closes #62.
This caused `resin help app rm` erroneusly show the help page for `resin app`.
2015-06-04 11:54:15 -04:00
56a78b57af Merge branch 'master' of https://github.com/resin-io/resin-cli 2015-06-04 10:38:53 -04:00
2bfeb7f42c Associate a device before first boot 2015-06-04 10:10:15 -04:00
37e0f12f89 Merge pull request #57 from resin-io/feature/associate-confirmation
Ask for confirmation on app associate command
2015-06-04 08:22:01 -04:00
fdd0e4a966 Implement config injection 2015-06-04 08:06:37 -04:00
38df7e0038 Use min mocha reporter 2015-06-04 08:06:08 -04:00
e9efb78280 Merge pull request #56 from resin-io/feature/login-feedback
Display feedback message after login
2015-06-03 08:46:18 -04:00
0424d7b640 Merge pull request #60 from resin-io/fix/login-browser-session
Open dashboardUrl instead of remoteUrl in auth login
2015-06-03 08:45:00 -04:00
2b80c7c91f Merge pull request #59 from resin-io/feature/app-create-feedback
Print feedback message after app create
2015-06-02 17:08:44 -04:00
142e2c0a65 Merge pull request #58 from resin-io/feature/tty-feedback
Quiet console.info if stdout is being redirected
2015-06-02 17:08:31 -04:00
1ed9ae7d60 Open dashboardUrl instead of remoteUrl in auth login 2015-06-02 13:21:59 -04:00
329bf25dbd Print feedback message after app create 2015-06-02 13:04:08 -04:00
e18ffba183 Quiet console.info if stdout is being redirected
We use `console.info()` for feedback messages.
2015-06-02 12:36:17 -04:00
ae3f0b429d Ask for confirmacion on app associate command 2015-06-02 12:32:35 -04:00
34736c4e9b Display feedback message after login 2015-06-02 11:57:52 -04:00
806678ee5f Merge pull request #55 from resin-io/feature/device-env-vars
Add per device environment variable support
2015-06-02 08:13:10 -04:00
1e70401bdd Make use of NPM@2 in Appveyor to prevent lock permission issues 2015-06-01 08:46:19 -04:00
3c7615f20d Upgrade drivelist to v1.2.2
Contains isSystem() fix for Linux
2015-06-01 08:35:48 -04:00
054d5e4879 Add per device environment variable support 2015-05-28 12:32:08 -04:00
b04ed43bed Merge pull request #54 from resin-io/fix/device-await-help
Fix device await help not showing up
2015-05-28 08:46:42 -04:00
c2bbb952c5 Fix device await help not showing up 2015-05-27 15:14:36 -04:00
63a9e1859b Merge pull request #53 from resin-io/feature/example-name
Accept names instead of ids in example commands
2015-05-25 08:53:06 -04:00
68ef069e6a Accept names instead of ids in example commands 2015-05-21 11:58:15 -04:00
72d4b21cb4 Configure appveyor CI 2015-05-21 10:52:37 -04:00
e8b931680d Merge pull request #52 from resin-io/fix/remove-test-notifier
Remove Mocha notification integration
2015-05-20 13:50:47 -04:00
218b407f30 Remove Mocha notification integration
It doesn't work in tmux and causes the process to hang.
2015-05-20 13:15:39 -04:00
773cc27145 Resin CLI v0.10.8 2015-05-19 15:04:52 -04:00
1c76e2e15b Upgrade Resin Image to v1.1.3 2015-05-19 15:02:12 -04:00
e466cfd6ff Resin CLI v0.10.7 2015-05-18 10:39:07 -04:00
992b04d521 Merge pull request #51 from resin-io/feature/nicer-logs
Expose logs as cli.actions.logs instead of cli.actions.logs.logs
2015-05-18 10:38:41 -04:00
5c16c86871 Merge pull request #50 from resin-io/fix/js-main
Point to a JavaScript file in package.json main property
2015-05-18 10:38:28 -04:00
78af9bbb10 Expose logs as cli.actions.logs instead of cli.actions.logs.logs 2015-05-18 09:37:27 -04:00
b78c48d89f Point to a JavaScript file in package.json main property 2015-05-18 09:35:10 -04:00
1f8c610bb0 Resin CLI v0.10.6 2015-05-14 11:50:43 -03:00
d220728380 Merge pull request #49 from resin-io/feature/device-list-devices
Return devices array to the done callback in device list command
2015-05-14 11:47:25 -03:00
db58e9986c Return devices array to the done callback in device list command
Useful when using the CLI programatically.
2015-05-14 11:43:41 -03:00
2a5e66eca6 Merge pull request #48 from resin-io/feature/use-selfupdate
Make use of selfupdate
2015-05-14 11:40:23 -03:00
e7e8ec296c Make use of selfupdate 2015-05-14 11:32:18 -03:00
80e69c56d0 Resin CLI v0.10.5 2015-05-11 14:42:00 -03:00
ce3c6aecff Upgrade Resin SDK to v1.4.3 2015-05-11 14:39:55 -03:00
300f76ba83 Upgrade Resin SDK to v1.4.2 2015-05-11 14:27:09 -03:00
a4e8a38bf4 Merge pull request #44 from resin-io/fix/download-exit
Fix callback not being called on success in os download command
2015-05-11 14:26:07 -03:00
9bb04f43a8 Fix callback not being called on success in os download command 2015-05-11 14:23:34 -03:00
9b0c08bd46 Don't umount in os install as it's already handled in Resin Image 2015-05-11 13:10:06 -03:00
679d48e86e Merge branch 'master' of github.com:resin-io/resin-cli 2015-05-11 13:08:44 -03:00
4b6bf60531 Upgrade Resin Image to v1.1.2 2015-05-11 12:38:19 -03:00
d8ce6648e2 Handle device unmounting in os install command 2015-05-11 10:04:05 -03:00
402bc2d3a8 Merge pull request #43 from resin-io/fix/non-interactive-login
Make login command behave non interactively if a token is passed as an argument
2015-05-11 09:46:07 -03:00
f3e193be0f Make login command behave non interactively if a token is passed as an argument 2015-05-11 09:42:25 -03:00
f5b461612b Upgrade Capitano to v1.6.0 2015-05-11 09:30:07 -03:00
d2514a3fc3 Resin CLI v0.10.4 2015-05-08 14:29:02 -03:00
2019f9fdeb Merge pull request #42 from resin-io/feature/use-resin-image
Make use of resin-image to remove image writing logic from the CLI
2015-05-08 14:28:33 -03:00
656f3e5cd9 Make use of resin-image to remove image writing logic from the CLI 2015-05-08 14:26:04 -03:00
741acfbba3 Merge pull request #41 from resin-io/feature/command-run
Make use of capitano.run() to run subcommands
2015-05-08 14:23:37 -03:00
4b7eca02a0 Resin CLI v0.10.3 2015-05-07 12:03:40 -03:00
c7788a80e1 Upgrade Resin SDK to v1.4.1
That version includes the os download piping issue fix
2015-05-07 12:03:12 -03:00
08648894e3 Merge pull request #40 from resin-io/feature/device-await
Implement device await command
2015-05-06 11:18:42 -03:00
4c5d5697bc Implement device await command 2015-05-06 11:14:08 -03:00
c758a5b9ea Make use of capitano.run() to run subcommands 2015-05-05 17:34:24 -03:00
2af54e2e28 Merge pull request #39 from resin-io/feature/coffee-compile
Compile CoffeeScript by default when initializing watch task
2015-05-05 06:49:45 -03:00
cf9b23b987 Compile CoffeeScript by default when initializing watch task 2015-05-05 00:21:30 -04:00
f8380ec8e6 Merge pull request #38 from resin-io/feature/os-install-umount
Handle device unmounting in os install command
2015-05-05 00:06:25 -04:00
cd3245a631 Handle device unmounting in os install command 2015-05-02 10:34:11 -04:00
144a155208 Merge pull request #36 from resin-io/feature/standard-version
Implement --version/-v global options. Closes #35
2015-04-30 13:12:51 -04:00
7f7ca13001 Implement --version/-v global options. Closes #35 2015-04-30 11:56:15 -04:00
361e149063 Merge pull request #34 from resin-io/fix/note-validation
Fix note command validation issues
2015-04-29 14:43:47 -04:00
fab85b381a Throw a nice error if note contents are missing 2015-04-29 14:39:46 -04:00
faecf103bf Upgrade Resin SDK to v1.3.4
This version addresses the device validation issue
2015-04-29 14:39:28 -04:00
a0f8c1aa8c Merge pull request #33 from resin-io/fix/devices-app-name
Fix devices command not showing application names. Closes #32
2015-04-29 14:13:09 -04:00
24726b575d Fix devices command not showing application names. Closes #32 2015-04-29 14:07:59 -04:00
688b89a099 Resin CLI v0.10.2 2015-04-28 09:34:41 -04:00
2e39110cc0 Merge pull request #31 from resin-io/feature/app-uniqueness
Check that an application exists before asking it's type. Closes #30
2015-04-28 09:33:59 -04:00
193cedae26 Check that an application exists before asking it's type. Closes #30 2015-04-28 09:18:21 -04:00
3d1f023ef5 Merge pull request #29 from resin-io/feature/list-all-devices
Make devices command list all devices if no application option
2015-04-27 11:26:00 -04:00
9bb51d7146 Make devices command list all devices if no application option. Closes #17 2015-04-27 11:21:30 -04:00
84900aa588 Remove outdated uuid checking help message 2015-04-27 10:51:26 -04:00
b2bce3c4ac Upgrade Resin SDK 2015-04-27 10:49:28 -04:00
8c11620a42 Upgrade Resin SDK 2015-04-27 10:33:34 -04:00
7c1e0ac2e9 Merge pull request #28 from resin-io/fix/logs-messages
Fix logs printing, as messages got added a message property
2015-04-27 10:05:16 -04:00
9a3c844336 Print logs correctly, as they recently got a message field added 2015-04-27 09:30:57 -04:00
69039d21c2 Resin CLI v0.10.1 2015-04-21 11:28:24 -04:00
34c9cdd8bb Upgrade Resin SDK to v1.2.1 2015-04-21 11:26:40 -04:00
0a8b30e824 Resin CLI v0.10.0 2015-04-21 09:06:45 -04:00
ea5b521262 Merge pull request #26 from resin-io/fix/device-init-temp-output
Fix temporary os download output option in device init
2015-04-21 09:06:11 -04:00
3bc71577b5 Fix temporary os download output option in device init 2015-04-21 08:37:40 -04:00
0fb24162fc Merge pull request #24 from resin-io/fix/update
Fix logical issue in update command
2015-04-20 14:14:33 -04:00
d0d63f5bbb Merge pull request #25 from resin-io/deduplicate/whoami
Remove duplicated whoami command
2015-04-20 14:14:25 -04:00
8041905144 Remove duplicated whoami command 2015-04-20 12:46:43 -04:00
37d96e238d Fix logical issue in update command 2015-04-20 12:42:31 -04:00
ae8c941bfe Resin CLI v0.9.0 2015-04-20 12:15:57 -04:00
4c16835ca4 Merge pull request #23 from resin-io/feature/device-init-app-name
Make device init and os download take app names instead of ids
2015-04-20 12:14:53 -04:00
7bd8922a4e Upgrade Resin VCS to v1.2.0 and make use of vcs.getApplicationName() 2015-04-20 11:41:26 -04:00
42b2e2fcf0 Regenerate documentation 2015-04-20 09:14:47 -04:00
f7256e9927 Make device init command take an application name instead of id 2015-04-20 09:13:15 -04:00
85444a5a6a Make os download command accept an application name instead of id 2015-04-20 09:06:40 -04:00
ac115c7ea3 Merge pull request #22 from resin-io/feature/clone-dir
Make "example clone" clone to a new directory
2015-04-20 08:59:28 -04:00
3c2a440553 Make "example clone" clone to a new directory 2015-04-20 08:56:10 -04:00
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
90 changed files with 1943 additions and 1482 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

@ -3,6 +3,7 @@
[![npm version](https://badge.fury.io/js/resin-cli.svg)](http://badge.fury.io/js/resin-cli)
[![dependencies](https://david-dm.org/resin-io/resin-cli.png)](https://david-dm.org/resin-io/resin-cli.png)
[![Build Status](https://travis-ci.org/resin-io/resin-cli.svg?branch=master)](https://travis-ci.org/resin-io/resin-cli)
[![Build status](https://ci.appveyor.com/api/projects/status/45i7d0m0patxj420?svg=true)](https://ci.appveyor.com/project/jviotti/resin-cli)
The official Resin CLI tool.

27
appveyor.yml Normal file
View 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

View File

@ -31,17 +31,21 @@
action: function(params, options, done) {
return async.waterfall([
function(callback) {
return resin.models.application.has(params.name, callback);
}, function(hasApplication, callback) {
if (hasApplication) {
return callback(new Error('You already have an application with that name!'));
}
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);
}
@ -50,7 +54,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 +68,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,41 +84,54 @@
};
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\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.id, callback);
return resin.models.application.get(params.name, callback);
}, function(application, callback) {
return vcs.addRemote(currentDirectory, application.git_repository, callback);
}
@ -140,14 +157,24 @@
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
}, 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,36 @@
resin = require('resin-sdk');
settings = require('resin-settings-client');
visuals = require('resin-cli-visuals');
TOKEN_URL = url.resolve(settings.get('dashboardUrl'), '/preferences');
exports.login = {
signature: 'login',
signature: 'login [token]',
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'
}
],
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) {
var hasOptionCredentials;
hasOptionCredentials = !_.isEmpty(options);
if (hasOptionCredentials) {
if (!options.username) {
return done(new Error('Missing username'));
}
if (!options.password) {
return done(new Error('Missing password'));
}
}
return async.waterfall([
function(callback) {
if (hasOptionCredentials) {
return callback(null, options);
} else {
return visuals.widgets.login(callback);
if (params.token != null) {
return callback(null, params.token);
}
}, function(credentials, callback) {
return resin.auth.login(credentials, callback);
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 visuals.patterns.loginWithToken(callback);
});
}, function(token, callback) {
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);
}
@ -104,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);
@ -123,10 +116,14 @@
permission: 'user',
action: function(params, options, done) {
return resin.auth.whoami(function(error, username) {
if (error != null) {
return done(error);
}
if (username == null) {
return done(new Error('Username not found'));
}
return console.log(username);
console.log(username);
return done();
});
}
};

View File

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

View File

@ -1,5 +1,9 @@
(function() {
var _, async, commandOptions, osAction, path, resin, vcs, visuals;
var _, async, capitano, commandOptions, fse, image, inject, manager, path, pine, registerDevice, resin, tmp, vcs, visuals;
fse = require('fs-extra');
capitano = require('capitano');
_ = require('lodash-contrib');
@ -13,34 +17,52 @@
vcs = require('resin-vcs');
commandOptions = require('./command-options');
manager = require('resin-image-manager');
osAction = require('./os');
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');
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',
options: [commandOptions.application],
help: 'Use this command to list all devices that belong to you.\n\nYou can filter the devices by application by using the `--application` option.\n\nExamples:\n\n $ resin devices\n $ resin devices --application MyApp\n $ resin devices --app MyApp\n $ resin devices -a MyApp',
options: [commandOptions.optionalApplication],
permission: 'user',
action: function(params, options, done) {
return resin.models.device.getAllByApplication(options.application, function(error, devices) {
var getFunction;
if (options.application != null) {
getFunction = _.partial(resin.models.device.getAllByApplication, options.application);
} else {
getFunction = resin.models.device.getAll;
}
return getFunction(function(error, devices) {
if (error != null) {
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);
});
}
};
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 +73,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 +96,23 @@
};
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);
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);
}
], done);
}
@ -108,38 +134,157 @@
}
};
exports.await = {
signature: 'device await <name>',
description: 'await for a device to become online',
help: 'Use this command to await for a device to become online.\n\nThe process will exit when the device becomes online.\n\nNotice that there is no time limit for this command, so it might run forever.\n\nYou can configure the poll interval with the --interval option (defaults to 3000ms).\n\nExamples:\n\n $ resin device await MyDevice\n $ resin device await MyDevice --interval 1000',
options: [
{
signature: 'interval',
parameter: 'interval',
description: 'poll interval',
alias: 'i'
}
],
permission: 'user',
action: function(params, options, done) {
var poll;
if (options.interval == null) {
options.interval = 3000;
}
poll = function() {
return resin.models.device.isOnline(params.name, function(error, isOnline) {
if (error != null) {
return done(error);
}
if (isOnline) {
console.info("Device became online: " + params.name);
return done();
} else {
console.info("Polling device network status: " + params.name);
return setTimeout(poll, options.interval);
}
});
};
return poll();
}
};
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 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) {
params.id = options.application;
var networkOptions;
networkOptions = {
network: options.network,
wifiSsid: options.ssid,
wifiKey: options.key
};
return async.waterfall([
function(callback) {
if (options.application != null) {
return callback(null, options.application);
}
return vcs.getApplicationId(process.cwd(), callback);
}, function(applicationId, callback) {
params.id = applicationId;
return vcs.getApplicationName(process.cwd(), callback);
}, function(applicationName, callback) {
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);
}
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();
}
options.yes = confirmed;
return osAction.download.action(params, options, callback);
}, function(outputFile, callback) {
params.image = outputFile;
return osAction.install.action(params, options, callback);
if (networkOptions.network != null) {
return callback();
}
return visuals.patterns.selectNetworkParameters(function(error, parameters) {
if (error != null) {
return callback(error);
}
_.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);
}

View File

@ -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);
}
}
};

View File

@ -1,5 +1,7 @@
(function() {
var _, async, examplesData, fs, path, resin, vcs, visuals;
var _, async, examplesData, fs, mkdirp, path, resin, vcs, visuals;
mkdirp = require('mkdirp');
async = require('async');
@ -33,45 +35,54 @@
}
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, example;
example = examplesData[params.id - 1];
var currentDirectory, destination, 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));
}
currentDirectory = process.cwd();
console.info("Cloning " + example.display_name + " to " + currentDirectory);
return vcs.clone(example.repository, currentDirectory, done);
destination = path.join(currentDirectory, example.name);
return mkdirp(destination, function(error) {
if (error != null) {
return done(error);
}
console.info("Cloning " + example.display_name + " to " + destination);
vcs.clone(example.repository, destination, done);
return done();
});
}
};

View File

@ -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'),

View File

@ -1,15 +1,32 @@
(function() {
var packageJSON;
var packageJSON, settings;
settings = require('resin-settings-client');
packageJSON = require('../../package.json');
exports.version = {
signature: 'version',
description: 'output the version number',
help: 'Display the Resin CLI, as well as the bundled NodeJS version.',
action: function() {
console.log(packageJSON.name + ": " + packageJSON.version);
return console.log("node: " + process.version);
help: 'Display the Resin CLI version.',
action: function(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.\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();
}
};

View File

@ -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();
});

View File

@ -7,10 +7,10 @@
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,\nand the tool won\'t notice if you\'re using an invalid UUID.\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',
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',
options: [
{
signature: 'num',
@ -35,10 +35,10 @@
}
if (_.isArray(message)) {
_.each(message, function(line) {
return console.log(line);
return console.log(line.message);
});
} else {
console.log(message);
console.log(message.message);
}
return done();
});

View File

@ -1,5 +1,7 @@
(function() {
var async, resin;
var _, async, resin;
_ = require('lodash');
async = require('async');
@ -8,18 +10,21 @@
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'
}
],
permission: 'user',
action: function(params, options, done) {
if (_.isEmpty(params.note)) {
return done(new Error('Missing note content'));
}
return resin.models.device.note(options.device, params.note, done);
}
};

View File

@ -1,169 +0,0 @@
(function() {
var _, async, commandOptions, diskio, fs, mkdirp, npm, os, packageJSON, path, progressStream, resin, updateActions, visuals;
_ = 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');
exports.download = {
signature: 'os download <id>',
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 91 --output ~/MyResinOS.zip\n $ resin os download 91 --network ethernet --output ~/MyResinOS.zip\n $ resin os download 91 --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip\n $ resin os download 91 --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) {
var osParams;
osParams = {
network: options.network,
wifiSsid: options.ssid,
wifiKey: options.key,
appId: params.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\nYou may have to unmount the device before attempting this operation.\n\nSee the `drives` command to get a list of all connected devices to your machine and their respective ids.\n\nIn Mac OS X:\n\n $ sudo diskutil unmountDisk /dev/xxx\n\nIn GNU/Linux:\n\n $ sudo umount /dev/xxx\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 updateActions.update.action(params, options, _.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, error, imageFileSize, imageFileStream, progress;
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);
}
], function(error) {
var resinWritePath, windosu;
if (error == null) {
return done();
}
if (_.all([os.platform() === 'win32', error.code === 'EPERM' || error.code === 'EACCES', !options.fromScript])) {
windosu = require('windosu');
resinWritePath = "\"" + (path.join(__dirname, '..', '..', 'bin', 'resin-write')) + "\"";
return windosu.exec("\"" + process.argv[0] + "\" " + resinWritePath + " \"" + params.image + "\" \"" + params.device + "\"");
} else {
return done(error);
}
});
}
};
}).call(this);

View File

@ -1,7 +1,7 @@
(function() {
var npm, packageJSON;
var packageJSON, selfupdate;
npm = require('../npm');
selfupdate = require('selfupdate');
packageJSON = require('../../package.json');
@ -10,12 +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.update(packageJSON.name, function(error, version) {
return selfupdate.update(packageJSON, function(error, version) {
if (error != null) {
return done(error);
}
console.info("Upgraded " + packageJSON.name + " to v" + version + ".");
return done(null, version);
console.info("Updated " + packageJSON.name + " to version " + version + ".");
return done();
});
}
};

View File

@ -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'));
}
@ -49,6 +52,13 @@
alias: 'j'
});
capitano.globalOption({
signature: 'version',
description: actions.info.version.description,
boolean: true,
alias: 'v'
});
capitano.globalOption({
signature: 'no-color',
description: 'disable colour highlighting',
@ -57,6 +67,8 @@
capitano.command(actions.info.version);
capitano.command(actions.info.config);
capitano.command(actions.help.help);
capitano.command(actions.auth.login);
@ -71,8 +83,6 @@
capitano.command(actions.app.list);
capitano.command(actions.app.info);
capitano.command(actions.app.remove);
capitano.command(actions.app.restart);
@ -81,6 +91,8 @@
capitano.command(actions.app.init);
capitano.command(actions.app.info);
capitano.command(actions.device.list);
capitano.command(actions.device.supported);
@ -89,6 +101,8 @@
capitano.command(actions.device.init);
capitano.command(actions.device.await);
capitano.command(actions.device.info);
capitano.command(actions.device.remove);
@ -117,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);
@ -155,13 +165,17 @@
}, 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) {
changeProjectDirectory(cli.global.project);
}
return capitano.execute(cli, callback);
if (cli.global.version) {
return actions.info.version.action(null, null, callback);
} else {
return capitano.execute(cli, callback);
}
}
], errors.handle);

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

@ -1,63 +0,0 @@
(function() {
var _, async, npm;
npm = require('npm');
async = require('async');
_ = 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) {
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);

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

791
doc/cli.markdown Normal file
View File

@ -0,0 +1,791 @@
# 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
- [login [token]](#/pages/using/cli.md#login-token-)
- [logout](#/pages/using/cli.md#logout)
- [signup](#/pages/using/cli.md#signup)
- [whoami](#/pages/using/cli.md#whoami)
- 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 await &#60;name&#62;](#/pages/using/cli.md#device-await-60-name-62-)
- [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;name&#62;](#/pages/using/cli.md#os-download-60-name-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.
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
## 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
## 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://dashboard.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
## whoami
Use this command to find out the current logged in username.
Examples:
$ resin whoami
# Device
## devices
Use this command to list all devices that belong to you.
You can filter the devices by application by using the `--application` option.
Examples:
$ resin devices
$ resin devices --application MyApp
$ resin devices --app MyApp
$ resin devices -a 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 await &#60;name&#62;
Use this command to await for a device to become online.
The process will exit when the device becomes online.
Notice that there is no time limit for this command, so it might run forever.
You can configure the poll interval with the --interval option (defaults to 3000ms).
Examples:
$ resin device await MyDevice
$ resin device await MyDevice --interval 1000
### Options
#### --interval, -i &#60;interval&#62;
poll interval
## 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 MyApp
$ resin device init --application MyApp --network ethernet
$ resin device init /dev/disk2 --application MyApp --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.
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;name&#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 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
#### --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.
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

@ -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' ], ->
@ -54,6 +53,6 @@ gulp.task 'build', [
'man'
]
gulp.task 'watch', [ 'test', 'lint' ], ->
gulp.task 'watch', [ 'test', 'lint', 'coffee' ], ->
gulp.watch([ OPTIONS.files.coffee, OPTIONS.files.json ], [ 'coffee' ])
gulp.watch([ OPTIONS.files.man ], [ 'man' ])

View File

@ -37,14 +37,22 @@ exports.create =
async.waterfall([
(callback) ->
return callback(null, options.type) if options.type?
resin.models.application.has(params.name, callback)
resin.models.device.getSupportedDeviceTypes (error, deviceTypes) ->
return callback(error) if error?
visuals.widgets.select('Select a type', deviceTypes, callback)
(hasApplication, callback) ->
if hasApplication
return callback(new Error('You already have an application with that name!'))
return callback(null, options.type) if options.type?
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)
@ -55,7 +63,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 +83,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 +106,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,29 +130,33 @@ 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.
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 91
$ resin app associate 91 --project my/app/directory
$ resin app associate MyApp
$ resin app associate MyApp --project my/app/directory
'''
options: [ commandOptions.yes ]
permission: 'user'
action: (params, options, done) ->
currentDirectory = process.cwd()
@ -152,10 +164,21 @@ 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) ->
resin.models.application.get(params.id, callback)
resin.models.application.get(params.name, callback)
(application, callback) ->
vcs.addRemote(currentDirectory, application.git_repository, callback)
@ -190,12 +213,22 @@ 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) ->
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,62 @@
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'
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.
TOKEN_URL = url.resolve(settings.get('dashboardUrl'), '/preferences')
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.
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 --username <username> --password <password>
$ resin login
'''
options: [
{
signature: 'username'
parameter: 'username'
description: 'user name'
alias: 'u'
}
{
signature: 'password'
parameter: 'password'
description: 'user password'
alias: 'p'
}
]
$ resin login "eyJ0eXAiOiJKV1Qi..."
"""
action: (params, options, done) ->
hasOptionCredentials = not _.isEmpty(options)
if hasOptionCredentials
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)
return callback(null, params.token) if params.token?
(credentials, callback) ->
resin.auth.login(credentials, callback)
console.info """
To login to the Resin CLI, you need your unique token, which is accesible from
the preferences page at #{TOKEN_URL}
], done
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.
"""
visuals.patterns.loginWithToken(callback)
(token, callback) ->
resin.auth.loginWithToken(token, callback)
(callback) ->
resin.auth.whoami(callback)
(username, callback) ->
console.info("Successfully logged in as: #{username}")
return callback()
], done)
exports.logout =
signature: 'logout'
@ -131,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) ->
@ -155,8 +155,10 @@ exports.whoami =
permission: 'user'
action: (params, options, done) ->
resin.auth.whoami (error, username) ->
return done(error) if error?
if not username?
return done(new Error('Username not found'))
console.log(username)
return done()

View File

@ -9,13 +9,25 @@ exports.yes =
exports.optionalApplication =
signature: 'application'
parameter: 'application'
description: 'application id'
description: 'application name'
alias: [ 'a', 'app' ]
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'

View File

@ -1,26 +1,48 @@
fse = require('fs-extra')
capitano = require('capitano')
_ = require('lodash-contrib')
path = require('path')
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'
description: 'list all devices'
help: '''
Use this command to list all devices that belong to a certain application.
Use this command to list all devices that belong to you.
You can filter the devices by application by using the `--application` option.
Examples:
$ resin devices --application 91
$ resin devices
$ resin devices --application MyApp
$ resin devices --app MyApp
$ resin devices -a MyApp
'''
options: [ commandOptions.application ]
options: [ commandOptions.optionalApplication ]
permission: 'user'
action: (params, options, done) ->
resin.models.device.getAllByApplication options.application, (error, devices) ->
if options.application?
getFunction = _.partial(resin.models.device.getAllByApplication, options.application)
else
getFunction = resin.models.device.getAll
getFunction (error, devices) ->
return done(error) if error?
console.log visuals.widgets.table.horizontal devices, [
'id'
@ -32,21 +54,21 @@ exports.list =
'last_seen'
]
return done()
return done(null, devices)
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 +89,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 +99,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 +126,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 +135,25 @@ 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)
visuals.widgets.ask('How do you want to name this device?', null, callback)
if not _.isEmpty(params.newName)
return callback(null, params.newName)
(name, callback) ->
resin.models.device.rename(params.id, name, 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)
], done
@ -147,6 +174,46 @@ exports.supported =
_.each(devices, _.unary(console.log))
done()
exports.await =
signature: 'device await <name>'
description: 'await for a device to become online'
help: '''
Use this command to await for a device to become online.
The process will exit when the device becomes online.
Notice that there is no time limit for this command, so it might run forever.
You can configure the poll interval with the --interval option (defaults to 3000ms).
Examples:
$ resin device await MyDevice
$ resin device await MyDevice --interval 1000
'''
options: [
signature: 'interval'
parameter: 'interval'
description: 'poll interval'
alias: 'i'
]
permission: 'user'
action: (params, options, done) ->
options.interval ?= 3000
poll = ->
resin.models.device.isOnline params.name, (error, isOnline) ->
return done(error) if error?
if isOnline
console.info("Device became online: #{params.name}")
return done()
else
console.info("Polling device network status: #{params.name}")
setTimeout(poll, options.interval)
poll()
exports.init =
signature: 'device init [device]'
description: 'initialise a device with resin os'
@ -160,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:
@ -177,9 +242,10 @@ exports.init =
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
$ resin device init
$ resin device init --application MyApp
$ resin device init --application MyApp --network ethernet
$ resin device init /dev/disk2 --application MyApp --network wifi --ssid MyNetwork --key secret
'''
options: [
commandOptions.optionalApplication
@ -188,32 +254,114 @@ exports.init =
commandOptions.wifiKey
]
permission: 'user'
root: true
action: (params, options, done) ->
params.id = options.application
networkOptions =
network: options.network
wifiSsid: options.ssid
wifiKey: options.key
async.waterfall([
(callback) ->
return callback(null, options.application) if options.application?
vcs.getApplicationId(process.cwd(), callback)
vcs.getApplicationName(process.cwd(), callback)
(applicationName, callback) ->
options.application = applicationName
resin.models.application.has(options.application, callback)
(hasApplication, callback) ->
if not hasApplication
return callback(new Error("Invalid application: #{options.application}"))
(applicationId, callback) ->
params.id = applicationId
return callback(null, params.device) if params.device?
visuals.patterns.selectDrive(callback)
(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
options.yes = confirmed
osAction.download.action(params, options, callback)
return callback() if networkOptions.network?
visuals.patterns.selectNetworkParameters (error, parameters) ->
return callback(error) if error?
_.extend(networkOptions, parameters)
return callback()
(outputFile, callback) ->
params.image = outputFile
osAction.install.action(params, options, 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)

View File

@ -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)

View File

@ -1,3 +1,4 @@
mkdirp = require('mkdirp')
async = require('async')
fs = require('fs')
path = require('path')
@ -29,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'
@ -66,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
@ -76,15 +76,20 @@ 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()
console.info("Cloning #{example.display_name} to #{currentDirectory}")
vcs.clone(example.repository, currentDirectory, done)
destination = path.join(currentDirectory, example.name)
mkdirp destination, (error) ->
return done(error) if error?
console.info("Cloning #{example.display_name} to #{destination}")
vcs.clone(example.repository, destination, done)
return done()

View File

@ -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')

View File

@ -1,11 +1,25 @@
settings = require('resin-settings-client')
packageJSON = require('../../package.json')
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}")
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()

View File

@ -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()

View File

@ -3,7 +3,7 @@ resin = require('resin-sdk')
LOGS_HISTORY_COUNT = 200
exports.logs =
module.exports =
signature: 'logs <uuid>'
description: 'show device logs'
help: '''
@ -16,8 +16,7 @@ exports.logs =
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.
Note that for now you need to provide the whole UUID for this command to work correctly.
This is due to some technical limitations that we plan to address soon.
@ -50,7 +49,7 @@ exports.logs =
return done(error) if error?
if _.isArray(message)
_.each message, (line) ->
console.log(line)
console.log(line.message)
else
console.log(message)
console.log(message.message)
return done()

View File

@ -1,3 +1,4 @@
_ = require('lodash')
async = require('async')
resin = require('resin-sdk')
@ -9,20 +10,24 @@ 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'
]
permission: 'user'
action: (params, options, done) ->
if _.isEmpty(params.note)
return done(new Error('Missing note content'))
resin.models.device.note(options.device, params.note, done)

View File

@ -1,205 +0,0 @@
_ = 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')
exports.download =
signature: 'os download <id>'
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 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: [
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) ->
osParams =
network: options.network
wifiSsid: options.ssid
wifiKey: options.key
appId: params.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.
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: [ 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...
'''
updateActions.update.action(params, options, _.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
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)
], (error) ->
return done() if not error?
if _.all [
os.platform() is 'win32'
error.code is 'EPERM' or error.code is 'EACCES'
# 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}\"")
else
return done(error)

View File

@ -1,4 +1,4 @@
npm = require('../npm')
selfupdate = require('selfupdate')
packageJSON = require('../../package.json')
exports.update =
@ -20,7 +20,7 @@ exports.update =
$ resin update
'''
action: (params, options, done) ->
npm.update packageJSON.name, (error, version) ->
selfupdate.update packageJSON, (error, version) ->
return done(error) if error?
console.info("Upgraded #{packageJSON.name} to v#{version}.")
return done(null, version)
console.info("Updated #{packageJSON.name} to version #{version}.")
return done()

View File

@ -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()
@ -31,6 +32,12 @@ capitano.globalOption
description: 'project path'
alias: 'j'
capitano.globalOption
signature: 'version'
description: actions.info.version.description
boolean: true
alias: 'v'
# We don't do anything in response to this options
# explicitly. We use InquirerJS to provide CLI widgets,
# and that module understands --no-color automatically.
@ -41,6 +48,7 @@ capitano.globalOption
# ---------- Info Module ----------
capitano.command(actions.info.version)
capitano.command(actions.info.config)
# ---------- Help Module ----------
capitano.command(actions.help.help)
@ -54,17 +62,18 @@ 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)
@ -91,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)
@ -128,12 +133,15 @@ 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?
changeProjectDirectory(cli.global.project)
capitano.execute(cli, callback)
if cli.global.version
actions.info.version.action(null, null, callback)
else
capitano.execute(cli, callback)
], errors.handle)

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

@ -1,57 +0,0 @@
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([
(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)

View File

@ -1,4 +1,4 @@
.TH "RESIN" "1" "March 2015" "" ""
.TH "RESIN" "1" "May 2015" "" ""
.SH "NAME"
\fBresin\fR \- tab completion for resin
.SH DESCRIPTION

View File

@ -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

View File

@ -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

View File

@ -1,8 +1,8 @@
{
"name": "resin-cli",
"version": "0.5.0",
"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",
@ -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",
@ -42,29 +42,34 @@
"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",
"diskio": "^1.0.0",
"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.1.0",
"nplugm": "^2.2.0",
"npm": "^2.6.1",
"open": "0.0.5",
"progress-stream": "^0.5.0",
"resin-cli-visuals": "^0.1.0",
"resin-sdk": "^1.0.0",
"resin-settings-client": "^1.0.0",
"resin-vcs": "^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"
}

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