Compare commits

...

41 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
27 changed files with 533 additions and 501 deletions

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

@ -39,14 +39,13 @@
if (options.type != null) {
return callback(null, options.type);
}
return resin.models.device.getSupportedDeviceTypes(function(error, deviceTypes) {
if (error != null) {
return callback(error);
}
return visuals.widgets.select('Select a type', deviceTypes, callback);
});
return visuals.patterns.selectDeviceType(callback);
}, function(type, callback) {
return resin.models.application.create(params.name, type, callback);
options.type = type;
return resin.models.application.create(params.name, options.type, callback);
}, function(applicationId, callback) {
console.info("Application created: " + params.name + " (" + options.type + ", id " + applicationId + ")");
return callback();
}
], done);
}
@ -110,13 +109,26 @@
exports.associate = {
signature: 'app associate <name>',
description: 'associate a resin project',
help: 'Use this command to associate a project directory with a resin application.\n\nThis command adds a \'resin\' git remote to the directory and runs git init if necessary.\n\nExamples:\n\n $ resin app associate MyApp\n $ resin app associate MyApp --project my/app/directory',
help: 'Use this command to associate a project directory with a resin application.\n\nThis command adds a \'resin\' git remote to the directory and runs git init if necessary.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin app associate MyApp\n $ resin app associate MyApp --project my/app/directory',
options: [commandOptions.yes],
permission: 'user',
action: function(params, options, done) {
var currentDirectory;
currentDirectory = process.cwd();
return async.waterfall([
function(callback) {
return resin.models.application.has(params.name, callback);
}, function(hasApp, callback) {
var message;
if (!hasApp) {
return callback(new Error("Invalid application: " + params.name));
}
message = "Are you sure you want to associate " + currentDirectory + " with " + params.name + "?";
return visuals.patterns.confirm(options.yes, message, callback);
}, function(confirmed, callback) {
if (!confirmed) {
return done();
}
return vcs.initialize(currentDirectory, callback);
}, function(callback) {
return resin.models.application.get(params.name, callback);
@ -145,7 +157,12 @@
function(callback) {
var currentDirectoryBasename;
currentDirectoryBasename = path.basename(currentDirectory);
return visuals.widgets.ask('What is the name of your application?', currentDirectoryBasename, callback);
return visuals.form.ask({
label: 'What is the name of your application?',
name: 'application',
type: 'text',
value: currentDirectoryBasename
}, callback);
}, function(applicationName, callback) {
return exports.create.action({
name: applicationName

View File

@ -15,7 +15,7 @@
visuals = require('resin-cli-visuals');
TOKEN_URL = url.resolve(settings.get('remoteUrl'), '/preferences');
TOKEN_URL = url.resolve(settings.get('dashboardUrl'), '/preferences');
exports.login = {
signature: 'login [token]',
@ -32,10 +32,15 @@
if (error != null) {
console.error("Unable to open a web browser in the current environment.\nPlease visit " + TOKEN_URL + " manually.");
}
return visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback);
return visuals.patterns.loginWithToken(callback);
});
}, function(token, callback) {
return resin.auth.loginWithToken(token, done);
return resin.auth.loginWithToken(token, callback);
}, function(callback) {
return resin.auth.whoami(callback);
}, function(username, callback) {
console.info("Successfully logged in as: " + username);
return callback();
}
], done);
}
@ -92,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);

View File

@ -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,7 @@
(function() {
var _, async, capitano, commandOptions, osAction, path, resin, tmp, vcs, visuals;
var _, async, capitano, commandOptions, fse, image, inject, manager, path, pine, registerDevice, resin, tmp, vcs, visuals;
fse = require('fs-extra');
capitano = require('capitano');
@ -15,14 +17,22 @@
vcs = require('resin-vcs');
manager = require('resin-image-manager');
image = require('resin-image');
inject = require('resin-config-inject');
registerDevice = require('resin-register-device');
pine = require('resin-pine');
tmp = require('tmp');
tmp.setGracefulCleanup();
commandOptions = require('./command-options');
osAction = require('./os');
exports.list = {
signature: 'devices',
description: 'list all devices',
@ -96,7 +106,11 @@
if (!_.isEmpty(params.newName)) {
return callback(null, params.newName);
}
return visuals.widgets.ask('How do you want to name this device?', null, callback);
return visuals.form.ask({
label: 'How do you want to name this device?',
name: 'device',
type: 'text'
}, callback);
}, function(newName, callback) {
return resin.models.device.rename(params.name, newName, callback);
}
@ -159,10 +173,17 @@
exports.init = {
signature: 'device init [device]',
description: 'initialise a device with resin os',
help: 'Use this command to download the OS image of a certain application and write it to an SD Card.\n\nNote that this command requires admin privileges.\n\nIf `device` is omitted, you will be prompted to select a device interactively.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nYou can quiet the progress bar by passing the `--quiet` boolean option.\n\nYou may have to unmount the device before attempting this operation.\n\nYou need to configure the network type and other settings:\n\nEthernet:\n You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".\n\nWifi:\n You can setup the device OS to use wifi by setting the `--network` option to "wifi".\n If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.\n\nYou can omit network related options to be asked about them interactively.\n\nExamples:\n\n $ resin device init\n $ resin device init --application MyApp\n $ resin device init --application MyApp --network ethernet\n $ resin device init /dev/disk2 --application MyApp --network wifi --ssid MyNetwork --key secret',
help: 'Use this command to download the OS image of a certain application and write it to an SD Card.\n\nNote that this command requires admin privileges.\n\nIf `device` is omitted, you will be prompted to select a device interactively.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nYou can quiet the progress bar and other logging information by passing the `--quiet` boolean option.\n\nYou need to configure the network type and other settings:\n\nEthernet:\n You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".\n\nWifi:\n You can setup the device OS to use wifi by setting the `--network` option to "wifi".\n If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.\n\nYou can omit network related options to be asked about them interactively.\n\nExamples:\n\n $ resin device init\n $ resin device init --application MyApp\n $ resin device init --application MyApp --network ethernet\n $ resin device init /dev/disk2 --application MyApp --network wifi --ssid MyNetwork --key secret',
options: [commandOptions.optionalApplication, commandOptions.network, commandOptions.wifiSsid, commandOptions.wifiKey],
permission: 'user',
root: true,
action: function(params, options, done) {
var networkOptions;
networkOptions = {
network: options.network,
wifiSsid: options.ssid,
wifiKey: options.key
};
return async.waterfall([
function(callback) {
if (options.application != null) {
@ -170,7 +191,12 @@
}
return vcs.getApplicationName(process.cwd(), callback);
}, function(applicationName, callback) {
params.name = applicationName;
options.application = applicationName;
return resin.models.application.has(options.application, callback);
}, function(hasApplication, callback) {
if (!hasApplication) {
return callback(new Error("Invalid application: " + options.application));
}
if (params.device != null) {
return callback(null, params.device);
}
@ -184,27 +210,81 @@
if (!confirmed) {
return done();
}
options.yes = confirmed;
return tmp.file({
prefix: 'resin-image-',
postfix: '.img'
}, callback);
}, function(tmpPath, tmpFd, cleanupCallback, callback) {
options.output = tmpPath;
return osAction.download.action(params, options, function(error, outputFile) {
if (networkOptions.network != null) {
return callback();
}
return visuals.patterns.selectNetworkParameters(function(error, parameters) {
if (error != null) {
return callback(error);
}
return callback(null, outputFile, cleanupCallback);
});
}, function(outputFile, cleanupCallback, callback) {
return capitano.run("os install " + outputFile + " " + params.device, function(error) {
if (error != null) {
return callback(error);
}
cleanupCallback();
_.extend(networkOptions, parameters);
return callback();
});
}, function(callback) {
console.info("Checking application: " + options.application);
return resin.models.application.get(options.application, callback);
}, function(application, callback) {
return async.parallel({
manifest: function(callback) {
console.info('Getting device manifest for the application');
return resin.models.device.getManifestBySlug(application.device_type, callback);
},
config: function(callback) {
console.info('Fetching application configuration');
return resin.models.application.getConfiguration(options.application, networkOptions, callback);
}
}, callback);
}, function(results, callback) {
console.info('Associating the device');
return registerDevice.register(pine, results.config, function(error, device) {
if (error != null) {
return callback(error);
}
results.config.deviceId = device.id;
results.config.uuid = device.uuid;
params.uuid = results.config.uuid;
return callback(null, results);
});
}, function(results, callback) {
var bar, spinner;
console.info('Configuring device operating system image');
if (process.env.DEBUG) {
console.log(results.config);
}
bar = new visuals.widgets.Progress('Downloading Device OS');
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)');
return manager.configure(results.manifest, results.config, function(error, imagePath, removeCallback) {
spinner.stop();
return callback(error, imagePath, removeCallback);
}, function(state) {
if (state != null) {
return bar.update(state);
} else {
return spinner.start();
}
});
}, function(configuredImagePath, removeCallback, callback) {
var bar;
console.info('Attempting to write operating system image to drive');
bar = new visuals.widgets.Progress('Writing Device OS');
return image.write({
device: params.device,
image: configuredImagePath,
progress: _.bind(bar.update, bar)
}, function(error) {
if (error != null) {
return callback(error);
}
return callback(null, configuredImagePath, removeCallback);
});
}, function(temporalImagePath, removeCallback, callback) {
console.info('Image written successfully');
return removeCallback(callback);
}, function(callback) {
return resin.models.device.getByUUID(params.uuid, callback);
}, function(device, callback) {
console.info("Device created: " + device.name);
return callback(null, device.name);
}
], done);
}

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

@ -35,41 +35,43 @@
}
return example;
});
return console.log(visuals.widgets.table.horizontal(examplesData, ['id', 'display_name', 'repository', 'author']));
return console.log(visuals.widgets.table.horizontal(examplesData, ['id', 'name', 'display_name', 'repository', 'author']));
}
};
exports.info = {
signature: 'example <id>',
signature: 'example <name>',
description: 'list a single example application',
help: 'Use this command to show information of a single example application\n\nExample:\n\n $ resin example 3',
help: 'Use this command to show information of a single example application\n\nExample:\n\n $ resin example cimon',
permission: 'user',
action: function(params, options, done) {
var example, id;
id = params.id - 1;
example = examplesData[id];
var example;
example = _.findWhere(examplesData, {
name: params.name
});
if (example == null) {
return done(new Error("Unknown example: " + id));
return done(new Error("Unknown example: " + params.name));
}
example.id = id;
if (example.author == null) {
example.author = 'Unknown';
}
console.log(visuals.widgets.table.vertical(example, ['id', 'display_name', 'description', 'author', 'repository']));
console.log(visuals.widgets.table.vertical(example, ['name', 'display_name', 'description', 'author', 'repository']));
return done();
}
};
exports.clone = {
signature: 'example clone <id>',
signature: 'example clone <name>',
description: 'clone an example application',
help: 'Use this command to clone an example application to the current directory\n\nThis command outputs information about the cloning process.\nUse `--quiet` to remove that output.\n\nExample:\n\n $ resin example clone 3',
help: 'Use this command to clone an example application to the current directory\n\nThis command outputs information about the cloning process.\nUse `--quiet` to remove that output.\n\nExample:\n\n $ resin example clone cimon',
permission: 'user',
action: function(params, options, done) {
var currentDirectory, destination, example;
example = examplesData[params.id - 1];
example = _.findWhere(examplesData, {
name: params.name
});
if (example == null) {
return done(new Error("Unknown example: " + id));
return done(new Error("Unknown example: " + params.name));
}
currentDirectory = process.cwd();
destination = path.join(currentDirectory, example.name);

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,5 +1,7 @@
(function() {
var packageJSON;
var packageJSON, settings;
settings = require('resin-settings-client');
packageJSON = require('../../package.json');
@ -13,4 +15,19 @@
}
};
exports.config = {
signature: 'config',
description: 'see your current configuration',
help: 'See your current Resin CLI configuration.\n\nConfiguration lives in $HOME/.resin/config.',
action: function(params, options, done) {
var key, ref, value;
ref = settings.get();
for (key in ref) {
value = ref[key];
console.log(key + ": " + value);
}
return done();
}
};
}).call(this);

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

@ -1,155 +0,0 @@
(function() {
var _, async, capitano, commandOptions, elevate, image, mkdirp, os, packageJSON, path, resin, selfupdate, visuals;
capitano = require('capitano');
_ = require('lodash-contrib');
os = require('os');
async = require('async');
path = require('path');
mkdirp = require('mkdirp');
resin = require('resin-sdk');
image = require('resin-image');
visuals = require('resin-cli-visuals');
selfupdate = require('selfupdate');
commandOptions = require('./command-options');
packageJSON = require('../../package.json');
elevate = require('../elevate');
exports.download = {
signature: 'os download <name>',
description: 'download device OS',
help: 'Use this command to download the device OS configured to a specific network.\n\nEthernet:\n You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".\n\nWifi:\n You can setup the device OS to use wifi by setting the `--network` option to "wifi".\n If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.\n\nAlternatively, you can omit all kind of network configuration options to configure interactively.\n\nYou have to specify an output location with the `--output` option.\n\nExamples:\n\n $ resin os download MyApp --output ~/MyResinOS.zip\n $ resin os download MyApp --network ethernet --output ~/MyResinOS.zip\n $ resin os download MyApp --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip\n $ resin os download MyApp --network ethernet --output ~/MyResinOS.zip',
options: [
commandOptions.network, commandOptions.wifiSsid, commandOptions.wifiKey, {
signature: 'output',
parameter: 'output',
description: 'output file',
alias: 'o',
required: 'You need to specify an output file'
}
],
permission: 'user',
action: function(params, options, done) {
return resin.models.application.get(params.name, function(error, application) {
var osParams;
if (error != null) {
return done(error);
}
osParams = {
network: options.network,
wifiSsid: options.ssid,
wifiKey: options.key,
appId: application.id
};
return async.waterfall([
function(callback) {
if (osParams.network != null) {
return callback();
}
return visuals.patterns.selectNetworkParameters(function(error, parameters) {
if (error != null) {
return callback(error);
}
_.extend(osParams, parameters);
return callback();
});
}, function(callback) {
return mkdirp(path.dirname(options.output), _.unary(callback));
}, function(callback) {
var bar, spinner;
console.info("Destination file: " + options.output + "\n");
bar = new visuals.widgets.Progress('Downloading Device OS');
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)');
return resin.models.os.download(osParams, options.output, function(error) {
spinner.stop();
return callback(error);
}, function(state) {
if (state != null) {
return bar.update(state);
} else {
return spinner.start();
}
});
}
], function(error) {
if (error != null) {
return done(error);
}
console.info("\nFinished downloading " + options.output);
return done(null, options.output);
});
});
}
};
exports.install = {
signature: 'os install <image> [device]',
description: 'write an operating system image to a device',
help: 'Use this command to write an operating system image to a device.\n\nNote that this command requires admin privileges.\n\nIf `device` is omitted, you will be prompted to select a device interactively.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nYou can quiet the progress bar by passing the `--quiet` boolean option.\n\nExamples:\n\n $ resin os install rpi.iso /dev/disk2',
options: [commandOptions.yes],
permission: 'user',
action: function(params, options, done) {
return async.waterfall([
function(callback) {
return selfupdate.isUpdated(packageJSON, callback);
}, function(isUpdated, callback) {
if (isUpdated) {
return callback();
}
console.info('Resin CLI is outdated.\n\nIn order to avoid device compatibility issues, this command\nrequires that you have the Resin CLI updated.\n\nUpdating now...');
return capitano.run('update', _.unary(callback));
}, function(callback) {
if (params.device != null) {
return callback(null, params.device);
}
return visuals.patterns.selectDrive(function(error, device) {
if (error != null) {
return callback(error);
}
if (device == null) {
return callback(new Error('No removable devices available'));
}
return callback(null, device);
});
}, function(device, callback) {
var message;
params.device = device;
message = "This will completely erase " + params.device + ". Are you sure you want to continue?";
return visuals.patterns.confirm(options.yes, message, callback);
}, function(confirmed, callback) {
var bar;
if (!confirmed) {
return done();
}
bar = new visuals.widgets.Progress('Writing Device OS');
params.progress = _.bind(bar.update, bar);
return image.write(params, callback);
}
], function(error) {
var resinWritePath;
if (error == null) {
return done();
}
if (elevate.shouldElevate(error) && !options.fromScript) {
resinWritePath = "\"" + (path.join(__dirname, '..', '..', 'bin', 'resin-write')) + "\"";
return elevate.run("\"" + process.argv[0] + "\" " + resinWritePath + " \"" + params.image + "\" \"" + params.device + "\"");
} else {
return done(error);
}
});
}
};
}).call(this);

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'));
}
@ -64,6 +67,8 @@
capitano.command(actions.info.version);
capitano.command(actions.info.config);
capitano.command(actions.help.help);
capitano.command(actions.auth.login);
@ -78,8 +83,6 @@
capitano.command(actions.app.list);
capitano.command(actions.app.info);
capitano.command(actions.app.remove);
capitano.command(actions.app.restart);
@ -88,6 +91,8 @@
capitano.command(actions.app.init);
capitano.command(actions.app.info);
capitano.command(actions.device.list);
capitano.command(actions.device.supported);
@ -96,14 +101,14 @@
capitano.command(actions.device.init);
capitano.command(actions.device.await);
capitano.command(actions.device.info);
capitano.command(actions.device.remove);
capitano.command(actions.device.identify);
capitano.command(actions.device.await);
capitano.command(actions.drive.list);
capitano.command(actions.notes.set);
@ -128,10 +133,6 @@
capitano.command(actions.logs);
capitano.command(actions.os.download);
capitano.command(actions.os.install);
capitano.command(actions.examples.list);
capitano.command(actions.examples.clone);
@ -164,7 +165,7 @@
}, function(callback) {
var cli;
cli = capitano.parse(process.argv);
if (cli.global.quiet) {
if (cli.global.quiet || !process.stdout.isTTY) {
console.info = _.noop;
}
if (cli.global.project != null) {

View File

@ -177,6 +177,9 @@ Use this command to associate a project directory with a resin application.
This command adds a 'resin' git remote to the directory and runs git init if necessary.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin app associate MyApp

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' ], ->

View File

@ -44,13 +44,15 @@ exports.create =
return callback(new Error('You already have an application with that name!'))
return callback(null, options.type) if options.type?
resin.models.device.getSupportedDeviceTypes (error, deviceTypes) ->
return callback(error) if error?
visuals.widgets.select('Select a type', deviceTypes, callback)
visuals.patterns.selectDeviceType(callback)
(type, callback) ->
resin.models.application.create(params.name, type, callback)
options.type = type
resin.models.application.create(params.name, options.type, callback)
(applicationId, callback) ->
console.info("Application created: #{params.name} (#{options.type}, id #{applicationId})")
return callback()
], done)
@ -146,11 +148,15 @@ exports.associate =
This command adds a 'resin' git remote to the directory and runs git init if necessary.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin app associate MyApp
$ resin app associate MyApp --project my/app/directory
'''
options: [ commandOptions.yes ]
permission: 'user'
action: (params, options, done) ->
currentDirectory = process.cwd()
@ -158,6 +164,17 @@ exports.associate =
async.waterfall [
(callback) ->
resin.models.application.has(params.name, callback)
(hasApp, callback) ->
if not hasApp
return callback(new Error("Invalid application: #{params.name}"))
message = "Are you sure you want to associate #{currentDirectory} with #{params.name}?"
visuals.patterns.confirm(options.yes, message, callback)
(confirmed, callback) ->
return done() if not confirmed
vcs.initialize(currentDirectory, callback)
(callback) ->
@ -196,7 +213,12 @@ exports.init =
(callback) ->
currentDirectoryBasename = path.basename(currentDirectory)
visuals.widgets.ask('What is the name of your application?', currentDirectoryBasename, callback)
visuals.form.ask
label: 'What is the name of your application?'
name: 'application'
type: 'text'
value: currentDirectoryBasename
, callback
(applicationName, callback) ->

View File

@ -6,7 +6,7 @@ resin = require('resin-sdk')
settings = require('resin-settings-client')
visuals = require('resin-cli-visuals')
TOKEN_URL = url.resolve(settings.get('remoteUrl'), '/preferences')
TOKEN_URL = url.resolve(settings.get('dashboardUrl'), '/preferences')
exports.login =
signature: 'login [token]'
@ -44,10 +44,17 @@ exports.login =
Please visit #{TOKEN_URL} manually.
"""
visuals.widgets.ask('What\'s your token? (visible in the preferences page)', null, callback)
visuals.patterns.loginWithToken(callback)
(token, callback) ->
resin.auth.loginWithToken(token, done)
resin.auth.loginWithToken(token, callback)
(callback) ->
resin.auth.whoami(callback)
(username, callback) ->
console.info("Successfully logged in as: #{username}")
return callback()
], done)
@ -124,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) ->

View File

@ -16,6 +16,18 @@ exports.application = _.defaults
required: 'You have to specify an application'
, exports.optionalApplication
exports.optionalDevice =
signature: 'device'
parameter: 'device'
description: 'device name'
alias: 'd'
exports.booleanDevice =
signature: 'device'
description: 'device name'
boolean: true
alias: 'd'
exports.network =
signature: 'network'
parameter: 'network'

View File

@ -1,3 +1,4 @@
fse = require('fs-extra')
capitano = require('capitano')
_ = require('lodash-contrib')
path = require('path')
@ -5,13 +6,17 @@ async = require('async')
resin = require('resin-sdk')
visuals = require('resin-cli-visuals')
vcs = require('resin-vcs')
manager = require('resin-image-manager')
image = require('resin-image')
inject = require('resin-config-inject')
registerDevice = require('resin-register-device')
pine = require('resin-pine')
tmp = require('tmp')
# Cleanup the temporary files even when an uncaught exception occurs
tmp.setGracefulCleanup()
commandOptions = require('./command-options')
osAction = require('./os')
exports.list =
signature: 'devices'
@ -140,7 +145,12 @@ exports.rename =
(callback) ->
if not _.isEmpty(params.newName)
return callback(null, params.newName)
visuals.widgets.ask('How do you want to name this device?', null, callback)
visuals.form.ask
label: 'How do you want to name this device?'
name: 'device'
type: 'text'
, callback
(newName, callback) ->
resin.models.device.rename(params.name, newName, callback)
@ -217,9 +227,7 @@ exports.init =
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
You can quiet the progress bar by passing the `--quiet` boolean option.
You may have to unmount the device before attempting this operation.
You can quiet the progress bar and other logging information by passing the `--quiet` boolean option.
You need to configure the network type and other settings:
@ -246,8 +254,14 @@ exports.init =
commandOptions.wifiKey
]
permission: 'user'
root: true
action: (params, options, done) ->
networkOptions =
network: options.network
wifiSsid: options.ssid
wifiKey: options.key
async.waterfall([
(callback) ->
@ -255,7 +269,13 @@ exports.init =
vcs.getApplicationName(process.cwd(), callback)
(applicationName, callback) ->
params.name = applicationName
options.application = applicationName
resin.models.application.has(options.application, callback)
(hasApplication, callback) ->
if not hasApplication
return callback(new Error("Invalid application: #{options.application}"))
return callback(null, params.device) if params.device?
visuals.patterns.selectDrive(callback)
@ -266,27 +286,82 @@ exports.init =
(confirmed, callback) ->
return done() if not confirmed
options.yes = confirmed
tmp.file
prefix: 'resin-image-'
postfix: '.img'
, callback
(tmpPath, tmpFd, cleanupCallback, callback) ->
options.output = tmpPath
# TODO: Figure out how to make use of capitano.run()
# here given the complexity of converting network
# params object to string options
osAction.download.action params, options, (error, outputFile) ->
return callback() if networkOptions.network?
visuals.patterns.selectNetworkParameters (error, parameters) ->
return callback(error) if error?
return callback(null, outputFile, cleanupCallback)
(outputFile, cleanupCallback, callback) ->
capitano.run "os install #{outputFile} #{params.device}", (error) ->
return callback(error) if error?
cleanupCallback()
_.extend(networkOptions, parameters)
return callback()
(callback) ->
console.info("Checking application: #{options.application}")
resin.models.application.get(options.application, callback)
(application, callback) ->
async.parallel
manifest: (callback) ->
console.info('Getting device manifest for the application')
resin.models.device.getManifestBySlug(application.device_type, callback)
config: (callback) ->
console.info('Fetching application configuration')
resin.models.application.getConfiguration(options.application, networkOptions, callback)
, callback
(results, callback) ->
console.info('Associating the device')
registerDevice.register pine, results.config, (error, device) ->
return callback(error) if error?
# Associate a device
results.config.deviceId = device.id
results.config.uuid = device.uuid
params.uuid = results.config.uuid
return callback(null, results)
(results, callback) ->
console.info('Configuring device operating system image')
if process.env.DEBUG
console.log(results.config)
bar = new visuals.widgets.Progress('Downloading Device OS')
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)')
manager.configure results.manifest, results.config, (error, imagePath, removeCallback) ->
spinner.stop()
return callback(error, imagePath, removeCallback)
, (state) ->
if state?
bar.update(state)
else
spinner.start()
(configuredImagePath, removeCallback, callback) ->
console.info('Attempting to write operating system image to drive')
bar = new visuals.widgets.Progress('Writing Device OS')
image.write
device: params.device
image: configuredImagePath
progress: _.bind(bar.update, bar)
, (error) ->
return callback(error) if error?
return callback(null, configuredImagePath, removeCallback)
(temporalImagePath, removeCallback, callback) ->
console.info('Image written successfully')
removeCallback(callback)
(callback) ->
resin.models.device.getByUUID(params.uuid, callback)
(device, callback) ->
console.info("Device created: #{device.name}")
return callback(null, device.name)
], done)

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

@ -30,34 +30,33 @@ exports.list =
console.log visuals.widgets.table.horizontal examplesData, [
'id'
'name'
'display_name'
'repository'
'author'
]
exports.info =
signature: 'example <id>'
signature: 'example <name>'
description: 'list a single example application'
help: '''
Use this command to show information of a single example application
Example:
$ resin example 3
$ resin example cimon
'''
permission: 'user'
action: (params, options, done) ->
id = params.id - 1
example = examplesData[id]
example = _.findWhere(examplesData, name: params.name)
if not example?
return done(new Error("Unknown example: #{id}"))
return done(new Error("Unknown example: #{params.name}"))
example.id = id
example.author ?= 'Unknown'
console.log visuals.widgets.table.vertical example, [
'id'
'name'
'display_name'
'description'
'author'
@ -67,7 +66,7 @@ exports.info =
return done()
exports.clone =
signature: 'example clone <id>'
signature: 'example clone <name>'
description: 'clone an example application'
help: '''
Use this command to clone an example application to the current directory
@ -77,14 +76,14 @@ exports.clone =
Example:
$ resin example clone 3
$ resin example clone cimon
'''
permission: 'user'
action: (params, options, done) ->
example = examplesData[params.id - 1]
example = _.findWhere(examplesData, name: params.name)
if not example?
return done(new Error("Unknown example: #{id}"))
return done(new Error("Unknown example: #{params.name}"))
currentDirectory = process.cwd()
destination = path.join(currentDirectory, example.name)

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,3 +1,4 @@
settings = require('resin-settings-client')
packageJSON = require('../../package.json')
exports.version =
@ -9,3 +10,16 @@ exports.version =
action: (params, options, done) ->
console.log(packageJSON.version)
return done()
exports.config =
signature: 'config'
description: 'see your current configuration'
help: '''
See your current Resin CLI configuration.
Configuration lives in $HOME/.resin/config.
'''
action: (params, options, done) ->
for key, value of settings.get()
console.log("#{key}: #{value}")
return done()

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

@ -1,171 +0,0 @@
capitano = require('capitano')
_ = require('lodash-contrib')
os = require('os')
async = require('async')
path = require('path')
mkdirp = require('mkdirp')
resin = require('resin-sdk')
image = require('resin-image')
visuals = require('resin-cli-visuals')
selfupdate = require('selfupdate')
commandOptions = require('./command-options')
packageJSON = require('../../package.json')
elevate = require('../elevate')
exports.download =
signature: 'os download <name>'
description: 'download device OS'
help: '''
Use this command to download the device OS configured to a specific network.
Ethernet:
You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".
Wifi:
You can setup the device OS to use wifi by setting the `--network` option to "wifi".
If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.
Alternatively, you can omit all kind of network configuration options to configure interactively.
You have to specify an output location with the `--output` option.
Examples:
$ resin os download MyApp --output ~/MyResinOS.zip
$ resin os download MyApp --network ethernet --output ~/MyResinOS.zip
$ resin os download MyApp --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip
$ resin os download MyApp --network ethernet --output ~/MyResinOS.zip
'''
options: [
commandOptions.network
commandOptions.wifiSsid
commandOptions.wifiKey
{
signature: 'output'
parameter: 'output'
description: 'output file'
alias: 'o'
required: 'You need to specify an output file'
}
]
permission: 'user'
action: (params, options, done) ->
resin.models.application.get params.name, (error, application) ->
return done(error) if error?
osParams =
network: options.network
wifiSsid: options.ssid
wifiKey: options.key
appId: application.id
async.waterfall [
(callback) ->
return callback() if osParams.network?
visuals.patterns.selectNetworkParameters (error, parameters) ->
return callback(error) if error?
_.extend(osParams, parameters)
return callback()
(callback) ->
# We need to ensure this directory exists
mkdirp(path.dirname(options.output), _.unary(callback))
(callback) ->
console.info("Destination file: #{options.output}\n")
bar = new visuals.widgets.Progress('Downloading Device OS')
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)')
resin.models.os.download osParams, options.output, (error) ->
spinner.stop()
return callback(error)
, (state) ->
if state?
bar.update(state)
else
spinner.start()
], (error) ->
return done(error) if error?
console.info("\nFinished downloading #{options.output}")
return done(null, options.output)
exports.install =
signature: 'os install <image> [device]'
description: 'write an operating system image to a device'
help: '''
Use this command to write an operating system image to a device.
Note that this command requires admin privileges.
If `device` is omitted, you will be prompted to select a device interactively.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
You can quiet the progress bar by passing the `--quiet` boolean option.
Examples:
$ resin os install rpi.iso /dev/disk2
'''
options: [ commandOptions.yes ]
permission: 'user'
action: (params, options, done) ->
async.waterfall [
(callback) ->
selfupdate.isUpdated(packageJSON, callback)
(isUpdated, callback) ->
return callback() if isUpdated
console.info '''
Resin CLI is outdated.
In order to avoid device compatibility issues, this command
requires that you have the Resin CLI updated.
Updating now...
'''
capitano.run('update', _.unary(callback))
(callback) ->
return callback(null, params.device) if params.device?
# TODO: See if we can reuse the drives action somehow here
visuals.patterns.selectDrive (error, device) ->
return callback(error) if error?
if not device?
return callback(new Error('No removable devices available'))
return callback(null, device)
(device, callback) ->
params.device = device
message = "This will completely erase #{params.device}. Are you sure you want to continue?"
visuals.patterns.confirm(options.yes, message, callback)
(confirmed, callback) ->
return done() if not confirmed
bar = new visuals.widgets.Progress('Writing Device OS')
params.progress = _.bind(bar.update, bar)
image.write(params, callback)
], (error) ->
return done() if not error?
if elevate.shouldElevate(error) and not options.fromScript
# Need to escape every path to avoid errors
resinWritePath = "\"#{path.join(__dirname, '..', '..', 'bin', 'resin-write')}\""
elevate.run("\"#{process.argv[0]}\" #{resinWritePath} \"#{params.image}\" \"#{params.device}\"")
else
return done(error)

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()
@ -47,6 +48,7 @@ capitano.globalOption
# ---------- Info Module ----------
capitano.command(actions.info.version)
capitano.command(actions.info.config)
# ---------- Help Module ----------
capitano.command(actions.help.help)
@ -60,21 +62,21 @@ capitano.command(actions.auth.whoami)
# ---------- App Module ----------
capitano.command(actions.app.create)
capitano.command(actions.app.list)
capitano.command(actions.app.info)
capitano.command(actions.app.remove)
capitano.command(actions.app.restart)
capitano.command(actions.app.associate)
capitano.command(actions.app.init)
capitano.command(actions.app.info)
# ---------- Device Module ----------
capitano.command(actions.device.list)
capitano.command(actions.device.supported)
capitano.command(actions.device.rename)
capitano.command(actions.device.init)
capitano.command(actions.device.await)
capitano.command(actions.device.info)
capitano.command(actions.device.remove)
capitano.command(actions.device.identify)
capitano.command(actions.device.await)
# ---------- Drive Module ----------
capitano.command(actions.drive.list)
@ -100,10 +102,6 @@ capitano.command(actions.env.remove)
# ---------- Logs Module ----------
capitano.command(actions.logs)
# ---------- OS Module ----------
capitano.command(actions.os.download)
capitano.command(actions.os.install)
# ---------- Examples Module ----------
capitano.command(actions.examples.list)
capitano.command(actions.examples.clone)
@ -135,7 +133,7 @@ async.waterfall([
(callback) ->
cli = capitano.parse(process.argv)
if cli.global.quiet
if cli.global.quiet or not process.stdout.isTTY
console.info = _.noop
if cli.global.project?

View File

@ -1,6 +1,6 @@
{
"name": "resin-cli",
"version": "0.10.7",
"version": "0.11.1",
"description": "Git Push to your devices",
"main": "./build/actions/index.js",
"homepage": "https://github.com/resin-io/resin-cli",
@ -42,7 +42,6 @@
"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"
@ -52,17 +51,22 @@
"capitano": "~1.6.0",
"coffee-script": "~1.8.0",
"conf.js": "^0.1.1",
"drivelist": "^1.2.1",
"drivelist": "^1.2.2",
"fs-extra": "^0.18.3",
"lodash": "~2.4.1",
"lodash-contrib": "~241.4.14",
"mkdirp": "~0.5.0",
"nplugm": "^2.2.0",
"npm": "^2.6.1",
"open": "0.0.5",
"resin-cli-visuals": "^0.1.0",
"resin-image": "^1.1.2",
"resin-sdk": "^1.4.3",
"resin-settings-client": "^1.0.0",
"resin-cli-visuals": "^0.2.0",
"resin-config-inject": "^2.0.0",
"resin-image": "^1.1.3",
"resin-image-manager": "^1.1.0",
"resin-pine": "^1.1.1",
"resin-register-device": "^1.0.1",
"resin-sdk": "^1.7.4",
"resin-settings-client": "^1.2.0",
"resin-vcs": "^1.2.0",
"selfupdate": "^1.1.0",
"tmp": "^0.0.25",