Method: OptParseBuilder.build_parser
- Defined in:
- lib/opt_parse_builder.rb
.build_parser {|parser_builder| ... } ⇒ Object
Create a new parser. If called without a block, returns a parser than you can then add arguments to:
arg_parser = OptParseBuilder.build_parser
arg_parser.add do |arg|
arg.key :force
arg.on "--force", "Force dangerous operation"
end
If called with a block, yields itself to the block:
arg_parser = OptParseBuilder.build_parser do |args|
args.add do |arg|
arg.key :force
arg.on "--force", "Force dangerous operation"
end
end
Note that the parser constructed using the block form can still be added onto:
arg_parser.add do |arg|
arg.key :size
arg.on "--size=N", Integer, "File size in bytes"
end
91 92 93 94 95 |
# File 'lib/opt_parse_builder.rb', line 91 def self.build_parser parser_builder = ParserBuilder.new yield parser_builder if block_given? parser_builder.parser end |