Accept names instead of ids in example commands

This commit is contained in:
Juan Cruz Viotti 2015-05-21 11:58:15 -04:00
parent 72d4b21cb4
commit 68ef069e6a
2 changed files with 25 additions and 24 deletions

View File

@ -35,41 +35,43 @@
} }
return example; return example;
}); });
return console.log(visuals.widgets.table.horizontal(examplesData, ['id', 'display_name', 'repository', 'author'])); return console.log(visuals.widgets.table.horizontal(examplesData, ['id', 'name', 'display_name', 'repository', 'author']));
} }
}; };
exports.info = { exports.info = {
signature: 'example <id>', signature: 'example <name>',
description: 'list a single example application', description: 'list a single example application',
help: 'Use this command to show information of a single example application\n\nExample:\n\n $ resin example 3', help: 'Use this command to show information of a single example application\n\nExample:\n\n $ resin example cimon',
permission: 'user', permission: 'user',
action: function(params, options, done) { action: function(params, options, done) {
var example, id; var example;
id = params.id - 1; example = _.findWhere(examplesData, {
example = examplesData[id]; name: params.name
});
if (example == null) { if (example == null) {
return done(new Error("Unknown example: " + id)); return done(new Error("Unknown example: " + params.name));
} }
example.id = id;
if (example.author == null) { if (example.author == null) {
example.author = 'Unknown'; example.author = 'Unknown';
} }
console.log(visuals.widgets.table.vertical(example, ['id', 'display_name', 'description', 'author', 'repository'])); console.log(visuals.widgets.table.vertical(example, ['name', 'display_name', 'description', 'author', 'repository']));
return done(); return done();
} }
}; };
exports.clone = { exports.clone = {
signature: 'example clone <id>', signature: 'example clone <name>',
description: 'clone an example application', description: 'clone an example application',
help: 'Use this command to clone an example application to the current directory\n\nThis command outputs information about the cloning process.\nUse `--quiet` to remove that output.\n\nExample:\n\n $ resin example clone 3', help: 'Use this command to clone an example application to the current directory\n\nThis command outputs information about the cloning process.\nUse `--quiet` to remove that output.\n\nExample:\n\n $ resin example clone cimon',
permission: 'user', permission: 'user',
action: function(params, options, done) { action: function(params, options, done) {
var currentDirectory, destination, example; var currentDirectory, destination, example;
example = examplesData[params.id - 1]; example = _.findWhere(examplesData, {
name: params.name
});
if (example == null) { if (example == null) {
return done(new Error("Unknown example: " + id)); return done(new Error("Unknown example: " + params.name));
} }
currentDirectory = process.cwd(); currentDirectory = process.cwd();
destination = path.join(currentDirectory, example.name); destination = path.join(currentDirectory, example.name);

View File

@ -30,34 +30,33 @@ exports.list =
console.log visuals.widgets.table.horizontal examplesData, [ console.log visuals.widgets.table.horizontal examplesData, [
'id' 'id'
'name'
'display_name' 'display_name'
'repository' 'repository'
'author' 'author'
] ]
exports.info = exports.info =
signature: 'example <id>' signature: 'example <name>'
description: 'list a single example application' description: 'list a single example application'
help: ''' help: '''
Use this command to show information of a single example application Use this command to show information of a single example application
Example: Example:
$ resin example 3 $ resin example cimon
''' '''
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options, done) ->
id = params.id - 1 example = _.findWhere(examplesData, name: params.name)
example = examplesData[id]
if not example? if not example?
return done(new Error("Unknown example: #{id}")) return done(new Error("Unknown example: #{params.name}"))
example.id = id
example.author ?= 'Unknown' example.author ?= 'Unknown'
console.log visuals.widgets.table.vertical example, [ console.log visuals.widgets.table.vertical example, [
'id' 'name'
'display_name' 'display_name'
'description' 'description'
'author' 'author'
@ -67,7 +66,7 @@ exports.info =
return done() return done()
exports.clone = exports.clone =
signature: 'example clone <id>' signature: 'example clone <name>'
description: 'clone an example application' description: 'clone an example application'
help: ''' help: '''
Use this command to clone an example application to the current directory Use this command to clone an example application to the current directory
@ -77,14 +76,14 @@ exports.clone =
Example: Example:
$ resin example clone 3 $ resin example clone cimon
''' '''
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options, done) ->
example = examplesData[params.id - 1] example = _.findWhere(examplesData, name: params.name)
if not example? if not example?
return done(new Error("Unknown example: #{id}")) return done(new Error("Unknown example: #{params.name}"))
currentDirectory = process.cwd() currentDirectory = process.cwd()
destination = path.join(currentDirectory, example.name) destination = path.join(currentDirectory, example.name)