mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-20 17:33:18 +00:00
List drives in OS X
This commit is contained in:
parent
d284e92520
commit
fd1e632b50
24
lib/actions/drive.coffee
Normal file
24
lib/actions/drive.coffee
Normal file
@ -0,0 +1,24 @@
|
||||
visuals = require('resin-cli-visuals')
|
||||
drive = require('../drive/drive')
|
||||
|
||||
exports.list =
|
||||
signature: 'drives'
|
||||
description: 'list available drives'
|
||||
help: '''
|
||||
Use this command to list all drives that are connected to your machine.
|
||||
|
||||
Examples:
|
||||
$ resin drives
|
||||
'''
|
||||
permission: 'user'
|
||||
action: (params, options, done) ->
|
||||
drive.listDrives (error, drives) ->
|
||||
return done(error) if error?
|
||||
|
||||
console.log visuals.widgets.table.horizontal drives, [
|
||||
'device'
|
||||
'description'
|
||||
'size'
|
||||
]
|
||||
|
||||
return done()
|
@ -2,6 +2,7 @@ module.exports =
|
||||
app: require('./app')
|
||||
info: require('./info')
|
||||
auth: require('./auth')
|
||||
drive: require('./drive')
|
||||
device: require('./device')
|
||||
env: require('./environment-variables')
|
||||
keys: require('./keys')
|
||||
|
@ -67,7 +67,10 @@ capitano.command(actions.device.info)
|
||||
capitano.command(actions.device.remove)
|
||||
capitano.command(actions.device.identify)
|
||||
|
||||
# ---------- Device Module ----------
|
||||
# ---------- Drive Module ----------
|
||||
capitano.command(actions.drive.list)
|
||||
|
||||
# ---------- Notes Module ----------
|
||||
capitano.command(actions.notes.set)
|
||||
|
||||
# ---------- Preferences Module ----------
|
||||
|
@ -5,6 +5,7 @@ _ = require('lodash-contrib')
|
||||
async = require('async')
|
||||
childProcess = require('child_process')
|
||||
progressStream = require('progress-stream')
|
||||
DriveOSX = require('./osx')
|
||||
|
||||
IS_WINDOWS = os.platform() is 'win32'
|
||||
DISK_IO_FLAGS = 'rs+'
|
||||
@ -96,3 +97,10 @@ exports.writeImage = (devicePath, imagePath, options = {}, callback = _.noop) ->
|
||||
delete error.code
|
||||
|
||||
return callback(error)
|
||||
|
||||
exports.listDrives = (callback) ->
|
||||
if os.platform() is 'darwin'
|
||||
DriveOSX.list(callback)
|
||||
else
|
||||
error = new Error('Your OS does not yet support this command')
|
||||
return callback(error)
|
||||
|
40
lib/drive/osx.coffee
Normal file
40
lib/drive/osx.coffee
Normal file
@ -0,0 +1,40 @@
|
||||
_ = require('lodash')
|
||||
os = require('os')
|
||||
childProcess = require('child_process')
|
||||
tableParser = require('table-parser')
|
||||
|
||||
exports.list = (callback) ->
|
||||
if os.platform() is 'darwin'
|
||||
childProcess.exec 'diskutil list', {}, (error, stdout, stderr) ->
|
||||
return callback(error) if error?
|
||||
|
||||
if not _.isEmpty(stderr)
|
||||
return callback(new Error(stderr))
|
||||
|
||||
result = tableParser.parse(stdout)
|
||||
|
||||
result = _.map result, (row) ->
|
||||
return _.compact _.flatten _.values(row)
|
||||
|
||||
result = _.filter result, (row) ->
|
||||
return row[0] is '0:'
|
||||
|
||||
result = _.map result, (row) ->
|
||||
return _.rest(row)
|
||||
|
||||
result = _.map result, (row) ->
|
||||
|
||||
device = row.pop()
|
||||
sizeMeasure = row.pop()
|
||||
size = row.pop()
|
||||
|
||||
return {
|
||||
device: "/dev/#{device}"
|
||||
size: "#{size}#{sizeMeasure}"
|
||||
description: row.join(' ')
|
||||
}
|
||||
|
||||
return callback(null, result)
|
||||
else
|
||||
error = new Error('Your OS does not yet support this command')
|
||||
return callback(error)
|
@ -58,6 +58,7 @@
|
||||
"progress-stream": "^0.5.0",
|
||||
"resin-cli-visuals": "0.0.3",
|
||||
"resin-sdk": "git+https://git@github.com/resin-io/resin-sdk.git",
|
||||
"table-parser": "0.0.3",
|
||||
"underscore.string": "~2.4.0"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user