list detected drives with resin os available-drives

This commit is contained in:
Eugene Mirotin 2017-06-09 13:44:58 +03:00
parent ed83514a2f
commit ad940824a6
7 changed files with 73 additions and 8 deletions

View File

@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- 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`
- List detected drives with `resin os available-drives`
### Fixed

View File

@ -273,7 +273,7 @@ exports.init = {
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.',
description: 'the drive to write the image to, like /dev/sdb. Careful with this as you can erase your hard drive. Check `resin os available-drives` for available options.',
parameter: 'drive',
alias: 'd'
}

View File

@ -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, formatVersion, initWarningMessage, resolveVersion;
var _, commandOptions, formatVersion, initWarningMessage, resolveVersion;
commandOptions = require('./command-options');
_ = require('lodash');
formatVersion = function(v, isRecommended) {
var result;
result = "v" + v;
@ -147,8 +149,7 @@ exports.configure = {
}
],
action: function(params, options, done) {
var _, form, helpers, init, resin;
_ = require('lodash');
var form, helpers, init, resin;
resin = require('resin-sdk-preconfigured');
form = require('resin-cli-form');
init = require('resin-device-init');
@ -178,6 +179,39 @@ exports.configure = {
initWarningMessage = 'Note: Initializing the device may ask for administrative permissions\nbecause we need to access the raw devices directly.';
exports.availableDrives = {
signature: 'os available-drives',
description: 'list available drives',
action: function() {
var Promise, chalk, driveListAsync, drivelist, formatDrive, getDrives;
Promise = require('bluebird');
drivelist = require('drivelist');
driveListAsync = Promise.promisify(drivelist.list);
chalk = require('chalk');
formatDrive = function(drive) {
var size;
size = drive.size / 1000000000;
return drive.device + " (" + (size.toFixed(1)) + " GB) - " + drive.description;
};
getDrives = function() {
return driveListAsync().then(function(drives) {
return _.reject(drives, {
system: true
});
});
};
return getDrives().then(function(drives) {
if (!drives.length) {
console.error((chalk.red('x')) + " No available drives were detected, plug one in!");
return;
}
return drives.forEach(function(drive) {
return console.log(formatDrive(drive));
});
});
}
};
exports.initialize = {
signature: 'os initialize <image>',
description: 'initialize an os image',
@ -192,7 +226,7 @@ exports.initialize = {
required: 'You have to specify a device type'
}, {
signature: 'drive',
description: 'drive',
description: 'drive to write the image to. Check `resin os available-drives` for available options.',
parameter: 'drive',
alias: 'd'
}

View File

@ -168,6 +168,8 @@ capitano.command(actions.env.remove);
capitano.command(actions.os.versions);
capitano.command(actions.os.availableDrives);
capitano.command(actions.os.download);
capitano.command(actions.os.configure);

View File

@ -376,7 +376,7 @@ exports.init =
signature: 'drive'
description: 'the drive to write the image to, like /dev/sdb.
Careful with this as you can erase your hard drive.
'
Check `resin os available-drives` for available options.'
parameter: 'drive'
alias: 'd'
}

View File

@ -15,6 +15,7 @@ limitations under the License.
###
commandOptions = require('./command-options')
_ = require('lodash')
formatVersion = (v, isRecommended) ->
result = "v#{v}"
@ -161,7 +162,6 @@ exports.configure =
alias: 'v'
]
action: (params, options, done) ->
_ = require('lodash')
resin = require('resin-sdk-preconfigured')
form = require('resin-cli-form')
init = require('resin-device-init')
@ -191,6 +191,33 @@ initWarningMessage = '''
because we need to access the raw devices directly.
'''
exports.availableDrives =
# TODO: dedupe with https://github.com/resin-io-modules/resin-cli-visuals/blob/master/lib/widgets/drive/index.coffee
signature: 'os available-drives'
description: 'list available drives'
action: ->
Promise = require('bluebird')
drivelist = require('drivelist')
driveListAsync = Promise.promisify(drivelist.list)
chalk = require('chalk')
formatDrive = (drive) ->
size = drive.size / 1000000000
return "#{drive.device} (#{size.toFixed(1)} GB) - #{drive.description}"
getDrives = ->
driveListAsync().then (drives) ->
return _.reject(drives, system: true)
getDrives()
.then (drives) ->
if not drives.length
console.error("#{chalk.red('x')} No available drives were detected, plug one in!")
return
drives.forEach (drive) ->
console.log(formatDrive(drive))
exports.initialize =
signature: 'os initialize <image>'
description: 'initialize an os image'
@ -215,7 +242,7 @@ exports.initialize =
}
{
signature: 'drive'
description: 'drive'
description: 'drive to write the image to. Check `resin os available-drives` for available options.'
parameter: 'drive'
alias: 'd'
}

View File

@ -136,6 +136,7 @@ capitano.command(actions.env.remove)
# ---------- OS Module ----------
capitano.command(actions.os.versions)
capitano.command(actions.os.availableDrives)
capitano.command(actions.os.download)
capitano.command(actions.os.configure)
capitano.command(actions.os.initialize)