diff --git a/build/actions/os.js b/build/actions/os.js index c138e353..d0e40718 100644 --- a/build/actions/os.js +++ b/build/actions/os.js @@ -22,7 +22,7 @@ commandOptions = require('./command-options'); exports.download = { signature: 'os download ', 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', + help: 'Use this command to download an unconfigured os image for a certain device type.\nIf version is not specified the newest stable (non-pre-release) version of OS\nis downloaded if available, or the newest version otherwise (if all existing\nversions for the given device type are pre-release).\n\nExamples:\n\n $ resin os download raspberrypi3 -o ../foo/bar/raspberry-pi.img\n $ resin os download raspberrypi3 -o ../foo/bar/raspberry-pi.img --version 1.24.1\n $ resin os download raspberrypi3 -o ../foo/bar/raspberry-pi.img --version ^1.20.0\n $ resin os download raspberrypi3 -o ../foo/bar/raspberry-pi.img --version latest\n $ resin os download raspberrypi3 -o ../foo/bar/raspberry-pi.img --version default', permission: 'user', options: [ { @@ -31,20 +31,32 @@ exports.download = { parameter: 'output', alias: 'o', required: 'You have to specify the output location' + }, { + signature: 'version', + description: "exact version number, or a valid semver range,\nor 'latest' (includes pre-releases),\nor 'default' (excludes pre-releases if at least one stable version is available),\nor 'recommended' (excludes pre-releases, will fail if only pre-release versions are available)", + parameter: 'version' } ], action: function(params, options, done) { - var fs, manager, rindle, unzip, visuals; + var displayVersion, fs, manager, rindle, unzip, version, visuals; unzip = require('unzip2'); fs = require('fs'); rindle = require('rindle'); manager = require('resin-image-manager'); visuals = require('resin-cli-visuals'); console.info("Getting device operating system for " + params.type); - return manager.get(params.type, 'default').then(function(stream) { + version = options.version; + if (!version) { + version = 'default'; + displayVersion = ''; + console.warn('OS version is not specified, using the default version: the newest stable (non-pre-release) version if available, or the newest version otherwise (if all existing versions for the given device type are pre-release)'); + } else { + displayVersion = " " + version; + } + return manager.get(params.type, version).then(function(stream) { var bar, output, spinner; - bar = new visuals.Progress('Downloading Device OS'); - spinner = new visuals.Spinner('Downloading Device OS (size unknown)'); + bar = new visuals.Progress("Downloading Device OS" + displayVersion); + spinner = new visuals.Spinner("Downloading Device OS" + displayVersion + " (size unknown)"); stream.on('progress', function(state) { if (state != null) { return bar.update(state); diff --git a/lib/actions/os.coffee b/lib/actions/os.coffee index dd059eb9..53130ef5 100644 --- a/lib/actions/os.coffee +++ b/lib/actions/os.coffee @@ -21,18 +21,37 @@ exports.download = description: 'download an unconfigured os image' help: ''' Use this command to download an unconfigured os image for a certain device type. + If version is not specified the newest stable (non-pre-release) version of OS + is downloaded if available, or the newest version otherwise (if all existing + versions for the given device type are pre-release). Examples: - $ resin os download parallella -o ../foo/bar/parallella.img + $ resin os download raspberrypi3 -o ../foo/bar/raspberry-pi.img + $ resin os download raspberrypi3 -o ../foo/bar/raspberry-pi.img --version 1.24.1 + $ resin os download raspberrypi3 -o ../foo/bar/raspberry-pi.img --version ^1.20.0 + $ resin os download raspberrypi3 -o ../foo/bar/raspberry-pi.img --version latest + $ resin os download raspberrypi3 -o ../foo/bar/raspberry-pi.img --version default ''' permission: 'user' options: [ - signature: 'output' - description: 'output path' - parameter: 'output' - alias: 'o' - required: 'You have to specify the output location' + { + signature: 'output' + description: 'output path' + parameter: 'output' + alias: 'o' + required: 'You have to specify the output location' + } + { + signature: 'version' + description: """ + exact version number, or a valid semver range, + or 'latest' (includes pre-releases), + or 'default' (excludes pre-releases if at least one stable version is available), + or 'recommended' (excludes pre-releases, will fail if only pre-release versions are available) + """ + parameter: 'version' + } ] action: (params, options, done) -> unzip = require('unzip2') @@ -43,9 +62,20 @@ exports.download = console.info("Getting device operating system for #{params.type}") - manager.get(params.type, 'default').then (stream) -> - bar = new visuals.Progress('Downloading Device OS') - spinner = new visuals.Spinner('Downloading Device OS (size unknown)') + version = options.version + if not version + version = 'default' + displayVersion = '' + console.warn('OS version is not specified, using the default version: + the newest stable (non-pre-release) version if available, + or the newest version otherwise (if all existing + versions for the given device type are pre-release)') + else + displayVersion = " #{version}" + + manager.get(params.type, version).then (stream) -> + bar = new visuals.Progress("Downloading Device OS#{displayVersion}") + spinner = new visuals.Spinner("Downloading Device OS#{displayVersion} (size unknown)") stream.on 'progress', (state) -> if state?