2014-12-22 16:20:08 +00:00
|
|
|
async = require('async')
|
|
|
|
fs = require('fs')
|
|
|
|
path = require('path')
|
2014-12-22 16:00:01 +00:00
|
|
|
_ = require('lodash')
|
2015-01-08 12:04:37 +00:00
|
|
|
resin = require('resin-sdk')
|
2015-01-21 13:50:19 +00:00
|
|
|
visuals = require('resin-cli-visuals')
|
2015-03-12 15:24:36 +00:00
|
|
|
vcs = require('resin-vcs')
|
2014-12-22 16:00:01 +00:00
|
|
|
examplesData = require('../data/examples.json')
|
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
exports.list =
|
|
|
|
signature: 'examples'
|
|
|
|
description: 'list all example applications'
|
|
|
|
help: '''
|
|
|
|
Use this command to list available example applications from resin.io
|
|
|
|
|
|
|
|
Example:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin examples
|
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: ->
|
2015-01-15 17:10:14 +00:00
|
|
|
examplesData = _.map examplesData, (example, index) ->
|
|
|
|
example.id = index + 1
|
|
|
|
return example
|
|
|
|
|
|
|
|
examplesData = _.map examplesData, (example) ->
|
|
|
|
example.author ?= 'Unknown'
|
|
|
|
return example
|
|
|
|
|
2015-01-21 13:50:19 +00:00
|
|
|
console.log visuals.widgets.table.horizontal examplesData, [
|
2015-01-22 17:06:02 +00:00
|
|
|
'id'
|
|
|
|
'display_name'
|
|
|
|
'repository'
|
|
|
|
'author'
|
2015-01-15 17:10:14 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
exports.info =
|
|
|
|
signature: 'example <id>'
|
|
|
|
description: 'list a single example application'
|
|
|
|
help: '''
|
|
|
|
Use this command to show information of a single example application
|
|
|
|
|
|
|
|
Example:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin example 3
|
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-01-15 17:10:14 +00:00
|
|
|
id = params.id - 1
|
|
|
|
example = examplesData[id]
|
|
|
|
|
|
|
|
if not example?
|
|
|
|
return done(new Error("Unknown example: #{id}"))
|
|
|
|
|
|
|
|
example.id = id
|
2014-12-22 16:00:01 +00:00
|
|
|
example.author ?= 'Unknown'
|
|
|
|
|
2015-01-21 13:50:19 +00:00
|
|
|
console.log visuals.widgets.table.vertical example, [
|
2015-01-22 17:06:02 +00:00
|
|
|
'id'
|
|
|
|
'display_name'
|
|
|
|
'description'
|
|
|
|
'author'
|
|
|
|
'repository'
|
2015-01-15 17:10:14 +00:00
|
|
|
]
|
2014-12-22 16:00:01 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
return done()
|
2015-01-06 17:07:35 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
exports.clone =
|
|
|
|
signature: 'example clone <id>'
|
|
|
|
description: 'clone an example application'
|
|
|
|
help: '''
|
|
|
|
Use this command to clone an example application to the current directory
|
2014-12-22 16:20:08 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
This command outputs information about the cloning process.
|
|
|
|
Use `--quiet` to remove that output.
|
2015-01-15 13:47:17 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
Example:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin example clone 3
|
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-01-15 17:10:14 +00:00
|
|
|
example = examplesData[params.id - 1]
|
2014-12-22 16:20:08 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
if not example?
|
|
|
|
return done(new Error("Unknown example: #{id}"))
|
2014-12-22 16:20:08 +00:00
|
|
|
|
2015-03-12 15:24:36 +00:00
|
|
|
currentDirectory = process.cwd()
|
|
|
|
console.info("Cloning #{example.display_name} to #{currentDirectory}")
|
|
|
|
vcs.clone(example.repository, currentDirectory, done)
|