Class: TTYCoke::CLI

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/ttycoke/cli.rb

Instance Method Summary collapse

Methods included from Log

#log_check_child_exit_status, #log_debug, #log_error, #log_rescue

Instance Method Details

#parse_options(argv) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ttycoke/cli.rb', line 7

def parse_options argv
  log_rescue(self, __method__, caller) {
    @opts=nil
    @opts = OptionParser.new do |o|
      o.banner = "Usage: ttycoke [-v] [-h] command [<args>]"
      o.separator ""
      o.on("-h", "--help", "Print this help.") {
        return $stderr.puts(@opts)
      }
      o.on("-v", "--version", "Print version.") {
        return $stderr.puts(TTYCoke::Version::STRING)
      }
      o.on("-d", "--debug", "Enable debug output.") {
        $DEBUG = true
      }
      o.separator ""
    end
    @opts.parse!(argv) rescue return $stderr.puts(@opts)
    if argv.empty?
      $stderr.puts(@opts)
    else
      TTYCoke::Run.new(argv)
    end
  }
end