Class: Trabox::Command::Parser
- Inherits:
-
Object
- Object
- Trabox::Command::Parser
- Defined in:
- lib/trabox/command/parser.rb
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parse! ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/trabox/command/parser.rb', line 6 def initialize @parser = OptionParser.new(nil, 20) do |o| o.version = VERSION o. = "\e[1mUsage: #{o.program_name}\e[0m <COMMAND> [OPTIONS]" o.on_tail('-h', '--help', 'Print help information') do $stdout.puts usage exit 0 end o.on_tail('-v', '--version', 'Print version information') end end |
Instance Method Details
#parse! ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/trabox/command/parser.rb', line 19 def parse! @parser.order! command = ARGV.shift return command unless command.nil? warn usage exit 1 end |
#usage ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/trabox/command/parser.rb', line 30 def usage <<~USAGE #{@parser.help} \e[1mCommands\e[0m: r, relay Relay events s, subscribe Subscribe events USAGE end |