From 71ee0a6cf7e3b766c1ef0716766a205b4ee1db49 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 15 Oct 2015 08:14:35 -0400 Subject: [PATCH] Support drive option in os initialize This allows the user to bypass the drive selection dialog. This option can be used along with `--yes` to make the command completely non-interactive. For example: $ resin os initialize rpi.img 'raspberry-pi' --drive /dev/disk2 --yes --- build/actions/os.js | 17 +++++++++++++++-- lib/actions/os.coffee | 15 +++++++++++++-- package.json | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/build/actions/os.js b/build/actions/os.js index 26b5f796..9f19ccbb 100644 --- a/build/actions/os.js +++ b/build/actions/os.js @@ -104,14 +104,27 @@ description: 'initialize an os image', help: 'Use this command to initialize a previously configured operating system image.\n\nExamples:\n\n $ resin os initialize ../path/rpi.img \'raspberry-pi\'', permission: 'user', - options: [commandOptions.yes], + options: [ + commandOptions.yes, { + signature: 'drive', + description: 'drive', + parameter: 'drive', + alias: 'd' + } + ], root: true, action: function(params, options, done) { console.info('Initializing device'); return resin.models.device.getManifestBySlug(params.type).then(function(manifest) { var ref; return (ref = manifest.initialization) != null ? ref.options : void 0; - }).then(form.run).tap(function(answers) { + }).then(function(questions) { + return form.run(questions, { + override: { + drive: options.drive + } + }); + }).tap(function(answers) { var message; if (answers.drive == null) { return; diff --git a/lib/actions/os.coffee b/lib/actions/os.coffee index c6c59804..42632733 100644 --- a/lib/actions/os.coffee +++ b/lib/actions/os.coffee @@ -106,14 +106,25 @@ exports.initialize = $ resin os initialize ../path/rpi.img 'raspberry-pi' ''' permission: 'user' - options: [ commandOptions.yes ] + options: [ + commandOptions.yes + { + signature: 'drive' + description: 'drive' + parameter: 'drive' + alias: 'd' + } + ] root: true action: (params, options, done) -> console.info('Initializing device') resin.models.device.getManifestBySlug(params.type) .then (manifest) -> return manifest.initialization?.options - .then(form.run) + .then (questions) -> + return form.run questions, + override: + drive: options.drive .tap (answers) -> return if not answers.drive? message = "This will erase #{answers.drive}. Are you sure?" diff --git a/package.json b/package.json index 08717b7c..3e8c7523 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "open": "0.0.5", "resin-cli-errors": "^1.0.0", "resin-cli-events": "^1.0.2", - "resin-cli-form": "^1.2.1", + "resin-cli-form": "^1.3.0", "resin-cli-visuals": "^1.2.2", "resin-config-inject": "^2.0.0", "resin-device-config": "^1.0.0",