From ed83514a2f4875b79601e9933035d9b8d211f2fc Mon Sep 17 00:00:00 2001 From: Eugene Mirotin Date: Fri, 9 Jun 2017 12:32:28 +0300 Subject: [PATCH] allow passing --drive to resin device init --- CHANGELOG.md | 1 + build/actions/device.js | 10 +++++++++- build/actions/os.js | 4 +--- build/utils/patterns.js | 5 ++++- lib/actions/device.coffee | 10 ++++++++++ lib/actions/os.coffee | 7 +++++-- lib/utils/patterns.coffee | 6 ++++-- 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 258bd6c8..2ad42dd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Show a clear message immediately as the deploy starts, if we're deploying an image. - Allow OS version selection when doing `resin device init` - Actually tolerate the `--yes` param to `resin device init` +- Allows passing `--drive` to `resin device init` ### Fixed diff --git a/build/actions/device.js b/build/actions/device.js index cb451000..6b35ffe0 100644 --- a/build/actions/device.js +++ b/build/actions/device.js @@ -271,7 +271,12 @@ exports.init = { }, _.assign({}, commandOptions.osVersion, { signature: 'os-version', parameter: 'os-version' - }) + }), { + signature: 'drive', + description: 'the drive to write the image to, like /dev/sdb. Careful with this as you can erase your hard drive.', + parameter: 'drive', + alias: 'd' + } ], permission: 'user', action: function(params, options, done) { @@ -314,6 +319,9 @@ exports.init = { if (options.yes) { osInitCommand += ' --yes'; } + if (options.drive) { + osInitCommand += " --drive " + options.drive; + } return capitanoRunAsync(osInitCommand); })["catch"](function(error) { return resin.models.device.remove(device.uuid)["finally"](function() { diff --git a/build/actions/os.js b/build/actions/os.js index 21e3ddcb..541232e2 100644 --- a/build/actions/os.js +++ b/build/actions/os.js @@ -215,12 +215,10 @@ exports.initialize = { } }); }).tap(function(answers) { - var message; if (answers.drive == null) { return; } - message = "This will erase " + answers.drive + ". Are you sure?"; - return patterns.confirm(options.yes, message)["return"](answers.drive).then(umountAsync); + return patterns.confirm(options.yes, "This will erase " + answers.drive + ". Are you sure?", "Going to erase " + answers.drive + ".")["return"](answers.drive).then(umountAsync); }).tap(function(answers) { return helpers.sudo(['internal', 'osinit', params.image, options.type, JSON.stringify(answers)]); }).then(function(answers) { diff --git a/build/utils/patterns.js b/build/utils/patterns.js index 34396d04..697293ac 100644 --- a/build/utils/patterns.js +++ b/build/utils/patterns.js @@ -100,9 +100,12 @@ exports.selectDeviceType = function() { }); }; -exports.confirm = function(yesOption, message) { +exports.confirm = function(yesOption, message, yesMessage) { return Promise["try"](function() { if (yesOption) { + if (yesMessage) { + console.log(yesMessage); + } return true; } return form.ask({ diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee index 8e1fbade..5cda9565 100644 --- a/lib/actions/device.coffee +++ b/lib/actions/device.coffee @@ -372,6 +372,14 @@ exports.init = alias: 'v' } _.assign({}, commandOptions.osVersion, { signature: 'os-version', parameter: 'os-version' }) + { + signature: 'drive' + description: 'the drive to write the image to, like /dev/sdb. + Careful with this as you can erase your hard drive. + ' + parameter: 'drive' + alias: 'd' + } ] permission: 'user' action: (params, options, done) -> @@ -411,6 +419,8 @@ exports.init = osInitCommand = "os initialize '#{tempPath}' --type #{application.device_type}" if options.yes osInitCommand += ' --yes' + if options.drive + osInitCommand += " --drive #{options.drive}" capitanoRunAsync(osInitCommand) # Make sure the device resource is removed if there is an # error when configuring or initializing a device image diff --git a/lib/actions/os.coffee b/lib/actions/os.coffee index 2f657c13..5fe33667 100644 --- a/lib/actions/os.coffee +++ b/lib/actions/os.coffee @@ -241,8 +241,11 @@ exports.initialize = drive: options.drive .tap (answers) -> return if not answers.drive? - message = "This will erase #{answers.drive}. Are you sure?" - patterns.confirm(options.yes, message) + patterns.confirm( + options.yes + "This will erase #{answers.drive}. Are you sure?" + "Going to erase #{answers.drive}." + ) .return(answers.drive) .then(umountAsync) .tap (answers) -> diff --git a/lib/utils/patterns.coffee b/lib/utils/patterns.coffee index 512866a8..baab81a0 100644 --- a/lib/utils/patterns.coffee +++ b/lib/utils/patterns.coffee @@ -76,9 +76,11 @@ exports.selectDeviceType = -> type: 'list' choices: deviceTypes -exports.confirm = (yesOption, message) -> +exports.confirm = (yesOption, message, yesMessage) -> Promise.try -> - return true if yesOption + if yesOption + console.log(yesMessage) if yesMessage + return true return form.ask message: message type: 'confirm'