tower-archive / tower

UNMAINTAINED - Small components for building apps, manipulating data, and automating a distributed infrastructure.
http://tower.github.io
MIT License
1.79k stars 120 forks source link

Command help info should be displayed when generate/destroy commands are run outside a tower app. #371

Closed btbinhtran closed 10 years ago

btbinhtran commented 11 years ago

Let's say I have an app named coolapp:

Generate and destroy commands are actually trying to update files that are within a tower app when they are executed outside of a tower app.

I think we can refactor and add 2 more program hooks into the commander library like in tower/packages/tower-command/server/command.coffee:

require('commander').Command.prototype.helpIfNecessary = (length) ->
    if (length && @rawArgs.length == length) || @rawArgs.indexOf('--help') > -1 || @rawArgs.indexOf('-h') > -1
    @outputHelp()
    process.exit()

In tower/packages/tower-command/server/command.coffee, I can add and refactor:

Command = require('commander').Command

Command.prototype.helpIfNecessary = (length) ->
    if (length && @rawArgs.length == length) || @rawArgs.indexOf('--help') > -1 || @rawArgs.indexOf('-h') > -1
        @outputHelp()
        process.exit()

Command.prototype.helpIf = (conditionalCallback) ->
    if conditionalCallback()
      @outputHelp()
      process.exit()

Command.prototype.helpIfOutAppRoot = ->
    @helpIf => return Tower.root == Tower.normalize('/')

What are your thoughts?