Implement example clone command

This commit is contained in:
Juan Cruz Viotti 2014-12-22 12:20:08 -04:00
parent 082382d244
commit 5ae3077df9
3 changed files with 74 additions and 16 deletions

View File

@ -1,4 +1,8 @@
async = require('async')
fs = require('fs')
path = require('path')
_ = require('lodash')
gitCli = require('git-cli')
resin = require('../resin')
permissions = require('../permissions/permissions')
ui = require('../ui')
@ -12,9 +16,10 @@ exports.list = permissions.user ->
resin.log.out ui.widgets.table.horizontal examplesData, (example) ->
delete example.description
delete example.name
example.author ?= 'Unknown'
return example
, [ 'ID', 'Name', 'Repository', 'Author' ]
, [ 'ID', 'Display Name', 'Repository', 'Author' ]
exports.info = permissions.user (params) ->
id = params.id - 1
@ -25,13 +30,38 @@ exports.info = permissions.user (params) ->
resin.errors.handle(error)
resin.log.out ui.widgets.table.vertical example, (example) ->
delete example.name
example.id = id
example.author ?= 'Unknown'
return example
, [
'ID'
'Name'
'Display Name'
'Description'
'Author'
'Repository'
]
exports.clone = permissions.user (params) ->
example = examplesData[params.id - 1]
if not example?
error = new Error("Unknown example: #{id}")
resin.errors.handle(error)
async.waterfall [
(callback) ->
exampleAbsolutePath = path.join(process.cwd(), example.name)
fs.exists exampleAbsolutePath, (exists) ->
return callback() if not exists
error = new Error("Directory exists: #{example.name}")
return callback(error)
(callback) ->
resin.log.info("Cloning #{example.display_name} to #{example.name}")
gitCli.Repository.clone(example.repository, example.name, callback)
], (error) ->
resin.errors.handle(error) if error?

View File

@ -506,6 +506,20 @@ capitano.command
'''
action: actions.examples.list
capitano.command
signature: 'example clone <id>'
description: 'clone an example application'
help: '''
Use this command to clone an example application to the current directory
This command outputs information about the cloning process.
Use `--quiet` to remove that output.
Example:
$ resin example clone 3
'''
action: actions.examples.clone
capitano.command
signature: 'example <id>'
description: 'list a single example application'

View File

@ -1,81 +1,95 @@
[
{
"name": "Node.js Starter Project",
"name": "basic-resin-node-project",
"display_name": "Node.js Starter Project",
"repository": "https://github.com/resin-io/basic-resin-node-project",
"description": "This is a simple Hello, World project for node.js designed to act as a basis for future work. It demonstrates how to install native Linux packages and configure your application."
},
{
"name": "Cimon",
"name": "cimon",
"display_name": "Cimon",
"repository": "https://bitbucket.org/efwe/cimon",
"description": "A simple tool for reading temperatures from a USB-enabled thermometer. This project is used as the backend to efwe's awesome temperature visualisation at 123k.de.",
"author": "efwe"
},
{
"name": "Digital Temperature Logger",
"name": "firebaseDTL",
"display_name": "Digital Temperature Logger",
"repository": "https://github.com/shaunmulligan/firebaseDTL",
"description": "A Firebase-backed Digital Temperature Logger allowing you to connect devices with multiple temperature sensors to a central cloud-based datastore.",
"author": "Shaun Mulligan"
},
{
"name": "Digitiser",
"name": "digitiser",
"display_name": "Digitiser",
"repository": "https://github.com/shaunmulligan/digitiser",
"description": "A tool for displaying integer values from a JSON endpoint on a MAX7219 7-segment display.",
"author": "Shaun Mulligan"
},
{
"name": "Example Pi Pins Application",
"name": "basic-gpio",
"display_name": "Example Pi Pins Application",
"repository": "https://github.com/shaunmulligan/basic-gpio",
"description": "A simple application which demonstrates the use of the Pi Pins library to interface with GPIO.",
"author": "Shaun Mulligan"
},
{
"name": "Google Coder",
"name": "coder",
"display_name": "Google Coder",
"repository": "https://github.com/resin-io/coder",
"description": "Resin.io-enabled version of Google's excellent Coder project which makes it easy to develop web projects on your device."
},
{
"name": "Hoversnap",
"name": "hoversnap",
"display_name": "Hoversnap",
"repository": "https://github.com/resin-io/hoversnap",
"description": "A tool for controlling a camera using a foot switch in order to capture shots in which people appear to be flying."
},
{
"name": "Pi Miner",
"name": "resin-piminer",
"display_name": "Pi Miner",
"repository": "https://github.com/csquared/resin-piminer",
"description": "A bitcoin miner for the Raspberry Pi.",
"author": "Chris Continanza"
},
{
"name": "Resin CCTV",
"name": "resin-cctv",
"display_name": "Resin CCTV",
"repository": "https://github.com/abresas/resin-cctv",
"description": "A project which allows you to use your devices as a CCTV camera system which hooks into Dropbox.",
"author": "Aleksis Brezas"
},
{
"name": "Resin Player",
"name": "resin_player",
"display_name": "Resin Player",
"repository": "https://bitbucket.org/lifeeth/resin_player/",
"description": "A project which allows you to play squeezebox media through your devices.",
"author": "Praneeth Bodduluri"
},
{
"name": "Salesforce Temperature Probe",
"name": "salesforceTemp",
"display_name": "Salesforce Temperature Probe",
"repository": "https://github.com/shaunmulligan/salesforceTemp",
"description": "Example application for interfacing with a temperature probe using Salesforce.com.",
"author": "Shaun Mulligan"
},
{
"name": "SMS to Speech",
"name": "sms2speech",
"display_name": "SMS to Speech",
"repository": "https://github.com/alexandrosm/sms2speech",
"description": "A simple tool which uses Twillio to read out incoming SMS messages.",
"author": "Alexandros Marinos"
},
{
"name": "Simple Digitiser Kiosk",
"name": "resin-kiosk",
"display_name": "Simple Digitiser Kiosk",
"repository": "https://bitbucket.org/lifeeth/resin-kiosk",
"description": "Displays values from a JSON endpoint on your browser in kiosk mode",
"author": "Praneeth Bodduluri"
},
{
"name": "Text to Speech Converter",
"name": "text2speech",
"display_name": "Text to Speech Converter",
"repository": "https://github.com/resin-io/text2speech",
"description": "A simple application that makes your device speak out loud."
}