Implement config read command

This command is used to read a config.json from a provisioned device
This commit is contained in:
Juan Cruz Viotti 2015-11-10 12:53:34 -04:00
parent f84d0d0980
commit 5509a3e9fd
9 changed files with 157 additions and 1 deletions

60
build/actions/config.js Normal file
View File

@ -0,0 +1,60 @@
(function() {
var Promise, imagefs, prettyjson, resin, rindle, umount, visuals;
Promise = require('bluebird');
umount = Promise.promisifyAll(require('umount'));
resin = require('resin-sdk');
imagefs = require('resin-image-fs');
visuals = require('resin-cli-visuals');
prettyjson = require('prettyjson');
rindle = require('rindle');
exports.read = {
signature: 'config read',
description: 'read a device configuration',
help: 'Use this command to read the config.json file from a provisioned device\n\nExample:\n\n $ resin config read --type raspberry-pi\n $ resin config read --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'
}
],
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 resin.models.device.getManifestBySlug(options.type).then(function(manifest) {
var config, ref;
config = (ref = manifest.configuration) != null ? ref.config : void 0;
if (config == null) {
throw new Error("Unsupported device type: " + options.type);
}
return imagefs.read({
image: drive,
partition: config.partition,
path: config.path
});
});
}).then(rindle.extract).then(JSON.parse).then(function(config) {
return console.log(prettyjson.render(config));
}).nodeify(done);
}
};
}).call(this);

View File

@ -10,7 +10,8 @@
logs: require('./logs'),
notes: require('./notes'),
help: require('./help'),
os: require('./os')
os: require('./os'),
config: require('./config')
};
}).call(this);

View File

@ -96,6 +96,8 @@
capitano.command(actions.os.initialize);
capitano.command(actions.config.read);
capitano.command(actions.logs);
update.notify();

View File

@ -62,6 +62,12 @@
"lib/actions/os.coffee"
]
},
{
"title": "Config",
"files": [
"lib/actions/config.coffee"
]
},
{
"title": "Wizard",
"files": [

View File

@ -76,6 +76,10 @@ Now you have access to all the commands referenced below.
- [os configure <image> <uuid>](#os-configure-60-image-62-60-uuid-62-)
- [os initialize <image>](#os-initialize-60-image-62-)
- Config
- [config read](#config-read)
- Wizard
- [quickstart [name]](#quickstart-name-)
@ -594,6 +598,27 @@ device type
drive
# Config
## config read
Use this command to read the config.json file from a provisioned device
Example:
$ resin config read --type raspberry-pi
$ resin config read --type raspberry-pi --drive /dev/disk2
### Options
#### --type, -t <type>
device type
#### --drive, -d <drive>
drive
# Wizard
## quickstart [name]

56
lib/actions/config.coffee Normal file
View File

@ -0,0 +1,56 @@
Promise = require('bluebird')
umount = Promise.promisifyAll(require('umount'))
resin = require('resin-sdk')
imagefs = require('resin-image-fs')
visuals = require('resin-cli-visuals')
prettyjson = require('prettyjson')
rindle = require('rindle')
exports.read =
signature: 'config read'
description: 'read a device configuration'
help: '''
Use this command to read the config.json file from a provisioned device
Example:
$ resin config read --type raspberry-pi
$ resin config read --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'
}
]
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) ->
resin.models.device.getManifestBySlug(options.type).then (manifest) ->
config = manifest.configuration?.config
if not config?
throw new Error("Unsupported device type: #{options.type}")
imagefs.read
image: drive
partition: config.partition
path: config.path
.then(rindle.extract)
.then(JSON.parse)
.then (config) ->
console.log(prettyjson.render(config))
.nodeify(done)

View File

@ -10,3 +10,4 @@ module.exports =
notes: require('./notes')
help: require('./help')
os: require('./os')
config: require('./config')

View File

@ -69,6 +69,9 @@ capitano.command(actions.os.download)
capitano.command(actions.os.configure)
capitano.command(actions.os.initialize)
# ---------- Config Module ----------
capitano.command(actions.config.read)
# ---------- Logs Module ----------
capitano.command(actions.logs)

View File

@ -47,6 +47,7 @@
"lodash": "^3.10.0",
"nplugm": "^3.0.0",
"president": "^2.0.0",
"prettyjson": "^1.1.3",
"resin-cli-errors": "^1.0.0",
"resin-cli-events": "^1.0.2",
"resin-cli-form": "^1.3.0",
@ -54,6 +55,7 @@
"resin-config-inject": "^2.0.0",
"resin-device-init": "^2.0.0",
"resin-image": "^1.1.4",
"resin-image-fs": "^2.1.1",
"resin-image-manager": "^3.2.2",
"resin-pine": "^1.3.0",
"resin-sdk": "^4.0.0",