From 082382d244ced0e224fc7b15b077d377f8d7afe4 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 22 Dec 2014 12:00:01 -0400 Subject: [PATCH] Implement examples and example commands --- lib/actions/examples.coffee | 37 +++++++++++++++++++++++++++++++++++++ lib/actions/index.coffee | 1 + lib/app.coffee | 23 +++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 lib/actions/examples.coffee diff --git a/lib/actions/examples.coffee b/lib/actions/examples.coffee new file mode 100644 index 00000000..019fef93 --- /dev/null +++ b/lib/actions/examples.coffee @@ -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' + ] diff --git a/lib/actions/index.coffee b/lib/actions/index.coffee index deff8fd5..3281ebf0 100644 --- a/lib/actions/index.coffee +++ b/lib/actions/index.coffee @@ -8,3 +8,4 @@ module.exports = preferences: require('./preferences') os: require('./os') help: require('./help') + examples: require('./examples') diff --git a/lib/app.coffee b/lib/app.coffee index 86237edb..33eaf061 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -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 ' + 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) ->