Class: Sensu::Translator::CLI
- Inherits:
-
Object
- Object
- Sensu::Translator::CLI
- Defined in:
- lib/sensu/translator/cli.rb
Class Method Summary collapse
-
.read(arguments = ARGV) ⇒ Hash
Parse CLI arguments using Ruby stdlib ‘optparse`.
Class Method Details
.read(arguments = ARGV) ⇒ Hash
Parse CLI arguments using Ruby stdlib ‘optparse`. This method provides Sensu Translator with process options (eg. config directory), and can provide users with information, such as the Translator version.
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 |
# File 'lib/sensu/translator/cli.rb', line 13 def self.read(arguments=ARGV) = { :output_dir => "/tmp/sensu_go", :namespace => "default" } if File.exist?("/etc/sensu/config.json") [:config_file] = "/etc/sensu/config.json" end if Dir.exist?("/etc/sensu/conf.d") [:config_dirs] = ["/etc/sensu/conf.d"] end 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 Sensu::Translator::VERSION exit end opts.on("-c", "--config FILE", "Sensu 1.x JSON config FILE. Default: /etc/sensu/config.json (if exists)") do |file| [:config_file] = file end opts.on("-d", "--config_dir DIR[,DIR]", "DIR or comma-delimited DIR list for Sensu 1.x JSON config files. Default: /etc/sensu/conf.d (if exists)") do |dir| [:config_dirs] = dir.split(",") end opts.on("-o", "--output_dir DIR", "Sensu 2.0 config output DIR. Default: /tmp/sensu_go") do |dir| [:output_dir] = dir end opts.on("-n", "--namespace NAMESPACE", "Sensu 2.0 Namespace. Default: default") do |namespace| [:namespace] = namespace end end optparse.parse!(arguments) end |