Class: Bicho::CLI::Command
- Inherits:
-
Object
- Object
- Bicho::CLI::Command
- Includes:
- Logging
- Defined in:
- lib/bicho/cli/command.rb
Overview
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 Trollop 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
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>
Direct Known Subclasses
Class Attribute Summary (collapse)
-
+ (Object) parser
Returns the value of attribute parser.
Instance Attribute Summary (collapse)
-
- (Object) t
Returns the value of attribute t.
Class Method Summary (collapse)
-
+ (Object) opt(*args)
Gateway to Trollop.
-
+ (Object) options
DSL method to describe a command's option.
Instance Method Summary (collapse)
- - (Object) do(opts, args)
-
- (Command) initialize
constructor
A new instance of Command.
-
- (Object) parse_options
Called by the cli to get the options with current ARGV.
- - (Object) parser
Methods included from Logging
Constructor Details
- (Command) initialize
A new instance of Command
65 66 67 |
# File 'lib/bicho/cli/command.rb', line 65 def initialize @t = HighLine.new end |
Class Attribute Details
+ (Object) parser
Returns the value of attribute parser
61 62 63 |
# File 'lib/bicho/cli/command.rb', line 61 def parser @parser end |
Instance Attribute Details
- (Object) t
Returns the value of attribute t
63 64 65 |
# File 'lib/bicho/cli/command.rb', line 63 def t @t end |
Class Method Details
+ (Object) opt(*args)
Gateway to Trollop
70 71 72 73 |
# File 'lib/bicho/cli/command.rb', line 70 def self.opt(*args) self.parser = Trollop::Parser.new if not self.parser self.parser.opt(*args) end |
+ (Object) options
DSL method to describe a command's option
76 77 78 |
# File 'lib/bicho/cli/command.rb', line 76 def self. yield end |
Instance Method Details
- (Object) do(opts, args)
93 94 95 |
# File 'lib/bicho/cli/command.rb', line 93 def do(opts, args) raise RuntimeError, "No implementation for #{self.class}" if self.class =~ /CommandTemplate/ end |
- (Object) parse_options
Called by the cli to get the options with current ARGV
82 83 84 85 86 87 |
# File 'lib/bicho/cli/command.rb', line 82 def self.class.parser = Trollop::Parser.new if not self.class.parser opts = Trollop::with_standard_exception_handling(self.class.parser) do o = self.class.parser.parse ARGV end end |
- (Object) parser
89 90 91 |
# File 'lib/bicho/cli/command.rb', line 89 def parser self.class.parser end |