mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-31 08:25:36 +00:00
Implement examples and example <id> commands
This commit is contained in:
parent
0a13fb54b5
commit
082382d244
37
lib/actions/examples.coffee
Normal file
37
lib/actions/examples.coffee
Normal 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'
|
||||
]
|
@ -8,3 +8,4 @@ module.exports =
|
||||
preferences: require('./preferences')
|
||||
os: require('./os')
|
||||
help: require('./help')
|
||||
examples: require('./examples')
|
||||
|
@ -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) ->
|
||||
|
Loading…
x
Reference in New Issue
Block a user