Implement examples and example <id> commands

This commit is contained in:
Juan Cruz Viotti 2014-12-22 12:00:01 -04:00
parent 0a13fb54b5
commit 082382d244
3 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,37 @@
_ = require('lodash')
resin = require('../resin')
permissions = require('../permissions/permissions')
ui = require('../ui')
examplesData = require('../data/examples.json')
exports.list = permissions.user ->
examplesData = _.map examplesData, (example, index) ->
example.id = index + 1
return example
resin.log.out ui.widgets.table.horizontal examplesData, (example) ->
delete example.description
example.author ?= 'Unknown'
return example
, [ 'ID', 'Name', 'Repository', 'Author' ]
exports.info = permissions.user (params) ->
id = params.id - 1
example = examplesData[id]
if not example?
error = new Error("Unknown example: #{id}")
resin.errors.handle(error)
resin.log.out ui.widgets.table.vertical example, (example) ->
example.id = id
example.author ?= 'Unknown'
return example
, [
'ID'
'Name'
'Description'
'Author'
'Repository'
]

View File

@ -8,3 +8,4 @@ module.exports =
preferences: require('./preferences')
os: require('./os')
help: require('./help')
examples: require('./examples')

View File

@ -494,6 +494,29 @@ capitano.command
}
]
# ---------- Examples Module ----------
capitano.command
signature: 'examples'
description: 'list all example applications'
help: '''
Use this command to list available example applications from resin.io
Example:
$ resin examples
'''
action: actions.examples.list
capitano.command
signature: 'example <id>'
description: 'list a single example application'
help: '''
Use this command to show information of a single example application
Example:
$ resin example 3
'''
action: actions.examples.info
cli = capitano.parse(process.argv)
changeProjectDirectory = (directory) ->