Class: Mir::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/mir/options.rb

Constant Summary collapse

USAGE_BANNER =
"Usage: mir [options] [target]"

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



10
11
12
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
62
63
64
65
66
# File 'lib/mir/options.rb', line 10

def self.parse(args)
  if args.size < 1
    puts USAGE_BANNER
    exit
  end
  options = OpenStruct.new
  options.debug = false
  options.verbose = false
  options.settings_file = nil
  options.log_destination = STDOUT
  options.flush = false
  options.copy = false
  options.settings_path = nil
  
  opts_parser = OptionParser.new do |opts|
    opts.banner = USAGE_BANNER
    opts.separator ""
    opts.separator "Specific options:"
    
    opts.on("--flush", "Flush the file index") do
      options.flush = true
    end
    
    opts.on("-c", "--copy", "Copy the remote files to target") do
      options.copy = true
    end
    
    opts.on("-d", "--debug", "Enable debug logging") do
      options.debug = true
    end
    
    opts.on("--settings", String, "The YAML settings file") do |path|
      options.settings_path = path
    end
    
    opts.on("-l", "--log-path LOG_FILE", String, "Location for storing execution logs") do |log_file|
      options.log_destination = log_file
    end
    
    opts.on("-v", "--verbose", "Run verbosely") do |v|
      options.verbose = true
    end
    
    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
    
    opts.on_tail("--version", "Show version") do
      puts Mir.version
      exit
    end
  end
  
  opts_parser.parse!(args)
  options
end