Class: EYCli::OptionsParser

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OptionsParser

Returns a new instance of OptionsParser.



11
12
13
# File 'lib/ey_cli/options_parser.rb', line 11

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/ey_cli/options_parser.rb', line 5

def options
  @options
end

Class Method Details

.parse(args) ⇒ Object



7
8
9
# File 'lib/ey_cli/options_parser.rb', line 7

def self.parse(args)
  new.parse(args)
end

Instance Method Details

#options_parserObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ey_cli/options_parser.rb', line 23

def options_parser
  ::OptionParser.new do |opts|
    opts.banner = 'ey_cli options:'
    opts.separator ' '

    opts.on('-v', '--version', 'display the current version') do
      puts "ey_cli #{EYCli::VERSION}"
      exit
    end

    opts.on('-a', '--account ACCOUNT_NAME') do ||
      options[:account] = 
    end

    opts.on('-p', '--app APP_NAME') do |app|
      options[:app] = app
    end

    opts.on('-e', '--environment ENVIRONMENT_NAME') do |environment|
      options[:environment] = environment
    end
  end
end

#parse(args) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/ey_cli/options_parser.rb', line 15

def parse(args)
  options_parser.parse!(args)
  options
rescue OptionParser::InvalidOption => e
  p e, options_parser
  exit 1
end