Class: TerraformLandscape::ArgumentsParser

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

Overview

Handles option parsing for the command line application.

Instance Method Summary collapse

Instance Method Details

#parse(args) ⇒ Hash

Parses command line options into an options hash.

Parameters:

  • args (Array<String>)

    arguments passed via the command line

Returns:

  • (Hash)

    parsed options



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/terraform_landscape/arguments_parser.rb', line 11

def parse(args)
  @options = {}
  @options[:command] = :pretty_print # Default command

  OptionParser.new do |parser|
    parser.banner = 'Usage: landscape [options] [plan-output-file]'

    add_info_options parser
  end.parse!(args)

  # Any remaining arguments are assumed to be the output file
  @options[:plan_output_file] = args.first

  @options
rescue OptionParser::InvalidOption => ex
  raise InvalidCliOptionError,
        "#{ex.message}\nRun `landscape --help` to " \
        'see a list of available options.'
end