class Bicho::CLI::Command
Bicho
allows to easily add commands to the command line interface.
In order to create a command, add a class under Bicho::CLI::Commands
. Then you need to:
-
Add options, using a Optimist syntax
-
Implement do(global_opts, options, args)
You can use t.say to talk to the terminal including all HighLine features.
<tt> class Bicho::CLI::Commands::Hello < ::Bicho::CLI::Command
options do opt :monkey, "Use monkey mode", :default => true opt :text, "Name", :type => :string end def do(global_opts, opts, args) t.say("Hello") end
end </tt>
Attributes
parser[RW]
t[RW]
Public Class Methods
new()
click to toggle source
# File lib/bicho/cli/command.rb, line 64 def initialize @t = HighLine.new end
opt(*args)
click to toggle source
Gateway to Optimist
# File lib/bicho/cli/command.rb, line 69 def self.opt(*args) self.parser = Optimist::Parser.new unless parser parser.opt(*args) end
options() { || ... }
click to toggle source
DSL method to describe a command's option
# File lib/bicho/cli/command.rb, line 75 def self.options yield end
Public Instance Methods
do(_opts, _args)
click to toggle source
# File lib/bicho/cli/command.rb, line 92 def do(_opts, _args) raise "No implementation for #{self.class}" if self.class =~ /CommandTemplate/ end
parse_options()
click to toggle source
Called by the cli to get the options with current ARGV
# File lib/bicho/cli/command.rb, line 81 def parse_options self.class.parser = Optimist::Parser.new unless self.class.parser Optimist.with_standard_exception_handling(self.class.parser) do self.class.parser.parse ARGV end end
parser()
click to toggle source
# File lib/bicho/cli/command.rb, line 88 def parser self.class.parser end