Class: Smith::CommandBase
- Inherits:
-
Object
- Object
- Smith::CommandBase
- Includes:
- Logger
- Defined in:
- lib/smith/command_base.rb
Direct Known Subclasses
Smith::Commands::Acl, Smith::Commands::Agents, Smith::Commands::Commands, Smith::Commands::Dump, Smith::Commands::Firehose, Smith::Commands::Kill, Smith::Commands::List, Smith::Commands::Logger, Smith::Commands::Metadata, Smith::Commands::ObjectCount, Smith::Commands::Pop, Smith::Commands::Push, Smith::Commands::Restart, Smith::Commands::Rm, Smith::Commands::Start, Smith::Commands::Status, Smith::Commands::Stop, Smith::Commands::Subscribe, Smith::Commands::Top, Smith::Commands::Version
Defined Under Namespace
Classes: UnkownCommandError
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #banner(banner = nil, opts = {}) ⇒ Object
- #format_help(opts = {}) ⇒ Object
-
#initialize ⇒ CommandBase
constructor
A new instance of CommandBase.
- #parse_options(args) ⇒ Object
Methods included from Logger
Constructor Details
#initialize ⇒ CommandBase
Returns a new instance of CommandBase.
13 14 15 16 |
# File 'lib/smith/command_base.rb', line 13 def initialize @parser = Trollop::Parser.new end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/smith/command_base.rb', line 9 def @options end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
9 10 11 |
# File 'lib/smith/command_base.rb', line 9 def target @target end |
Instance Method Details
#banner(banner = nil, opts = {}) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/smith/command_base.rb', line 31 def (=nil, opts={}) if .nil? @banner else @banner = @parser.((opts[:no_template]) ? : ()) end end |
#format_help(opts = {}) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/smith/command_base.rb', line 23 def format_help(opts={}) StringIO.new.tap do |help| help.puts opts[:prefix] if opts[:prefix] @parser.educate(help) help.rewind end.read end |
#parse_options(args) ⇒ Object
18 19 20 21 |
# File 'lib/smith/command_base.rb', line 18 def (args) @options = @parser.parse(args) @target = args end |