From df9c4ce2fdcbe4f13c022a6a41c7b32beeade4e4 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 23 Mar 2015 08:17:55 -0400 Subject: [PATCH] Reference applications and devices by name --- build/actions/app.js | 37 +++++++++++++++------------ build/actions/command-options.js | 2 +- build/actions/device.js | 26 +++++++++---------- build/actions/notes.js | 4 +-- lib/actions/app.coffee | 41 +++++++++++++++++------------- lib/actions/command-options.coffee | 2 +- lib/actions/device.coffee | 30 +++++++++++----------- lib/actions/notes.coffee | 8 +++--- package.json | 2 +- 9 files changed, 81 insertions(+), 71 deletions(-) diff --git a/build/actions/app.js b/build/actions/app.js index 545c97d0..93c0d86a 100644 --- a/build/actions/app.js +++ b/build/actions/app.js @@ -50,7 +50,7 @@ exports.list = { signature: 'apps', description: 'list all applications', - help: 'Use this command to list all your applications.\n\nNotice this command only shows the most important bits of information for each app.\nIf you want detailed information, use resin app instead.\n\nExamples:\n\n $ resin apps', + help: 'Use this command to list all your applications.\n\nNotice this command only shows the most important bits of information for each app.\nIf you want detailed information, use resin app instead.\n\nExamples:\n\n $ resin apps', permission: 'user', action: function(params, options, done) { return resin.models.application.getAll(function(error, applications) { @@ -64,12 +64,12 @@ }; exports.info = { - signature: 'app ', + signature: 'app ', description: 'list a single application', - help: 'Use this command to show detailed information for a single application.\n\nExamples:\n\n $ resin app 91', + help: 'Use this command to show detailed information for a single application.\n\nExamples:\n\n $ resin app MyApp', permission: 'user', action: function(params, options, done) { - return resin.models.application.get(params.id, function(error, application) { + return resin.models.application.get(params.name, function(error, application) { if (error != null) { return done(error); } @@ -80,32 +80,32 @@ }; exports.restart = { - signature: 'app restart ', + signature: 'app restart ', description: 'restart an application', - help: 'Use this command to restart all devices that belongs to a certain application.\n\nExamples:\n\n $ resin app restart 91', + help: 'Use this command to restart all devices that belongs to a certain application.\n\nExamples:\n\n $ resin app restart MyApp', permission: 'user', action: function(params, options, done) { - return resin.models.application.restart(params.id, done); + return resin.models.application.restart(params.name, done); } }; exports.remove = { - signature: 'app rm ', + signature: 'app rm ', description: 'remove an application', - help: 'Use this command to remove a resin.io application.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin app rm 91\n $ resin app rm 91 --yes', + help: 'Use this command to remove a resin.io application.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin app rm MyApp\n $ resin app rm MyApp --yes', options: [commandOptions.yes], permission: 'user', action: function(params, options, done) { return visuals.patterns.remove('application', options.yes, function(callback) { - return resin.models.application.remove(params.id, callback); + return resin.models.application.remove(params.name, callback); }, done); } }; exports.associate = { - signature: 'app associate ', + signature: 'app associate ', description: 'associate a resin project', - help: 'Use this command to associate a project directory with a resin application.\n\nThis command adds a \'resin\' git remote to the directory and runs git init if necessary.\n\nExamples:\n\n $ resin app associate 91\n $ resin app associate 91 --project my/app/directory', + help: 'Use this command to associate a project directory with a resin application.\n\nThis command adds a \'resin\' git remote to the directory and runs git init if necessary.\n\nExamples:\n\n $ resin app associate MyApp\n $ resin app associate MyApp --project my/app/directory', permission: 'user', action: function(params, options, done) { var currentDirectory; @@ -114,7 +114,7 @@ function(callback) { return vcs.initialize(currentDirectory, callback); }, function(callback) { - return resin.models.application.get(params.id, callback); + return resin.models.application.get(params.name, callback); }, function(application, callback) { return vcs.addRemote(currentDirectory, application.git_repository, callback); } @@ -144,10 +144,15 @@ }, function(applicationName, callback) { return exports.create.action({ name: applicationName - }, options, callback); - }, function(applicationId, callback) { + }, options, function(error) { + if (error != null) { + return callback(error); + } + return callback(null, applicationName); + }); + }, function(applicationName, callback) { return exports.associate.action({ - id: applicationId + name: applicationName }, options, callback); } ], done); diff --git a/build/actions/command-options.js b/build/actions/command-options.js index 46a7677f..2b184d75 100644 --- a/build/actions/command-options.js +++ b/build/actions/command-options.js @@ -13,7 +13,7 @@ exports.optionalApplication = { signature: 'application', parameter: 'application', - description: 'application id', + description: 'application name', alias: ['a', 'app'] }; diff --git a/build/actions/device.js b/build/actions/device.js index 4b10f2c3..d3f909b1 100644 --- a/build/actions/device.js +++ b/build/actions/device.js @@ -20,7 +20,7 @@ exports.list = { signature: 'devices', description: 'list all devices', - help: 'Use this command to list all devices that belong to a certain application.\n\nExamples:\n\n $ resin devices --application 91', + help: 'Use this command to list all devices that belong to a certain application.\n\nExamples:\n\n $ resin devices --application MyApp', options: [commandOptions.application], permission: 'user', action: function(params, options, done) { @@ -35,12 +35,12 @@ }; exports.info = { - signature: 'device ', + signature: 'device ', description: 'list a single device', - help: 'Use this command to show information about a single device.\n\nExamples:\n\n $ resin device 317', + help: 'Use this command to show information about a single device.\n\nExamples:\n\n $ resin device MyDevice', permission: 'user', action: function(params, options, done) { - return resin.models.device.get(params.id, function(error, device) { + return resin.models.device.get(params.name, function(error, device) { if (error != null) { return done(error); } @@ -51,14 +51,14 @@ }; exports.remove = { - signature: 'device rm ', + signature: 'device rm ', description: 'remove a device', - help: 'Use this command to remove a device from resin.io.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin device rm 317\n $ resin device rm 317 --yes', + help: 'Use this command to remove a device from resin.io.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin device rm MyDevice\n $ resin device rm MyDevice --yes', options: [commandOptions.yes], permission: 'user', action: function(params, options, done) { return visuals.patterns.remove('device', options.yes, function(callback) { - return resin.models.device.remove(params.id, callback); + return resin.models.device.remove(params.name, callback); }, done); } }; @@ -74,19 +74,19 @@ }; exports.rename = { - signature: 'device rename [name]', + signature: 'device rename [newName]', description: 'rename a resin device', - help: 'Use this command to rename a device.\n\nIf you omit the name, you\'ll get asked for it interactively.\n\nExamples:\n\n $ resin device rename 317 MyPi\n $ resin device rename 317', + help: 'Use this command to rename a device.\n\nIf you omit the name, you\'ll get asked for it interactively.\n\nExamples:\n\n $ resin device rename MyDevice MyPi\n $ resin device rename MyDevice', permission: 'user', action: function(params, options, done) { return async.waterfall([ function(callback) { - if (!_.isEmpty(params.name)) { - return callback(null, params.name); + if (!_.isEmpty(params.newName)) { + return callback(null, params.newName); } return visuals.widgets.ask('How do you want to name this device?', null, callback); - }, function(name, callback) { - return resin.models.device.rename(params.id, name, callback); + }, function(newName, callback) { + return resin.models.device.rename(params.name, newName, callback); } ], done); } diff --git a/build/actions/notes.js b/build/actions/notes.js index 983e10b0..2de622cb 100644 --- a/build/actions/notes.js +++ b/build/actions/notes.js @@ -8,12 +8,12 @@ exports.set = { signature: 'note <|note>', description: 'set a device note', - help: 'Use this command to set or update a device note.\n\nIf note command isn\'t passed, the tool attempts to read from `stdin`.\n\nTo view the notes, use $ resin device .\n\nExamples:\n\n $ resin note "My useful note" --device 317\n $ cat note.txt | resin note --device 317', + help: 'Use this command to set or update a device note.\n\nIf note command isn\'t passed, the tool attempts to read from `stdin`.\n\nTo view the notes, use $ resin device .\n\nExamples:\n\n $ resin note "My useful note" --device MyDevice\n $ cat note.txt | resin note --device MyDevice', options: [ { signature: 'device', parameter: 'device', - description: 'device id', + description: 'device name', alias: ['d', 'dev'], required: 'You have to specify a device' } diff --git a/lib/actions/app.coffee b/lib/actions/app.coffee index 83d28d03..636b2d66 100644 --- a/lib/actions/app.coffee +++ b/lib/actions/app.coffee @@ -55,7 +55,7 @@ exports.list = Use this command to list all your applications. Notice this command only shows the most important bits of information for each app. - If you want detailed information, use resin app instead. + If you want detailed information, use resin app instead. Examples: @@ -75,18 +75,18 @@ exports.list = return done() exports.info = - signature: 'app ' + signature: 'app ' description: 'list a single application' help: ''' Use this command to show detailed information for a single application. Examples: - $ resin app 91 + $ resin app MyApp ''' permission: 'user' action: (params, options, done) -> - resin.models.application.get params.id, (error, application) -> + resin.models.application.get params.name, (error, application) -> return done(error) if error? console.log visuals.widgets.table.vertical application, [ 'id' @@ -98,21 +98,21 @@ exports.info = return done() exports.restart = - signature: 'app restart ' + signature: 'app restart ' description: 'restart an application' help: ''' Use this command to restart all devices that belongs to a certain application. Examples: - $ resin app restart 91 + $ resin app restart MyApp ''' permission: 'user' action: (params, options, done) -> - resin.models.application.restart(params.id, done) + resin.models.application.restart(params.name, done) exports.remove = - signature: 'app rm ' + signature: 'app rm ' description: 'remove an application' help: ''' Use this command to remove a resin.io application. @@ -122,18 +122,18 @@ exports.remove = Examples: - $ resin app rm 91 - $ resin app rm 91 --yes + $ resin app rm MyApp + $ resin app rm MyApp --yes ''' options: [ commandOptions.yes ] permission: 'user' action: (params, options, done) -> visuals.patterns.remove 'application', options.yes, (callback) -> - resin.models.application.remove(params.id, callback) + resin.models.application.remove(params.name, callback) , done exports.associate = - signature: 'app associate ' + signature: 'app associate ' description: 'associate a resin project' help: ''' Use this command to associate a project directory with a resin application. @@ -142,8 +142,8 @@ exports.associate = Examples: - $ resin app associate 91 - $ resin app associate 91 --project my/app/directory + $ resin app associate MyApp + $ resin app associate MyApp --project my/app/directory ''' permission: 'user' action: (params, options, done) -> @@ -155,7 +155,7 @@ exports.associate = vcs.initialize(currentDirectory, callback) (callback) -> - resin.models.application.get(params.id, callback) + resin.models.application.get(params.name, callback) (application, callback) -> vcs.addRemote(currentDirectory, application.git_repository, callback) @@ -193,9 +193,14 @@ exports.init = visuals.widgets.ask('What is the name of your application?', currentDirectoryBasename, callback) (applicationName, callback) -> - exports.create.action(name: applicationName, options, callback) - (applicationId, callback) -> - exports.associate.action(id: applicationId, options, callback) + # TODO: Make resin.models.application.create return + # the whole application instead of just the id + exports.create.action name: applicationName, options, (error) -> + return callback(error) if error? + return callback(null, applicationName) + + (applicationName, callback) -> + exports.associate.action(name: applicationName, options, callback) ], done) diff --git a/lib/actions/command-options.coffee b/lib/actions/command-options.coffee index 4a3e5b1f..0ea90266 100644 --- a/lib/actions/command-options.coffee +++ b/lib/actions/command-options.coffee @@ -9,7 +9,7 @@ exports.yes = exports.optionalApplication = signature: 'application' parameter: 'application' - description: 'application id' + description: 'application name' alias: [ 'a', 'app' ] exports.application = _.defaults diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee index 9024b666..ffc72930 100644 --- a/lib/actions/device.coffee +++ b/lib/actions/device.coffee @@ -15,7 +15,7 @@ exports.list = Examples: - $ resin devices --application 91 + $ resin devices --application MyApp ''' options: [ commandOptions.application ] permission: 'user' @@ -35,18 +35,18 @@ exports.list = return done() exports.info = - signature: 'device ' + signature: 'device ' description: 'list a single device' help: ''' Use this command to show information about a single device. Examples: - $ resin device 317 + $ resin device MyDevice ''' permission: 'user' action: (params, options, done) -> - resin.models.device.get params.id, (error, device) -> + resin.models.device.get params.name, (error, device) -> return done(error) if error? console.log visuals.widgets.table.vertical device, [ 'id' @@ -67,7 +67,7 @@ exports.info = return done() exports.remove = - signature: 'device rm ' + signature: 'device rm ' description: 'remove a device' help: ''' Use this command to remove a device from resin.io. @@ -77,14 +77,14 @@ exports.remove = Examples: - $ resin device rm 317 - $ resin device rm 317 --yes + $ resin device rm MyDevice + $ resin device rm MyDevice --yes ''' options: [ commandOptions.yes ] permission: 'user' action: (params, options, done) -> visuals.patterns.remove 'device', options.yes, (callback) -> - resin.models.device.remove(params.id, callback) + resin.models.device.remove(params.name, callback) , done exports.identify = @@ -104,7 +104,7 @@ exports.identify = resin.models.device.identify(params.uuid, done) exports.rename = - signature: 'device rename [name]' + signature: 'device rename [newName]' description: 'rename a resin device' help: ''' Use this command to rename a device. @@ -113,20 +113,20 @@ exports.rename = Examples: - $ resin device rename 317 MyPi - $ resin device rename 317 + $ resin device rename MyDevice MyPi + $ resin device rename MyDevice ''' permission: 'user' action: (params, options, done) -> async.waterfall [ (callback) -> - if not _.isEmpty(params.name) - return callback(null, params.name) + if not _.isEmpty(params.newName) + return callback(null, params.newName) visuals.widgets.ask('How do you want to name this device?', null, callback) - (name, callback) -> - resin.models.device.rename(params.id, name, callback) + (newName, callback) -> + resin.models.device.rename(params.name, newName, callback) ], done diff --git a/lib/actions/notes.coffee b/lib/actions/notes.coffee index aeba40fc..39b5ab15 100644 --- a/lib/actions/notes.coffee +++ b/lib/actions/notes.coffee @@ -9,17 +9,17 @@ exports.set = If note command isn't passed, the tool attempts to read from `stdin`. - To view the notes, use $ resin device . + To view the notes, use $ resin device . Examples: - $ resin note "My useful note" --device 317 - $ cat note.txt | resin note --device 317 + $ resin note "My useful note" --device MyDevice + $ cat note.txt | resin note --device MyDevice ''' options: [ signature: 'device' parameter: 'device' - description: 'device id' + description: 'device name' alias: [ 'd', 'dev' ] required: 'You have to specify a device' ] diff --git a/package.json b/package.json index 526a8ba8..be9b79c6 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "open": "0.0.5", "progress-stream": "^0.5.0", "resin-cli-visuals": "^0.1.0", - "resin-sdk": "^1.1.0", + "resin-sdk": "^1.2.0", "resin-settings-client": "^1.0.0", "resin-vcs": "^1.0.0", "underscore.string": "~2.4.0",