2014-11-27 13:10:51 +00:00
|
|
|
_ = require('lodash')
|
2014-11-26 19:05:00 +00:00
|
|
|
program = require('commander')
|
2014-11-27 13:10:51 +00:00
|
|
|
pluralize = require('pluralize')
|
|
|
|
indefiniteArticle = require('indefinite-article')
|
2014-11-26 19:05:00 +00:00
|
|
|
log = require('../log/log')
|
|
|
|
|
|
|
|
exports.getArgument = (name) ->
|
|
|
|
return program[name]
|
|
|
|
|
|
|
|
exports.setVersion = (version) ->
|
|
|
|
program.version(version)
|
|
|
|
|
|
|
|
# Set version command automatically
|
|
|
|
exports.addCommand 'version', 'show version', ->
|
|
|
|
log.out(version)
|
|
|
|
|
|
|
|
exports.addCommand = (command, description, action) ->
|
|
|
|
program
|
|
|
|
.command(command)
|
|
|
|
.description(description)
|
|
|
|
.action(action)
|
|
|
|
|
|
|
|
return program
|
|
|
|
|
|
|
|
exports.addOption = (option, description, coerceFunction) ->
|
|
|
|
program.option(option, description, coerceFunction)
|
|
|
|
|
2014-11-27 13:10:51 +00:00
|
|
|
exports.addResource = (name, displayName, actions = {}) ->
|
|
|
|
displayName ?= name
|
|
|
|
nameArticle = indefiniteArticle(displayName)
|
|
|
|
|
|
|
|
pluralizedName = pluralize(name)
|
|
|
|
pluralizedDisplayName = pluralize(displayName)
|
|
|
|
|
|
|
|
if _.isFunction(actions.create)
|
|
|
|
exports.addCommand("#{name}:create <name>", "create #{nameArticle} #{displayName}", actions.create)
|
|
|
|
|
|
|
|
if _.isFunction(actions.list)
|
|
|
|
exports.addCommand("#{pluralizedName}", "list all #{pluralizedDisplayName}", actions.list)
|
|
|
|
|
|
|
|
if _.isFunction(actions.info)
|
|
|
|
exports.addCommand("#{name} <id>", "list a single #{displayName}", actions.info)
|
|
|
|
|
|
|
|
if _.isFunction(actions.remove)
|
|
|
|
exports.addCommand("#{name}:rm <id>", "remove #{nameArticle} #{displayName}", actions.remove)
|
|
|
|
|
2014-11-26 19:05:00 +00:00
|
|
|
exports.parse = (argv) ->
|
|
|
|
program.parse(argv)
|