Class: BigBrother::Runner
- Inherits:
-
Object
- Object
- BigBrother::Runner
- Defined in:
- lib/big_brother/runner.rb
Class Method Summary collapse
- .config_commands(args) ⇒ Object
- .parse_cmd_line_args(args) ⇒ Object
- .parse_options ⇒ Object
- .print_version ⇒ Object
- .run(cmd_line_args, options = {}) ⇒ Object
- .set_output_stream(os_stream) ⇒ Object
- .stdout ⇒ Object
Class Method Details
.config_commands(args) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/big_brother/runner.rb', line 50 def self.config_commands(args) if args[1] == "get" return stdout.puts "needs a value to get" unless args[2] stdout.puts "#{args[2]} is \"\e[34m#{BigBrother::Settings.get(args[2])}\e[39m\"" elsif args[1] == "set" return stdout.puts "needs a key and value to set" unless (args[2] && args[3]) BigBrother::Settings.set(args[2], args[3]) stdout.puts "#{args[2]} set to \"\e[34m#{args[3]}\e[39m\"" else stdout.puts "Don't know how to use command #{args[1]}" end end |
.parse_cmd_line_args(args) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/big_brother/runner.rb', line 38 def self.parse_cmd_line_args(args) if args[0] == "json" stdout.puts BigBrother::Counter.count_commands_json elsif args[0] == "config" config_commands(args) elsif args[0] == "push" BigBrother::Pusher.push else stdout.puts "Big bro runner template" end end |
.parse_options ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/big_brother/runner.rb', line 17 def self. = {} OptionParser.new do |opts| opts. = "Usage: big-bro [options]" opts.on("-v", "--version", "Show version") do [:version] = true end opts.on("-h", "--help", "Show help") do [:help] = true end [:help_message] = opts.to_s end.parse! end |
.print_version ⇒ Object
34 35 36 |
# File 'lib/big_brother/runner.rb', line 34 def self.print_version stdout.puts BigBrother::VERSION end |
.run(cmd_line_args, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/big_brother/runner.rb', line 4 def self.run(cmd_line_args, = {}) BigBrother::Settings.load = .merge() = [:help_message] if [:version] print_version elsif [:help] || cmd_line_args.empty? || cmd_line_args[0] == "help" stdout.puts else parse_cmd_line_args(cmd_line_args) end end |
.set_output_stream(os_stream) ⇒ Object
63 64 65 |
# File 'lib/big_brother/runner.rb', line 63 def self.set_output_stream(os_stream) @output = os_stream end |
.stdout ⇒ Object
67 68 69 |
# File 'lib/big_brother/runner.rb', line 67 def self.stdout @output || STDOUT end |