Class: Snapme::CLI::Options
- Inherits:
-
Object
- Object
- Snapme::CLI::Options
- Defined in:
- lib/snapme/cli/options.rb
Constant Summary collapse
- DEFAULT_HOST =
'http://snapme.herokuapp.com'- DEFAULT_INTERVAL =
seconds
30
Instance Attribute Summary collapse
-
#daemon ⇒ Object
readonly
Returns the value of attribute daemon.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#kill ⇒ Object
readonly
Returns the value of attribute kill.
-
#show_version ⇒ Object
readonly
Returns the value of attribute show_version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(daemon: true, host: DEFAULT_HOST, interval: DEFAULT_INTERVAL, kill: false, show_version: false) ⇒ Options
constructor
A new instance of Options.
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
#daemon ⇒ Object (readonly)
Returns the value of attribute daemon.
9 10 11 |
# File 'lib/snapme/cli/options.rb', line 9 def daemon @daemon end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
9 10 11 |
# File 'lib/snapme/cli/options.rb', line 9 def host @host end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
9 10 11 |
# File 'lib/snapme/cli/options.rb', line 9 def interval @interval end |
#kill ⇒ Object (readonly)
Returns the value of attribute kill.
9 10 11 |
# File 'lib/snapme/cli/options.rb', line 9 def kill @kill end |
#show_version ⇒ Object (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) = {} OptionParser.new do |opts| opts. = '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| [:host] = url end opts.on('-d', '--[no-]daemon', 'Daemonize process') do |daemon| [:daemon] = daemon end opts.on('-i', '--interval [SECONDS]', 'Snapshot interval') do |seconds| [:interval] = seconds end opts.on('-k', '--kill', 'Kill any snapme processes') do [:kill] = true end opts.on('-v', '--version', 'Print snapme version') do [:show_version] = true end end.parse!(args) new() end |