# http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.htmlrequire'optparse'moduleRSpec::CoreclassParserdefself.parse!(args)new.parse!(args)endclass<<selfalias_method:parse,:parse!enddefparse!(args)return{}ifargs.empty?ifargs.include?("--formatter")RSpec.deprecate("the --formatter option","-f or --format")args[args.index("--formatter")]="--format"endoptions={}parser(options).parse!(args)optionsendalias_method:parse,:parse!defparser(options)OptionParser.newdo|parser|parser.banner="Usage: rspec [options] [files or directories]\n\n"parser.on('-b','--backtrace','Enable full backtrace')do|o|options[:full_backtrace]=trueendparser.on('-c','--[no-]color','--[no-]colour','Enable color in the output')do|o|options[:color_enabled]=oendparser.on('-d','--debugger','Enable debugging')do|o|options[:debug]=trueendparser.on('-e','--example STRING',"Run examples whose full nested names include STRING")do|o|options[:full_description]=Regexp.compile(Regexp.escape(o))endparser.on('-f','--format FORMATTER','Choose a formatter',' [p]rogress (default - dots)',' [d]ocumentation (group and example names)',' [h]tml',' [t]extmate',' custom formatter class name')do|o|options[:formatters]||=[]options[:formatters]<<[o]endparser.on('-o','--out FILE','Write output to a file instead of STDOUT. This option applies','to the previously specified --format, or the default format if','no format is specified.')do|o|options[:formatters]||=[['progress']]options[:formatters].last<<oendparser.on_tail('-h','--help',"You're looking at it.")doputsparserexitendparser.on('-I DIRECTORY','specify $LOAD_PATH directory (may be used more than once)')do|dir|options[:libs]||=[]options[:libs]<<direndparser.on('-l','--line_number LINE','Specify the line number of a single example to run')do|o|options[:line_number]=oendparser.on('-O','--options PATH','Specify the path to an options file')do|path|options[:custom_options_file]=pathendparser.on('-p','--profile','Enable profiling of examples with output of the top 10 slowest examples')do|o|options[:profile_examples]=oendparser.on('-P','--pattern PATTERN','Load files those matching this pattern. Default is "spec/**/*_spec.rb"')do|o|options[:pattern]=oendparser.on('-r','--require PATH','Require a file')do|path|options[:requires]||=[]options[:requires]<<pathendparser.on('-v','--version','Show version')doputsRSpec::Core::Version::STRINGexitendparser.on('-X','--drb','Run examples via DRb')do|o|options[:drb]=trueendparser.on('--configure COMMAND','Generate configuration files')do|cmd|CommandLineConfiguration.new(cmd).runexitendparser.on('--drb-port [PORT]','Port to connect to on the DRb server')do|o|options[:drb_port]=o.to_iendparser.on('--fail-fast','Abort the run on first failure.')do|o|options[:fail_fast]=trueendparser.on('-t','--tag TAG[:VALUE]','Run examples with the specified tag','To exclude examples, add ~ before the tag (e.g. ~slow)','(TAG is always converted to a symbol)')do|tag|filter_type=tag=~/^~/?:exclusion_filter::filtername,value=tag.gsub(/^(~@|~|@)/,'').split(':')name=name.to_symvalue=trueifvalue.nil?options[filter_type]||={}options[filter_type][name]=valueendparser.on('--tty','Used internally by rspec when sending commands to other processes')do|o|options[:tty]=trueendendendendend