Class: Bixby::Client::App
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#global_options ⇒ Object
readonly
Returns the value of attribute global_options.
Instance Method Summary collapse
- #display_help ⇒ Object
-
#initialize ⇒ App
constructor
A new instance of App.
- #options ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ App
Returns a new instance of App.
18 19 20 21 |
# File 'lib/bixby-client/app.rb', line 18 def initialize = {} @commands = [] end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
16 17 18 |
# File 'lib/bixby-client/app.rb', line 16 def command @command end |
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
16 17 18 |
# File 'lib/bixby-client/app.rb', line 16 def commands @commands end |
#global_options ⇒ Object (readonly)
Returns the value of attribute global_options.
16 17 18 |
# File 'lib/bixby-client/app.rb', line 16 def end |
Instance Method Details
#display_help ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bixby-client/app.rb', line 53 def display_help puts "Usage: bixby [global options] command [command options] [arguments...]" puts puts "GLOBAL OPTIONS" puts .summarize puts puts "COMMANDS" commands.each do |c| puts " " + c.command_name + " - " + c.desc end exit 0 end |
#options ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bixby-client/app.rb', line 68 def ||= OptionParser.new do |opts| opts. = nil opts.on_tail("-v", "--verbose", "Enable verbose output") { [:verbose] = true } opts.on_tail("-h", "--help", "Display this help") { [:help] = true } end end |
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bixby-client/app.rb', line 23 def run begin .order!(ARGV) if [:help] then display_help() end rescue Exception => ex exit if ex.kind_of? SystemExit STDERR.puts "error: #{ex}" STDERR.puts STDERR.puts parser exit 1 end subcmd = ARGV.shift commands.each do |c| if c.match(subcmd) then ret = c.new.run(, ARGV) exit (ret || 0) end end # if we reached here, no cmd given, show help? display_help() end |