Sha256: fb45531a717bb12068ea265ee5bf605297fb57e3f48cb709b110e40ed8484e46

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

require 'optparse'

module Snapme
  module CLI
    class Options
      DEFAULT_HOST     = 'http://snapme.herokuapp.com'
      DEFAULT_INTERVAL = 30 #seconds

      attr_reader :daemon, :host, :interval, :kill, :show_version

      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

      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
snapme-0.2.2 lib/snapme/cli/options.rb