Class: Barnyard2::Waldo::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/barnyard2waldo/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



13
14
15
16
17
18
19
20
21
22
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
52
53
54
55
56
57
58
59
60
61
# File 'lib/barnyard2waldo/cli.rb', line 13

def initialize
  options = {}
  options[:utc] = Barnyard2::Waldo::Defaults::UTC
  options[:bookmark] = Barnyard2::Waldo::Defaults::Bookmark

  opt_parser = OptionParser.new do |opt|
    opt.banner = "Usage: waldo [OPTIONS]"

    opt.on("-b", "--bookmark [waldofile]", "Bookmark file", "  Default: #{options[:bookmark]}") do |value|
      options[:bookmark] = value
    end

    opt.on("-z", "--zulu", "Print Zulu time (utc)", "  Default: #{options[:utc]}") do |value|
      options[:utc] = value
    end

    opt.separator "Options::"

    opt.on_tail("-h", "--help", "Display this screen") do
      puts opt_parser
      exit 0
    end

  end

  #Verify the options
  begin
  #  raise unless ARGV.size > 0
    opt_parser.parse!

  #If options fail display help
  #rescue Exception => e
  #  puts e.message
  #  puts e.backtrace.inspect
  rescue
    puts opt_parser
    exit
  end

  begin
      finder = Barnyard2::Waldo::Where.new(options[:bookmark])
      finder.utc = options[:utc]
      puts finder
  rescue Barnyard2::Waldo::WaldoFilePermissionsError
      abort "Waldo File Read Perrmission Error, check permissions on the bookmark file."
  rescue Barnyard2::Waldo::WaldoFileError
      abort "Waldo File Error, file may not exist."
  end
end

Class Method Details

.invokeObject



9
10
11
# File 'lib/barnyard2waldo/cli.rb', line 9

def self.invoke
  self.new
end