Class: GreenPepper::ArgumentParser
- Inherits:
-
Object
- Object
- GreenPepper::ArgumentParser
- Defined in:
- lib/greenpepper/argumentparser.rb
Instance Attribute Summary collapse
-
#execution_context ⇒ Object
readonly
Returns the value of attribute execution_context.
-
#writer_context ⇒ Object
readonly
Returns the value of attribute writer_context.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ ArgumentParser
constructor
A new instance of ArgumentParser.
- #parse_args(argv) ⇒ Object
Constructor Details
#initialize(args) ⇒ ArgumentParser
Returns a new instance of ArgumentParser.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/greenpepper/argumentparser.rb', line 11 def initialize(args) @execution_context = {:html_results_output => true, :xml_output => false, :console_output => "", :repository => nil, :load_path => Array.new, :input_document => nil, :output_document => nil} @writer_context = {:no_exception_stack => false} if args.empty? @execution_context[:console_output] = ArgumentParser.usage else @parsed = parse_args args end end |
Instance Attribute Details
#execution_context ⇒ Object (readonly)
Returns the value of attribute execution_context.
9 10 11 |
# File 'lib/greenpepper/argumentparser.rb', line 9 def execution_context @execution_context end |
#writer_context ⇒ Object (readonly)
Returns the value of attribute writer_context.
9 10 11 |
# File 'lib/greenpepper/argumentparser.rb', line 9 def writer_context @writer_context end |
Class Method Details
.usage ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/greenpepper/argumentparser.rb', line 102 def self.usage str = "Usage: ruby greenpepper.rb input_document " str += "[ouput_document] [options]\n\n" str += "--help Display the help.\n" str += "--version Output version information.\n" str += "-r CLASS;ARGS The url of the repository of the" + str += " specifications.\n" str += "--no-html-results This option will not print result in output.\n" str += "--xml [output_document] Generate XML report (default is plain text)." str += " If output_document is specified, the xml report will outputed" str += " in the specified file.\n" str += "--no-exception-stack Disable outputting of exception stack when" str += " execution exception are raised.\n" str += "--load_path path1 [pathX] List of path to include for execution." str end |
Instance Method Details
#parse_args(argv) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/greenpepper/argumentparser.rb', line 29 def parse_args(argv) argv = [argv] unless argv.is_a? Array args = argv.dup arg_regex = /^\s*-.+\s*/ return false if args.size < 1 while arg = args.shift if arg =~ arg_regex case arg when "--no-html-results" #Not in doc @execution_context[:html_results_output] = false when "--no-exception-stack" @writer_context[:no_exception_stack] = true when "--help" @execution_context[:console_output] = ArgumentParser.usage return when "--version" @execution_context[:console_output] = "#{$APP_NAME} version : #{$VERSION}" return when "--xml" @execution_context[:xml_output] = true @execution_context[:output_document] = args.shift unless args[0] =~ arg_regex || args.size == 0 #Output to the specified output. If no specified output, #outputting to INPUTFILENAME_output.xml when "-r" if args[0] =~ arg_regex || args.size == 0 @execution_context[:console_output] = ArgumentParser.usage return else @execution_context[:repository] = args.shift end when "--loadpath" if args[0] =~ arg_regex || args.size == 0 @execution_context[:console_output] = ArgumentParser.usage return else while !(args[0] =~ arg_regex || args.size == 0) @execution_context[:load_path] << args.shift end end else @execution_context[:console_output] = "#{arg.to_s} option is not recognize\n#{ArgumentParser.usage}" return end else if @execution_context[:input_document].nil? @execution_context[:input_document] = arg elsif @execution_context[:output_document].nil? @execution_context[:output_document] = arg end end end if (@execution_context[:input_document].nil?) @execution_context[:console_output] = ArgumentParser.usage return else if(@execution_context[:output_document].nil?) extension_name = File.extname @execution_context[:input_document] base_name = File.basename @execution_context[:input_document] base_name.gsub!(extension_name, "") extension_name = '.xml' if @execution_context[:xml_output] @execution_context[:output_document] = "#{base_name}_output#{extension_name}" end end end |