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', permission: 'user',
primary: true, primary: true,
action: function(params, options, done) { action: function(params, options, done) {
var Promise, resin, visuals; var Promise, _, resin, visuals;
Promise = require('bluebird'); Promise = require('bluebird');
_ = require('lodash');
resin = require('resin-sdk'); resin = require('resin-sdk');
visuals = require('resin-cli-visuals'); visuals = require('resin-cli-visuals');
return Promise["try"](function() { return Promise["try"](function() {
@ -38,6 +39,10 @@ limitations under the License.
} }
return resin.models.device.getAll(); return resin.models.device.getAll();
}).tap(function(devices) { }).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'])); return console.log(visuals.table.horizontal(devices, ['id', 'uuid', 'name', 'device_type', 'application_name', 'status']));
}).nodeify(done); }).nodeify(done);
} }
@ -46,7 +51,7 @@ limitations under the License.
exports.info = { exports.info = {
signature: 'device <uuid>', signature: 'device <uuid>',
description: 'list a single device', 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', permission: 'user',
primary: true, primary: true,
action: function(params, options, done) { action: function(params, options, done) {
@ -97,7 +102,7 @@ limitations under the License.
exports.remove = { exports.remove = {
signature: 'device rm <uuid>', signature: 'device rm <uuid>',
description: 'remove a device', 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], options: [commandOptions.yes],
permission: 'user', permission: 'user',
action: function(params, options, done) { action: function(params, options, done) {
@ -118,7 +123,7 @@ limitations under the License.
exports.identify = { exports.identify = {
signature: 'device identify <uuid>', signature: 'device identify <uuid>',
description: 'identify a device with a 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', permission: 'user',
action: function(params, options, done) { action: function(params, options, done) {
var resin; var resin;
@ -130,7 +135,7 @@ limitations under the License.
exports.rename = { exports.rename = {
signature: 'device rename <uuid> [newName]', signature: 'device rename <uuid> [newName]',
description: 'rename a resin device', 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', permission: 'user',
action: function(params, options, done) { action: function(params, options, done) {
var Promise, _, events, form, resin; var Promise, _, events, form, resin;
@ -158,7 +163,7 @@ limitations under the License.
exports.move = { exports.move = {
signature: 'device move <uuid>', signature: 'device move <uuid>',
description: 'move a device to another application', 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', permission: 'user',
options: [commandOptions.optionalApplication], options: [commandOptions.optionalApplication],
action: function(params, options, done) { action: function(params, options, done) {

View File

@ -23,7 +23,7 @@ limitations under the License.
exports.list = { exports.list = {
signature: 'envs', signature: 'envs',
description: 'list all environment variables', 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: [ options: [
commandOptions.optionalApplication, commandOptions.optionalDevice, { commandOptions.optionalApplication, commandOptions.optionalDevice, {
signature: 'verbose', signature: 'verbose',
@ -91,7 +91,7 @@ limitations under the License.
exports.add = { exports.add = {
signature: 'env add <key> [value]', signature: 'env add <key> [value]',
description: 'add an environment variable', 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], options: [commandOptions.optionalApplication, commandOptions.optionalDevice],
permission: 'user', permission: 'user',
action: function(params, options, done) { action: function(params, options, done) {

View File

@ -19,7 +19,7 @@ limitations under the License.
module.exports = { module.exports = {
signature: 'logs <uuid>', signature: 'logs <uuid>',
description: 'show device logs', 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: [ options: [
{ {
signature: 'tail', signature: 'tail',

View File

@ -19,7 +19,7 @@ limitations under the License.
exports.set = { exports.set = {
signature: 'note <|note>', signature: 'note <|note>',
description: 'set a device 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: [ options: [
{ {
signature: 'device', signature: 'device',

View File

@ -92,7 +92,7 @@ limitations under the License.
exports.configure = { exports.configure = {
signature: 'os configure <image> <uuid>', signature: 'os configure <image> <uuid>',
description: 'configure an os image', 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', permission: 'user',
options: [ options: [
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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