Class: CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/command_line.rb

Constant Summary collapse

VALID_OUTPUT_FORMATS =
[:graphic, :json, :yaml, :csv].freeze

Class Method Summary collapse

Class Method Details

.parse!(options) ⇒ Object



6
7
8
9
10
11
12
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
# File 'lib/command_line.rb', line 6

def self.parse!(options)
  OptionParser.new do |opts|
    opts.banner = 'Usage: probium my_policy.yaml [options]'

    opts.on('-o', '--output-format=FORMAT', 'Format in which to display policy report (graphic, json, yaml, csv)') do |of|
      if VALID_OUTPUT_FORMATS.include?(f = of.downcase.to_sym)
        options[:output_format] = f
      else
        options[:message] =  "Invalid output-format '#{of}'. Options are #{VALID_OUTPUT_FORMATS.join(', ')}"
        options[:state] = :fail
      end
    end

    opts.on('-e', '--extension-dir=PATH', 'Location of extension files') do |path|
      options[:extensions_path] = path
    end

    opts.on('-d', '--debug', 'Enable debug output') do
      options[:debug] = true
    end

    opts.on('--no-color', 'Disable color in output') do
      options[:color] = false
    end

    opts.on('-h', '--help', 'Print this help') do
      options[:message] = opts
      options[:state] = :exit
    end
  end.parse!
  options
end

.policy!Object



39
40
41
42
43
44
45
# File 'lib/command_line.rb', line 39

def self.policy!
  policy_file = ARGV.shift
  unless policy_file
    raise StandardError, 'Missing required policy file as argument'
  end
  policy_file
end