From 1cfe64e4a7529fc1c2422618efe9678f4df3cff1 Mon Sep 17 00:00:00 2001 From: Eugene Mirotin Date: Thu, 8 Jun 2017 22:58:37 +0300 Subject: [PATCH] choose version during device init, and list versions with resin os versions --- CHANGELOG.md | 1 + build/actions/command-options.js | 6 ++++++ build/actions/device.js | 22 ++++++++++++--------- build/actions/os.js | 23 +++++++++++++++++----- build/app.js | 2 ++ lib/actions/command-options.coffee | 11 +++++++++++ lib/actions/device.coffee | 9 ++++----- lib/actions/os.coffee | 31 +++++++++++++++++++----------- lib/app.coffee | 1 + 9 files changed, 76 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 562c6b13..cd83d024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Added ability to run an emulated build silently with `resin build` - Gzip images when uploading in `resin deploy` - Show a clear message immediately as the deploy starts, if we're deploying an image. +- Allow OS version selection when doing `resin device init` ### Fixed diff --git a/build/actions/command-options.js b/build/actions/command-options.js index 8d971f56..ecd7df59 100644 --- a/build/actions/command-options.js +++ b/build/actions/command-options.js @@ -51,6 +51,12 @@ exports.booleanDevice = { alias: 'd' }; +exports.osVersion = { + 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),\nor 'menu' (will show the interactive menu)", + parameter: 'version' +}; + exports.network = { signature: 'network', parameter: 'network', diff --git a/build/actions/device.js b/build/actions/device.js index 94547f4d..1e478a55 100644 --- a/build/actions/device.js +++ b/build/actions/device.js @@ -15,10 +15,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -var commandOptions; +var _, commandOptions; commandOptions = require('./command-options'); +_ = require('lodash'); + exports.list = { signature: 'devices', description: 'list all devices', @@ -27,9 +29,8 @@ exports.list = { permission: 'user', primary: true, action: function(params, options, done) { - var Promise, _, resin, visuals; + var Promise, resin, visuals; Promise = require('bluebird'); - _ = require('lodash'); resin = require('resin-sdk-preconfigured'); visuals = require('resin-cli-visuals'); return Promise["try"](function() { @@ -219,9 +220,8 @@ exports.rename = { 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 7cf02a6\n $ resin device rename 7cf02a6 MyPi', permission: 'user', action: function(params, options, done) { - var Promise, _, form, resin; + var Promise, form, resin; Promise = require('bluebird'); - _ = require('lodash'); resin = require('resin-sdk-preconfigured'); form = require('resin-cli-form'); return Promise["try"](function() { @@ -243,9 +243,8 @@ exports.move = { permission: 'user', options: [commandOptions.optionalApplication], action: function(params, options, done) { - var _, patterns, resin; + var patterns, resin; resin = require('resin-sdk-preconfigured'); - _ = require('lodash'); patterns = require('../utils/patterns'); return resin.models.device.get(params.uuid).then(function(device) { return options.application || patterns.selectApplication(function(application) { @@ -269,7 +268,10 @@ exports.init = { description: 'enable advanced configuration', boolean: true, alias: 'v' - } + }, _.assign({}, commandOptions.osVersion, { + signature: 'os-version', + parameter: 'os-version' + }) ], permission: 'user', action: function(params, options, done) { @@ -292,7 +294,9 @@ exports.init = { var download; download = function() { return tmpNameAsync().then(function(tempPath) { - return capitanoRunAsync("os download " + application.device_type + " --output '" + tempPath + "' --version default"); + var osVersion; + osVersion = options['os-version'] || 'default'; + return capitanoRunAsync("os download " + application.device_type + " --output '" + tempPath + "' --version " + osVersion); }).disposer(function(tempPath) { return rimraf(tempPath); }); diff --git a/build/actions/os.js b/build/actions/os.js index 58a00c3b..21e3ddcb 100644 --- a/build/actions/os.js +++ b/build/actions/os.js @@ -53,6 +53,23 @@ resolveVersion = function(deviceType, version) { }); }; +exports.versions = { + signature: 'os versions ', + description: 'show the available resinOS versions for the given device type', + help: 'Use this command to show the available resinOS versions for a certain device type.\nCheck available types with `resin devices supported`\n\nExample:\n\n $ resin os versions raspberrypi3', + action: function(params, options, done) { + var resin; + resin = require('resin-sdk-preconfigured'); + return resin.models.os.getSupportedVersions(params.type).then(function(arg) { + var recommended, versions; + versions = arg.versions, recommended = arg.recommended; + return versions.forEach(function(v) { + return console.log(formatVersion(v, v === recommended)); + }); + }); + } +}; + exports.download = { signature: 'os download ', description: 'download an unconfigured os image', @@ -65,11 +82,7 @@ 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),\nor 'menu' (will show the interactive menu)", - parameter: 'version' - } + }, commandOptions.osVersion ], action: function(params, options, done) { var Promise, displayVersion, fs, manager, rindle, unzip, visuals; diff --git a/build/app.js b/build/app.js index 615ad146..73564169 100644 --- a/build/app.js +++ b/build/app.js @@ -166,6 +166,8 @@ capitano.command(actions.env.rename); capitano.command(actions.env.remove); +capitano.command(actions.os.versions); + capitano.command(actions.os.download); capitano.command(actions.os.configure); diff --git a/lib/actions/command-options.coffee b/lib/actions/command-options.coffee index 80ecead3..2ea912a1 100644 --- a/lib/actions/command-options.coffee +++ b/lib/actions/command-options.coffee @@ -44,6 +44,17 @@ exports.booleanDevice = boolean: true alias: 'd' +exports.osVersion = + 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), + or 'menu' (will show the interactive menu) + """ + parameter: 'version' + exports.network = signature: 'network' parameter: 'network' diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee index 0bfd61a3..b088b91f 100644 --- a/lib/actions/device.coffee +++ b/lib/actions/device.coffee @@ -15,6 +15,7 @@ limitations under the License. ### commandOptions = require('./command-options') +_ = require('lodash') exports.list = signature: 'devices' @@ -36,7 +37,6 @@ exports.list = primary: true action: (params, options, done) -> Promise = require('bluebird') - _ = require('lodash') resin = require('resin-sdk-preconfigured') visuals = require('resin-cli-visuals') @@ -304,7 +304,6 @@ exports.rename = permission: 'user' action: (params, options, done) -> Promise = require('bluebird') - _ = require('lodash') resin = require('resin-sdk-preconfigured') form = require('resin-cli-form') @@ -335,7 +334,6 @@ exports.move = options: [ commandOptions.optionalApplication ] action: (params, options, done) -> resin = require('resin-sdk-preconfigured') - _ = require('lodash') patterns = require('../utils/patterns') resin.models.device.get(params.uuid).then (device) -> @@ -373,6 +371,7 @@ exports.init = boolean: true alias: 'v' } + _.assign({}, commandOptions.osVersion, { signature: 'os-version', parameter: 'os-version' }) ] permission: 'user' action: (params, options, done) -> @@ -395,8 +394,8 @@ exports.init = download = -> tmpNameAsync().then (tempPath) -> - # TODO: allow version selection - capitanoRunAsync("os download #{application.device_type} --output '#{tempPath}' --version default") + osVersion = options['os-version'] or 'default' + capitanoRunAsync("os download #{application.device_type} --output '#{tempPath}' --version #{osVersion}") .disposer (tempPath) -> return rimraf(tempPath) diff --git a/lib/actions/os.coffee b/lib/actions/os.coffee index 8deffc8c..2f657c13 100644 --- a/lib/actions/os.coffee +++ b/lib/actions/os.coffee @@ -41,6 +41,25 @@ resolveVersion = (deviceType, version) -> choices: choices default: recommended +exports.versions = + signature: 'os versions ' + description: 'show the available resinOS versions for the given device type' + help: ''' + Use this command to show the available resinOS versions for a certain device type. + Check available types with `resin devices supported` + + Example: + + $ resin os versions raspberrypi3 + ''' + action: (params, options, done) -> + resin = require('resin-sdk-preconfigured') + + resin.models.os.getSupportedVersions(params.type) + .then ({ versions, recommended }) -> + versions.forEach (v) -> + console.log(formatVersion(v, v is recommended)) + exports.download = signature: 'os download ' description: 'download an unconfigured os image' @@ -73,17 +92,7 @@ exports.download = 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), - or 'menu' (will show the interactive menu) - """ - parameter: 'version' - } + commandOptions.osVersion ] action: (params, options, done) -> Promise = require('bluebird') diff --git a/lib/app.coffee b/lib/app.coffee index 2bff2741..4de49f2c 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -135,6 +135,7 @@ capitano.command(actions.env.rename) capitano.command(actions.env.remove) # ---------- OS Module ---------- +capitano.command(actions.os.versions) capitano.command(actions.os.download) capitano.command(actions.os.configure) capitano.command(actions.os.initialize)