Merge pull request #300 from resin-io/feat/shorter-uuids

Support shorter uuids
This commit is contained in:
Juan Cruz Viotti 2016-01-21 10:41:55 -04:00
commit 4bf079377b
11 changed files with 51 additions and 41 deletions

View File

@ -28,8 +28,9 @@ limitations under the License.
permission: 'user',
primary: true,
action: function(params, options, done) {
var Promise, resin, visuals;
var Promise, _, resin, visuals;
Promise = require('bluebird');
_ = require('lodash');
resin = require('resin-sdk');
visuals = require('resin-cli-visuals');
return Promise["try"](function() {
@ -38,6 +39,10 @@ limitations under the License.
}
return resin.models.device.getAll();
}).tap(function(devices) {
devices = _.map(devices, function(device) {
device.uuid = device.uuid.slice(0, 7);
return device;
});
return console.log(visuals.table.horizontal(devices, ['id', 'uuid', 'name', 'device_type', 'application_name', 'status']));
}).nodeify(done);
}
@ -46,7 +51,7 @@ limitations under the License.
exports.info = {
signature: 'device <uuid>',
description: 'list a single device',
help: 'Use this command to show information about a single device.\n\nExamples:\n\n $ resin device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9',
help: 'Use this command to show information about a single device.\n\nExamples:\n\n $ resin device 7cf02a6',
permission: 'user',
primary: true,
action: function(params, options, done) {
@ -97,7 +102,7 @@ limitations under the License.
exports.remove = {
signature: 'device rm <uuid>',
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 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9\n $ resin device rm 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 --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 7cf02a6\n $ resin device rm 7cf02a6 --yes',
options: [commandOptions.yes],
permission: 'user',
action: function(params, options, done) {
@ -118,7 +123,7 @@ limitations under the License.
exports.identify = {
signature: 'device identify <uuid>',
description: 'identify a device with a UUID',
help: 'Use this command to identify a device.\n\nIn the Raspberry Pi, the ACT led is blinked several times.\n\nExamples:\n\n $ resin device identify 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828',
help: 'Use this command to identify a device.\n\nIn the Raspberry Pi, the ACT led is blinked several times.\n\nExamples:\n\n $ resin device identify 23c73a1',
permission: 'user',
action: function(params, options, done) {
var resin;
@ -130,7 +135,7 @@ limitations under the License.
exports.rename = {
signature: 'device rename <uuid> [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 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 MyPi\n $ resin device rename 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9',
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 7cf02a6\n $ resin device rename 7cf02a6 MyPi',
permission: 'user',
action: function(params, options, done) {
var Promise, _, events, form, resin;
@ -158,7 +163,7 @@ limitations under the License.
exports.move = {
signature: 'device move <uuid>',
description: 'move a device to another application',
help: 'Use this command to move a device to another application you own.\n\nIf you omit the application, you\'ll get asked for it interactively.\n\nExamples:\n\n $ resin device move 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9\n $ resin device move 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 --application MyNewApp',
help: 'Use this command to move a device to another application you own.\n\nIf you omit the application, you\'ll get asked for it interactively.\n\nExamples:\n\n $ resin device move 7cf02a6\n $ resin device move 7cf02a6 --application MyNewApp',
permission: 'user',
options: [commandOptions.optionalApplication],
action: function(params, options, done) {

View File

@ -23,7 +23,7 @@ limitations under the License.
exports.list = {
signature: 'envs',
description: 'list all environment variables',
help: 'Use this command to list all environment variables for\na particular application or device.\n\nThis command lists all custom environment variables.\nIf you want to see all environment variables, including private\nones used by resin, use the verbose option.\n\nExample:\n\n $ resin envs --application MyApp\n $ resin envs --application MyApp --verbose\n $ resin envs --device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9',
help: 'Use this command to list all environment variables for\na particular application or device.\n\nThis command lists all custom environment variables.\nIf you want to see all environment variables, including private\nones used by resin, use the verbose option.\n\nExample:\n\n $ resin envs --application MyApp\n $ resin envs --application MyApp --verbose\n $ resin envs --device 7cf02a6',
options: [
commandOptions.optionalApplication, commandOptions.optionalDevice, {
signature: 'verbose',
@ -91,7 +91,7 @@ limitations under the License.
exports.add = {
signature: 'env add <key> [value]',
description: 'add an environment variable',
help: 'Use this command to add an enviroment variable to an application.\n\nIf value is omitted, the tool will attempt to use the variable\'s value\nas defined in your host machine.\n\nUse the `--device` option if you want to assign the environment variable\nto a specific device.\n\nIf the value is grabbed from the environment, a warning message will be printed.\nUse `--quiet` to remove it.\n\nExamples:\n\n $ resin env add EDITOR vim --application MyApp\n $ resin env add TERM --application MyApp\n $ resin env add EDITOR vim --device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9',
help: 'Use this command to add an enviroment variable to an application.\n\nIf value is omitted, the tool will attempt to use the variable\'s value\nas defined in your host machine.\n\nUse the `--device` option if you want to assign the environment variable\nto a specific device.\n\nIf the value is grabbed from the environment, a warning message will be printed.\nUse `--quiet` to remove it.\n\nExamples:\n\n $ resin env add EDITOR vim --application MyApp\n $ resin env add TERM --application MyApp\n $ resin env add EDITOR vim --device 7cf02a6',
options: [commandOptions.optionalApplication, commandOptions.optionalDevice],
permission: 'user',
action: function(params, options, done) {

View File

@ -19,7 +19,7 @@ limitations under the License.
module.exports = {
signature: 'logs <uuid>',
description: 'show device logs',
help: 'Use this command to show logs for a specific device.\n\nBy default, the command prints all log messages and exit.\n\nTo continuously stream output, and see new logs in real time, use the `--tail` option.\n\nNote that for now you need to provide the whole UUID for this command to work correctly.\n\nThis is due to some technical limitations that we plan to address soon.\n\nExamples:\n\n $ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828\n $ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828 --tail',
help: 'Use this command to show logs for a specific device.\n\nBy default, the command prints all log messages and exit.\n\nTo continuously stream output, and see new logs in real time, use the `--tail` option.\n\nNote that for now you need to provide the whole UUID for this command to work correctly.\n\nThis is due to some technical limitations that we plan to address soon.\n\nExamples:\n\n $ resin logs 23c73a1\n $ resin logs 23c73a1',
options: [
{
signature: 'tail',

View File

@ -19,7 +19,7 @@ limitations under the License.
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 <uuid>.\n\nExamples:\n\n $ resin note "My useful note" --device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9\n $ cat note.txt | resin note --device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9',
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 <uuid>.\n\nExamples:\n\n $ resin note "My useful note" --device 7cf02a6\n $ cat note.txt | resin note --device 7cf02a6',
options: [
{
signature: 'device',

View File

@ -92,7 +92,7 @@ limitations under the License.
exports.configure = {
signature: 'os configure <image> <uuid>',
description: 'configure an os image',
help: 'Use this command to configure a previously download operating system image with a device.\n\nExamples:\n\n $ resin os configure ../path/rpi.img 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9',
help: 'Use this command to configure a previously download operating system image with a device.\n\nExamples:\n\n $ resin os configure ../path/rpi.img 7cf02a6',
permission: 'user',
options: [
{

View File

@ -263,7 +263,7 @@ Use this command to show information about a single device.
Examples:
$ resin device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin device 7cf02a6
## device register &#60;application&#62;
@ -288,8 +288,8 @@ You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin device rm 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin device rm 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 --yes
$ resin device rm 7cf02a6
$ resin device rm 7cf02a6 --yes
### Options
@ -305,7 +305,7 @@ In the Raspberry Pi, the ACT led is blinked several times.
Examples:
$ resin device identify 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828
$ resin device identify 23c73a1
## device rename &#60;uuid&#62; [newName]
@ -315,8 +315,8 @@ If you omit the name, you'll get asked for it interactively.
Examples:
$ resin device rename 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 MyPi
$ resin device rename 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin device rename 7cf02a6
$ resin device rename 7cf02a6 MyPi
## device move &#60;uuid&#62;
@ -326,8 +326,8 @@ If you omit the application, you'll get asked for it interactively.
Examples:
$ resin device move 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin device move 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 --application MyNewApp
$ resin device move 7cf02a6
$ resin device move 7cf02a6 --application MyNewApp
### Options
@ -376,7 +376,7 @@ Example:
$ resin envs --application MyApp
$ resin envs --application MyApp --verbose
$ resin envs --device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin envs --device 7cf02a6
### Options
@ -436,7 +436,7 @@ Examples:
$ resin env add EDITOR vim --application MyApp
$ resin env add TERM --application MyApp
$ resin env add EDITOR vim --device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin env add EDITOR vim --device 7cf02a6
### Options
@ -552,8 +552,8 @@ This is due to some technical limitations that we plan to address soon.
Examples:
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828 --tail
$ resin logs 23c73a1
$ resin logs 23c73a1
### Options
@ -573,8 +573,8 @@ To view the notes, use $ resin device <uuid>.
Examples:
$ resin note "My useful note" --device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ cat note.txt | resin note --device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin note "My useful note" --device 7cf02a6
$ cat note.txt | resin note --device 7cf02a6
### Options
@ -604,7 +604,7 @@ Use this command to configure a previously download operating system image with
Examples:
$ resin os configure ../path/rpi.img 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin os configure ../path/rpi.img 7cf02a6
### Options

View File

@ -36,6 +36,7 @@ exports.list =
primary: true
action: (params, options, done) ->
Promise = require('bluebird')
_ = require('lodash')
resin = require('resin-sdk')
visuals = require('resin-cli-visuals')
@ -45,6 +46,10 @@ exports.list =
return resin.models.device.getAll()
.tap (devices) ->
devices = _.map devices, (device) ->
device.uuid = device.uuid.slice(0, 7)
return device
console.log visuals.table.horizontal devices, [
'id'
'uuid'
@ -63,7 +68,7 @@ exports.info =
Examples:
$ resin device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin device 7cf02a6
'''
permission: 'user'
primary: true
@ -139,8 +144,8 @@ exports.remove =
Examples:
$ resin device rm 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin device rm 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 --yes
$ resin device rm 7cf02a6
$ resin device rm 7cf02a6 --yes
'''
options: [ commandOptions.yes ]
permission: 'user'
@ -165,7 +170,7 @@ exports.identify =
Examples:
$ resin device identify 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828
$ resin device identify 23c73a1
'''
permission: 'user'
action: (params, options, done) ->
@ -182,8 +187,8 @@ exports.rename =
Examples:
$ resin device rename 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 MyPi
$ resin device rename 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin device rename 7cf02a6
$ resin device rename 7cf02a6 MyPi
'''
permission: 'user'
action: (params, options, done) ->
@ -215,8 +220,8 @@ exports.move =
Examples:
$ resin device move 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin device move 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 --application MyNewApp
$ resin device move 7cf02a6
$ resin device move 7cf02a6 --application MyNewApp
'''
permission: 'user'
options: [ commandOptions.optionalApplication ]

View File

@ -31,7 +31,7 @@ exports.list =
$ resin envs --application MyApp
$ resin envs --application MyApp --verbose
$ resin envs --device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin envs --device 7cf02a6
'''
options: [
commandOptions.optionalApplication
@ -130,7 +130,7 @@ exports.add =
$ resin env add EDITOR vim --application MyApp
$ resin env add TERM --application MyApp
$ resin env add EDITOR vim --device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin env add EDITOR vim --device 7cf02a6
'''
options: [
commandOptions.optionalApplication

View File

@ -30,8 +30,8 @@ module.exports =
Examples:
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828 --tail
$ resin logs 23c73a1
$ resin logs 23c73a1
'''
options: [
{

View File

@ -26,8 +26,8 @@ exports.set =
Examples:
$ resin note "My useful note" --device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ cat note.txt | resin note --device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin note "My useful note" --device 7cf02a6
$ cat note.txt | resin note --device 7cf02a6
'''
options: [
signature: 'device'

View File

@ -96,7 +96,7 @@ exports.configure =
Examples:
$ resin os configure ../path/rpi.img 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin os configure ../path/rpi.img 7cf02a6
'''
permission: 'user'
options: [