From f64676ab98b8b5b8da86a71ce5b284a16e6a8504 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 11 Nov 2015 10:38:45 -0400 Subject: [PATCH] Implement config reconfigure command This command allows the user to reconfigure an already provisioned device. Fixes: https://github.com/resin-io/resin-cli/issues/102 --- build/actions/config.js | 49 +++++++++++++++++++++++++++++++++++- build/app.js | 2 ++ doc/cli.markdown | 25 ++++++++++++++++++ lib/actions/config.coffee | 53 +++++++++++++++++++++++++++++++++++++++ lib/app.coffee | 1 + 5 files changed, 129 insertions(+), 1 deletion(-) diff --git a/build/actions/config.js b/build/actions/config.js index 1dc2857e..3ad13b9a 100644 --- a/build/actions/config.js +++ b/build/actions/config.js @@ -1,10 +1,12 @@ (function() { - var Promise, _, config, prettyjson, umount, visuals; + var Promise, _, capitano, config, prettyjson, umount, visuals; _ = require('lodash'); Promise = require('bluebird'); + capitano = Promise.promisifyAll(require('capitano')); + umount = Promise.promisifyAll(require('umount')); visuals = require('resin-cli-visuals'); @@ -83,4 +85,49 @@ } }; + exports.reconfigure = { + signature: 'config reconfigure', + description: 'reconfigure a provisioned device', + help: 'Use this command to reconfigure a provisioned device\n\nExamples:\n\n $ resin config reconfigure --type raspberry-pi\n $ resin config reconfigure --type raspberry-pi --advanced\n $ resin config reconfigure --type raspberry-pi --drive /dev/disk2', + options: [ + { + signature: 'type', + description: 'device type', + parameter: 'type', + alias: 't', + required: 'You have to specify a device type' + }, { + signature: 'drive', + description: 'drive', + parameter: 'drive', + alias: 'd' + }, { + signature: 'advanced', + description: 'show advanced commands', + boolean: true, + alias: 'v' + } + ], + permission: 'user', + root: true, + action: function(params, options, done) { + return Promise["try"](function() { + return options.drive || visuals.drive('Select the device drive'); + }).tap(umount.umountAsync).then(function(drive) { + return config.read(drive, options.type).get('uuid').tap(function() { + return umount.umountAsync(drive); + }).then(function(uuid) { + var configureCommand; + configureCommand = "os configure " + drive + " " + uuid; + if (options.advanced) { + configureCommand += ' --advanced'; + } + return capitano.runAsync(configureCommand); + }); + }).then(function() { + return console.info('Done'); + }).nodeify(done); + } + }; + }).call(this); diff --git a/build/app.js b/build/app.js index 9c0e610c..6b140b76 100644 --- a/build/app.js +++ b/build/app.js @@ -100,6 +100,8 @@ capitano.command(actions.config.write); + capitano.command(actions.config.reconfigure); + capitano.command(actions.logs); update.notify(); diff --git a/doc/cli.markdown b/doc/cli.markdown index 268f796b..610e58ce 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -79,6 +79,7 @@ Now you have access to all the commands referenced below. - [config read](#config-read) - [config write <key> <value>](#config-write-60-key-62-60-value-62-) + - [config reconfigure](#config-reconfigure) - Wizard @@ -627,6 +628,30 @@ device type drive +## config reconfigure + +Use this command to reconfigure a provisioned device + +Examples: + + $ resin config reconfigure --type raspberry-pi + $ resin config reconfigure --type raspberry-pi --advanced + $ resin config reconfigure --type raspberry-pi --drive /dev/disk2 + +### Options + +#### --type, -t <type> + +device type + +#### --drive, -d <drive> + +drive + +#### --advanced, -v + +show advanced commands + # Wizard ## quickstart [name] diff --git a/lib/actions/config.coffee b/lib/actions/config.coffee index 8774273b..55d1b994 100644 --- a/lib/actions/config.coffee +++ b/lib/actions/config.coffee @@ -1,5 +1,6 @@ _ = require('lodash') Promise = require('bluebird') +capitano = Promise.promisifyAll(require('capitano')) umount = Promise.promisifyAll(require('umount')) visuals = require('resin-cli-visuals') config = require('resin-config-json') @@ -88,3 +89,55 @@ exports.write = .tap -> console.info('Done') .nodeify(done) + +exports.reconfigure = + signature: 'config reconfigure' + description: 'reconfigure a provisioned device' + help: ''' + Use this command to reconfigure a provisioned device + + Examples: + + $ resin config reconfigure --type raspberry-pi + $ resin config reconfigure --type raspberry-pi --advanced + $ resin config reconfigure --type raspberry-pi --drive /dev/disk2 + ''' + options: [ + { + signature: 'type' + description: 'device type' + parameter: 'type' + alias: 't' + required: 'You have to specify a device type' + } + { + signature: 'drive' + description: 'drive' + parameter: 'drive' + alias: 'd' + } + { + signature: 'advanced' + description: 'show advanced commands' + boolean: true + alias: 'v' + } + ] + permission: 'user' + root: true + action: (params, options, done) -> + Promise.try -> + return options.drive or visuals.drive('Select the device drive') + .tap(umount.umountAsync) + .then (drive) -> + config.read(drive, options.type).get('uuid') + .tap -> + umount.umountAsync(drive) + .then (uuid) -> + configureCommand = "os configure #{drive} #{uuid}" + if options.advanced + configureCommand += ' --advanced' + return capitano.runAsync(configureCommand) + .then -> + console.info('Done') + .nodeify(done) diff --git a/lib/app.coffee b/lib/app.coffee index 86a1bd80..24f859e7 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -72,6 +72,7 @@ capitano.command(actions.os.initialize) # ---------- Config Module ---------- capitano.command(actions.config.read) capitano.command(actions.config.write) +capitano.command(actions.config.reconfigure) # ---------- Logs Module ---------- capitano.command(actions.logs)