From 68ef069e6abb0fcdadd54d5f1d8b8119f8580dca Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 21 May 2015 11:58:15 -0400 Subject: [PATCH] Accept names instead of ids in example commands --- build/actions/examples.js | 28 +++++++++++++++------------- lib/actions/examples.coffee | 21 ++++++++++----------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/build/actions/examples.js b/build/actions/examples.js index dba15c66..bdea13c4 100644 --- a/build/actions/examples.js +++ b/build/actions/examples.js @@ -35,41 +35,43 @@ } 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 = { - signature: 'example ', + signature: 'example ', 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', action: function(params, options, done) { - var example, id; - id = params.id - 1; - example = examplesData[id]; + var example; + example = _.findWhere(examplesData, { + name: params.name + }); 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) { 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(); } }; exports.clone = { - signature: 'example clone ', + signature: 'example clone ', 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', action: function(params, options, done) { var currentDirectory, destination, example; - example = examplesData[params.id - 1]; + example = _.findWhere(examplesData, { + name: params.name + }); if (example == null) { - return done(new Error("Unknown example: " + id)); + return done(new Error("Unknown example: " + params.name)); } currentDirectory = process.cwd(); destination = path.join(currentDirectory, example.name); diff --git a/lib/actions/examples.coffee b/lib/actions/examples.coffee index 67529097..5a8a9532 100644 --- a/lib/actions/examples.coffee +++ b/lib/actions/examples.coffee @@ -30,34 +30,33 @@ exports.list = console.log visuals.widgets.table.horizontal examplesData, [ 'id' + 'name' 'display_name' 'repository' 'author' ] exports.info = - signature: 'example ' + signature: 'example ' description: 'list a single example application' help: ''' Use this command to show information of a single example application Example: - $ resin example 3 + $ resin example cimon ''' permission: 'user' action: (params, options, done) -> - id = params.id - 1 - example = examplesData[id] + example = _.findWhere(examplesData, name: params.name) if not example? - return done(new Error("Unknown example: #{id}")) + return done(new Error("Unknown example: #{params.name}")) - example.id = id example.author ?= 'Unknown' console.log visuals.widgets.table.vertical example, [ - 'id' + 'name' 'display_name' 'description' 'author' @@ -67,7 +66,7 @@ exports.info = return done() exports.clone = - signature: 'example clone ' + signature: 'example clone ' description: 'clone an example application' help: ''' Use this command to clone an example application to the current directory @@ -77,14 +76,14 @@ exports.clone = Example: - $ resin example clone 3 + $ resin example clone cimon ''' permission: 'user' action: (params, options, done) -> - example = examplesData[params.id - 1] + example = _.findWhere(examplesData, name: params.name) if not example? - return done(new Error("Unknown example: #{id}")) + return done(new Error("Unknown example: #{params.name}")) currentDirectory = process.cwd() destination = path.join(currentDirectory, example.name)