mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-07 11:26:41 +00:00
Reference applications and devices by name
This commit is contained in:
parent
fa5a7abbbf
commit
df9c4ce2fd
@ -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 <id> 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 <name> 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 <id>',
|
||||
signature: 'app <name>',
|
||||
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 <id>',
|
||||
signature: 'app restart <name>',
|
||||
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 <id>',
|
||||
signature: 'app rm <name>',
|
||||
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 <id>',
|
||||
signature: 'app associate <name>',
|
||||
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);
|
||||
|
@ -13,7 +13,7 @@
|
||||
exports.optionalApplication = {
|
||||
signature: 'application',
|
||||
parameter: 'application',
|
||||
description: 'application id',
|
||||
description: 'application name',
|
||||
alias: ['a', 'app']
|
||||
};
|
||||
|
||||
|
@ -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 <id>',
|
||||
signature: 'device <name>',
|
||||
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 <id>',
|
||||
signature: 'device rm <name>',
|
||||
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 <id> [name]',
|
||||
signature: 'device rename <name> [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);
|
||||
}
|
||||
|
@ -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 <id>.\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 <name>.\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'
|
||||
}
|
||||
|
@ -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 <id> instead.
|
||||
If you want detailed information, use resin app <name> instead.
|
||||
|
||||
Examples:
|
||||
|
||||
@ -75,18 +75,18 @@ exports.list =
|
||||
return done()
|
||||
|
||||
exports.info =
|
||||
signature: 'app <id>'
|
||||
signature: 'app <name>'
|
||||
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 <id>'
|
||||
signature: 'app restart <name>'
|
||||
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 <id>'
|
||||
signature: 'app rm <name>'
|
||||
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 <id>'
|
||||
signature: 'app associate <name>'
|
||||
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)
|
||||
|
@ -9,7 +9,7 @@ exports.yes =
|
||||
exports.optionalApplication =
|
||||
signature: 'application'
|
||||
parameter: 'application'
|
||||
description: 'application id'
|
||||
description: 'application name'
|
||||
alias: [ 'a', 'app' ]
|
||||
|
||||
exports.application = _.defaults
|
||||
|
@ -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 <id>'
|
||||
signature: 'device <name>'
|
||||
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 <id>'
|
||||
signature: 'device rm <name>'
|
||||
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 <id> [name]'
|
||||
signature: 'device rename <name> [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
|
||||
|
||||
|
@ -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 <id>.
|
||||
To view the notes, use $ resin device <name>.
|
||||
|
||||
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'
|
||||
]
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user