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 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
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
Bicho::CLI::Commands::Attachments, Bicho::CLI::Commands::History, Bicho::CLI::Commands::Reopen, Bicho::CLI::Commands::Search, Bicho::CLI::Commands::Show, Bicho::CLI::Commands::Version
Class Attribute Summary collapse
-
.parser ⇒ Object
Returns the value of attribute parser.
Instance Attribute Summary collapse
-
#t ⇒ Object
Returns the value of attribute t.
Class Method Summary collapse
-
.opt(*args) ⇒ Object
Gateway to Optimist.
-
.options ⇒ Object
DSL method to describe a command’s option.
Instance Method Summary collapse
- #do(_opts, _args) ⇒ Object
-
#initialize ⇒ Command
constructor
A new instance of Command.
-
#parse_options ⇒ Object
Called by the cli to get the options with current ARGV.
- #parser ⇒ Object
Methods included from Logging
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
64 65 66 |
# File 'lib/bicho/cli/command.rb', line 64 def initialize @t = HighLine.new end |
Class Attribute Details
.parser ⇒ Object
Returns the value of attribute parser.
60 61 62 |
# File 'lib/bicho/cli/command.rb', line 60 def parser @parser end |
Instance Attribute Details
#t ⇒ Object
Returns the value of attribute t.
62 63 64 |
# File 'lib/bicho/cli/command.rb', line 62 def t @t end |
Class Method Details
.opt(*args) ⇒ Object
Gateway to Optimist
69 70 71 72 |
# File 'lib/bicho/cli/command.rb', line 69 def self.opt(*args) self.parser = Optimist::Parser.new unless parser parser.opt(*args) end |
.options ⇒ Object
DSL method to describe a command’s option
75 76 77 |
# File 'lib/bicho/cli/command.rb', line 75 def self. yield end |
Instance Method Details
#do(_opts, _args) ⇒ Object
92 93 94 |
# 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 ⇒ Object
Called by the cli to get the options with current ARGV
81 82 83 84 85 86 |
# File 'lib/bicho/cli/command.rb', line 81 def 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 ⇒ Object
88 89 90 |
# File 'lib/bicho/cli/command.rb', line 88 def parser self.class.parser end |