Class: Snapme::CLI::Options

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

Constant Summary collapse

DEFAULT_HOST =
'http://snapme.herokuapp.com'
DEFAULT_INTERVAL =

seconds

30

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(daemon: true, host: DEFAULT_HOST, interval: DEFAULT_INTERVAL, kill: false, show_version: false) ⇒ Options

Returns a new instance of Options.



11
12
13
14
15
16
17
# File 'lib/snapme/cli/options.rb', line 11

def initialize(daemon: true, host: DEFAULT_HOST, interval: DEFAULT_INTERVAL, kill: false, show_version: false)
  @daemon   = !!(daemon)
  @host     = host
  @interval = interval.to_i
  @kill     = kill
  @show_version = show_version
end

Instance Attribute Details

#daemonObject (readonly)

Returns the value of attribute daemon.



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

def daemon
  @daemon
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#intervalObject (readonly)

Returns the value of attribute interval.



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

def interval
  @interval
end

#killObject (readonly)

Returns the value of attribute kill.



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

def kill
  @kill
end

#show_versionObject (readonly)

Returns the value of attribute show_version.



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

def show_version
  @show_version
end

Class Method Details

.parse(args) ⇒ Object



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
# File 'lib/snapme/cli/options.rb', line 19

def self.parse(args)
  options = {}

  OptionParser.new do |opts|
    opts.banner = 'Usage: snapme [options]'

    opts.on('-h', '--help', 'Show this message') do
      puts opts
      exit
    end

    opts.on('-H', '--host [URL]', 'Snapme service web address') do |url|
      options[:host] = url
    end

    opts.on('-d', '--[no-]daemon', 'Daemonize process') do |daemon|
      options[:daemon] = daemon
    end

    opts.on('-i', '--interval [SECONDS]', 'Snapshot interval') do |seconds|
      options[:interval] = seconds
    end

    opts.on('-k', '--kill', 'Kill any snapme processes') do
      options[:kill] = true
    end

    opts.on('-v', '--version', 'Print snapme version') do
      options[:show_version] = true
    end
  end.parse!(args)

  new(options)
end