From 8bdacbb11ee10e571b5a1fabcbe60083adc0a99e Mon Sep 17 00:00:00 2001 From: Eugene Mirotin Date: Thu, 15 Jun 2017 00:51:56 +0300 Subject: [PATCH] dedupe the shared options --- build/actions/command-options.js | 14 ++++++++++++++ build/actions/device.js | 14 ++------------ build/actions/os.js | 21 +++------------------ doc/cli.markdown | 8 ++++---- lib/actions/command-options.coffee | 14 ++++++++++++++ lib/actions/device.coffee | 16 ++-------------- lib/actions/os.coffee | 21 +++------------------ 7 files changed, 42 insertions(+), 66 deletions(-) diff --git a/build/actions/command-options.js b/build/actions/command-options.js index 137fbe19..65693c56 100644 --- a/build/actions/command-options.js +++ b/build/actions/command-options.js @@ -84,3 +84,17 @@ exports.forceUpdateLock = { boolean: true, alias: 'f' }; + +exports.drive = { + signature: 'drive', + description: 'the drive to write the image to, like `/dev/sdb` or `/dev/mmcblk0`. Careful with this as you can erase your hard drive. Check `resin util available-drives` for available options.', + parameter: 'drive', + alias: 'd' +}; + +exports.advancedConfig = { + signature: 'advanced', + description: 'show advanced configuration options', + boolean: true, + alias: 'v' +}; diff --git a/build/actions/device.js b/build/actions/device.js index e315fba3..f9b0584a 100644 --- a/build/actions/device.js +++ b/build/actions/device.js @@ -264,20 +264,10 @@ exports.init = { description: 'initialise a device with resinOS', help: 'Use this command to download the OS image of a certain application and write it to an SD Card.\n\nNotice this command may ask for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin device init\n $ resin device init --application MyApp', options: [ - commandOptions.optionalApplication, commandOptions.yes, { - signature: 'advanced', - description: 'enable advanced configuration', - boolean: true, - alias: 'v' - }, _.assign({}, commandOptions.osVersion, { + commandOptions.optionalApplication, commandOptions.yes, commandOptions.advancedConfig, _.assign({}, commandOptions.osVersion, { signature: 'os-version', parameter: 'os-version' - }), { - signature: 'drive', - description: 'the drive to write the image to, like `/dev/sdb` or `/dev/mmcblk0`. Careful with this as you can erase your hard drive. Check `resin util available-drives` for available options.', - parameter: 'drive', - alias: 'd' - }, { + }), commandOptions.drive, { signature: 'config', description: 'path to the config JSON file, see `resin os build-config`', parameter: 'config' diff --git a/build/actions/os.js b/build/actions/os.js index 7289d00f..90c3f42d 100644 --- a/build/actions/os.js +++ b/build/actions/os.js @@ -165,12 +165,7 @@ exports.buildConfig = { help: 'Use this command to prebuild the OS config once and skip the interactive part of `resin os configure`.\n\nExamples:\n\n $ resin os build-config ../path/rpi3.img raspberrypi3 --output rpi3-config.json\n $ resin os configure ../path/rpi3.img 7cf02a6 --config "$(cat rpi3-config.json)"', permission: 'user', options: [ - { - signature: 'advanced', - description: 'show advanced commands', - boolean: true, - alias: 'v' - }, { + commandOptions.advancedConfig, { signature: 'output', description: 'the path to the output JSON file', alias: 'o', @@ -195,12 +190,7 @@ exports.configure = { help: 'Use this command to configure a previously downloaded operating system image for the specific device.\n\nExamples:\n\n $ resin os configure ../path/rpi.img 7cf02a6', permission: 'user', options: [ - { - signature: 'advanced', - description: 'show advanced commands', - boolean: true, - alias: 'v' - }, { + commandOptions.advancedConfig, { signature: 'config', description: 'path to the config JSON file, see `resin os build-config`', parameter: 'config' @@ -240,12 +230,7 @@ exports.initialize = { parameter: 'type', alias: 't', required: 'You have to specify a device type' - }, { - signature: 'drive', - description: 'drive to write the image to. Check `resin util available-drives` for available options.', - parameter: 'drive', - alias: 'd' - } + }, commandOptions.drive ], action: function(params, options, done) { var Promise, form, helpers, patterns, umountAsync; diff --git a/doc/cli.markdown b/doc/cli.markdown index b701156b..fbd83a26 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -481,7 +481,7 @@ confirm non interactively #### --advanced, -v -enable advanced configuration +show advanced configuration options #### --os-version <os-version> @@ -892,7 +892,7 @@ Examples: #### --advanced, -v -show advanced commands +show advanced configuration options #### --output, -o <output> @@ -910,7 +910,7 @@ Examples: #### --advanced, -v -show advanced commands +show advanced configuration options #### --config <config> @@ -939,7 +939,7 @@ device type (Check available types with `resin devices supported`) #### --drive, -d <drive> -drive to write the image to. Check `resin util available-drives` for available options. +the drive to write the image to, like `/dev/sdb` or `/dev/mmcblk0`. Careful with this as you can erase your hard drive. Check `resin util available-drives` for available options. # Config diff --git a/lib/actions/command-options.coffee b/lib/actions/command-options.coffee index d62dbba5..e17ad467 100644 --- a/lib/actions/command-options.coffee +++ b/lib/actions/command-options.coffee @@ -78,3 +78,17 @@ exports.forceUpdateLock = description: 'force action if the update lock is set' boolean: true alias: 'f' + +exports.drive = + signature: 'drive' + description: 'the drive to write the image to, like `/dev/sdb` or `/dev/mmcblk0`. + Careful with this as you can erase your hard drive. + Check `resin util available-drives` for available options.' + parameter: 'drive' + alias: 'd' + +exports.advancedConfig = + signature: 'advanced' + description: 'show advanced configuration options' + boolean: true + alias: 'v' diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee index 951cd0ec..dad7e6e8 100644 --- a/lib/actions/device.coffee +++ b/lib/actions/device.coffee @@ -370,21 +370,9 @@ exports.init = options: [ commandOptions.optionalApplication commandOptions.yes - { - signature: 'advanced' - description: 'enable advanced configuration' - boolean: true - alias: 'v' - } + commandOptions.advancedConfig _.assign({}, commandOptions.osVersion, { signature: 'os-version', parameter: 'os-version' }) - { - signature: 'drive' - description: 'the drive to write the image to, like `/dev/sdb` or `/dev/mmcblk0`. - Careful with this as you can erase your hard drive. - Check `resin util available-drives` for available options.' - parameter: 'drive' - alias: 'd' - } + commandOptions.drive { signature: 'config' description: 'path to the config JSON file, see `resin os build-config`' diff --git a/lib/actions/os.coffee b/lib/actions/os.coffee index fd7f0397..5f4a5683 100644 --- a/lib/actions/os.coffee +++ b/lib/actions/os.coffee @@ -174,12 +174,7 @@ exports.buildConfig = ''' permission: 'user' options: [ - { - signature: 'advanced' - description: 'show advanced commands' - boolean: true - alias: 'v' - } + commandOptions.advancedConfig { signature: 'output' description: 'the path to the output JSON file' @@ -210,12 +205,7 @@ exports.configure = ''' permission: 'user' options: [ - { - signature: 'advanced' - description: 'show advanced commands' - boolean: true - alias: 'v' - } + commandOptions.advancedConfig { signature: 'config' description: 'path to the config JSON file, see `resin os build-config`' @@ -267,12 +257,7 @@ exports.initialize = alias: 't' required: 'You have to specify a device type' } - { - signature: 'drive' - description: 'drive to write the image to. Check `resin util available-drives` for available options.' - parameter: 'drive' - alias: 'd' - } + commandOptions.drive ] action: (params, options, done) -> Promise = require('bluebird')