Sha256: 2c89595c13e1adf1b1c4971b008537c182c2723ebdcf876a5930f143992f5006

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require "optparse"
require "sensu/run/version"
require "sensu/run/check"
require "sensu/run/api_client"

module Sensu
  module Run
    def self.read_cli_opts(arguments=ARGV)
      options = {}

      optparse = OptionParser.new do |opts|
        opts.on("-h", "--help", "Display this message") do
          puts opts
          exit
        end
        opts.on("-V", "--version", "Display version") do
          puts VERSION
          exit
        end
        opts.on("-n", "--namespace NAME", "Sensu Go namespace") do |name|
          options[:namespace] = name
        end
        opts.on("-c", "--check-name NAME", "Sensu Go check name") do |name|
          options[:check_name] = name
        end
        opts.on("-e", "--entity-name NAME", "Sensu Go entity name") do |name|
          options[:entity_name] = name
        end
        opts.on("-t", "--check-timeout SECONDS", "Sensu Go check execution timeout") do |timeout|
          options[:timeout] = timeout.to_i
        end
        opts.on("-T", "--check-ttl SECONDS", "Sensu Go check TTL") do |ttl|
          options[:ttl] = ttl.to_i
        end
        opts.on("-H", "--handlers NAME[,NAME]", "Sensu Go event handlers") do |handlers|
          options[:handlers] = handlers.split(",")
        end
        opts.on("-b", "--backends URL[,URL]", "URL or comma-delimited list of Sensu Go Backend API URLs") do |backends|
          options[:backends] = backends.split(",")
        end
        opts.on("-k", "--api-key KEY", "Sensu Go Backend API key") do |key|
          options[:api_key] = key
        end
      end

      optparse.parse!(arguments)
      options[:command] = arguments.join(" ")

      options
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sensu-run-0.1.0 lib/sensu/run.rb