[Nitro] Generators

TRANS transfire at gmail.com
Thu Nov 3 13:26:11 EST 2005


On 11/3/05, George Moschovitis <george.moschovitis at gmail.com> wrote:
> Well, you have a point, let me think about this :)
>
> thanks for the comments,

No problem. Btw, rather then use cmdparser, check out facets'
shellcommand.rb. It's new and could use some improvements, but it's
very easy to use --very fluid with OOP practices. I haven;t documetned
it yetm but here's a simple example:

bin/mycommand:

 #!/usr/bin/ruby

 require 'facet/shellcommand'

 class MyCommand < ShellCommand

  # Options

  # verbose mode
  def __verbose ; $VERBOSE = true ; end
  alias_method :_V, :__verbose

  # option to display version
  def __version ; version ; end
  alias_method :_v, :__version

  # option to display help
  def __help ; help ; end
  alias_method :_h, :__help

  # Commands

  # default action
  def default
    help
  end

  # display version
  def version
    puts "MyCommand  v.1"
    exit 0
  end

  # display help
  def help
    puts "Help!"
    exit 0
  end

  def dosomething
    if $VERBOSE
      puts "Doing it loudly!"
    else
      puts "Doing it."
    end
  end

 end

 MyCommand.go

The on the command line:

 > mycommand dosomething
 Doing it.

 > mycommand -V dosomething
 Doing it loudly!

 > mycommand --verbose dosomething
 Doing it loudly!

 > mycommand help
 Help?

 > mycommand
 Help?

so on.

T.




More information about the Nitro-general mailing list