Class: Sapristi::ArgumentsParser
- Inherits:
-
Object
- Object
- Sapristi::ArgumentsParser
- Defined in:
- lib/sapristi/arguments_parser.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ ArgumentsParser
constructor
A new instance of ArgumentsParser.
- #parse(options) ⇒ Object
Constructor Details
#initialize ⇒ ArgumentsParser
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.(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.(opts, args) opts. = '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() ArgumentsParser.build_parser(@args).parse!() @args end |