Class: Prepd::Cli::OptionsParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ OptionsParser

Returns a new instance of OptionsParser.



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

def initialize(options = nil)
  self.options = options || {}
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#parseObject



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
38
39
40
# File 'lib/prepd/cli/options_parser.rb', line 11

def parse
  optparse = OptionParser.new do |opts|
    opts.on('-c', '--client [OPT]', 'Client') do |value|
      options['CLIENT'] = value
    end

    opts.on( '-d', '--data_dir [OPT]', 'Data directory' ) do |value|
      options['DATA_DIR'] = value
    end

    opts.on( '-p', '--project [OPT]', 'Project' ) do |value|
      options['PROJECT'] = value
    end

    opts.on('-h', '--help', 'Display this screen') do
      puts opts
      exit
    end

    opts.on('-n', '--no-op', 'Show what would happen but do not execute') do
      options.no_op = true
    end

    opts.on('-v', '--verbose', 'Display additional information') do
      options.verbose = true
    end
  end
  optparse.parse!
  options
end