balena-cli/build/actions/os.js
Juan Cruz Viotti f6d8f12ba2 Implement os download command
This command download an unconfigured image to both the cache and to the
specified location by the `--output` option.
2015-09-29 13:03:14 -04:00

51 lines
1.6 KiB
JavaScript

(function() {
var fs, helpers, manager, visuals;
fs = require('fs');
manager = require('resin-image-manager');
visuals = require('resin-cli-visuals');
helpers = require('../utils/helpers');
exports.download = {
signature: 'os download <type>',
description: 'download an unconfigured os image',
help: 'Use this command to download an unconfigured os image for a certain device type.\n\nExamples:\n\n $ resin os download parallella -o ../foo/bar/parallella.img',
permission: 'user',
options: [
{
signature: 'output',
description: 'output path',
parameter: 'output',
alias: 'o',
required: 'You have to specify an output location'
}
],
action: function(params, options, done) {
console.info("Getting device operating system for " + params.type);
return manager.get(params.type).then(function(stream) {
var bar, output, spinner;
bar = new visuals.Progress('Downloading Device OS');
spinner = new visuals.Spinner('Downloading Device OS (size unknown)');
stream.on('progress', function(state) {
if (state != null) {
return bar.update(state);
} else {
return spinner.start();
}
});
stream.on('end', function() {
return spinner.stop();
});
output = fs.createWriteStream(options.output);
return helpers.waitStream(stream.pipe(output))["return"](options.output);
}).tap(function(output) {
return console.log("The image was downloaded to " + output);
}).nodeify(done);
}
};
}).call(this);