Class: Sapristi::ArgumentsParser

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArgumentsParser

Returns a new instance of ArgumentsParser.



8
9
10
# File 'lib/sapristi/arguments_parser.rb', line 8

def initialize
  @args = OpenStruct.new
end

Class Method Details

.build_parser(args) ⇒ Object



17
18
19
20
21
# File 'lib/sapristi/arguments_parser.rb', line 17

def self.build_parser(args)
  OptionParser.new do |opts|
    ArgumentsParser.populate_options(opts, args)
  end
end

.populate_options(opts, args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/sapristi/arguments_parser.rb', line 23

def self.populate_options(opts, args)
  opts.banner = 'Usage: sapristi [options]'
  opts.on('-v', '--verbose', 'Verbose mode') { |value| args.verbose = value }
  opts.on('--dry-run', 'Dry run') { |value| args.dry = value }
  opts.on('-f', '--file FILE', 'Read configuration from FILE') { |file| args.file = file }
  opts.on('-h', '--help', 'Prints this help') do
    puts opts
    exit
  end
end

Instance Method Details

#parse(options) ⇒ Object



12
13
14
15
# File 'lib/sapristi/arguments_parser.rb', line 12

def parse(options)
  ArgumentsParser.build_parser(@args).parse!(options)
  @args
end