Geminstaller C0 Coverage Information - RCov

lib/geminstaller/arg_parser.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/geminstaller/arg_parser.rb 171 145
100.00%
100.00%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 module GemInstaller
2   class ArgParser
3     attr_reader :output
4     attr_writer :options
5     
6     VALID_GEMINSTALLER_OUTPUT_FLAGS = [:none,:error,:install,:info,:commandecho,:debug,:all]
7     VALID_RUBYGEMS_OUTPUT_FLAGS = [:none,:stdout,:stderr,:all]
8     
9     def parse(args = [])
10       raise GemInstaller::GemInstallerError.new("Args must be passed as an array.") unless args.nil? or args.respond_to? :shift
11       args = ARGV if args.nil? || args == []
12       # check to see if args is an array of (nothing but) gems here...  if so, set args as [@options[:gems] and return
13 
14       raise GemInstaller::GemInstallerError.new("Error: An array of options to be populated must be injected prior to calling GemInstaller::ArgParser.parse") unless @options
15       @options[:exceptions] = false
16       @options[:redirect_stderr_to_stdout] = false
17       @options[:silent] = false
18       @options[:sudo] = false
19       @options[:geminstaller_output] = [:error,:install,:info]
20       @options[:rubygems_output] = [:stderr]
21       @output = ""
22       @unparsed_geminstaller_output_flags = nil
23       @unparsed_rubygems_output_flags = nil
24       opts = OptionParser.new do |opts|
25         opts.banner = "Usage: geminstaller [options]"
26 
27         opts.separator ""
28 
29         config_msg =                         "Comma-delimited path(s) to GemInstaller config file(s)."
30         exceptions_msg =                     "Raise any exceptions, rather than just printing them and exiting\n" +
31         "                                     with a non-zero return code."
32         redirect_stderr_to_stdout_msg =      "Redirect all STDERR output to STDOUT.  Useful to get all output when\n" +
33         "                                     invoking GemInstaller via system()."
34         geminstaller_output_msg =            "Comma-delimited list of output types to show from GemInstaller.\n" +
35         "                                       Examples:\n" + 
36         "                                         --gall\n" +
37         "                                         --geminstaller-output=error,install,commandecho\n" +
38         "                                       Default: error,install,info\n" +
39         "                                       Valid types:\n" +
40         "                                         - none:        print only fatal errors\n" +
41         "                                         - error:       print error messages\n" +
42         "                                         - install:     print install messages\n" +
43         "                                         - info:        print informational messages\n" +
44         "                                         - commandecho: print rubygems commands as they are invoked\n" +
45         "                                         - debug:       print debug messages\n" +
46         "                                         - all:         print all messages"
47         help_msg =                           "Show this message."
48         print_rogue_gems_msg =               "Print a report of all locally installed gems which are not specified\n" +
49         "                                     in the geminstaller config file."
50         bundler_export_msg =                 "Export a Bundler manifest Gemfile based on the geminstaller config"
51         rubygems_output_msg =                "Comma-delimited list of output types to show from internal:\n" +
52         "                                       RubyGems command invocation.\n" +
53         "                                       Examples:\n" + 
54         "                                         --rall\n" +
55         "                                         --rubygems-output=stderr\n" +
56         "                                       Default: stderr\n" +
57         "                                       Valid types:\n" +
58         "                                         - none:        print no output\n" +
59         "                                         - stdout:      print standard output stream\n" +
60         "                                         - stderr:      print standard error stream\n" +
61         "                                         - all:         print all output"
62         sudo_msg =                           "Perform all gem operations under sudo (as root).  Will only work on\n" +
63         "                                     correctly configured, supported systems.  See docs for more info."
64         silent_msg =                         "Suppress all output except fatal exceptions, and output from\n" +
65         "                                     rogue-gems option."
66         version_msg =                        "Show GemInstaller version and exit."
67 
68         opts.on("-cCONFIGPATHS", "--config=CONFIGPATHS", String, config_msg) do |config_paths|
69           @options[:config_paths] = config_paths
70         end
71 
72         opts.on("-e", "--exceptions", exceptions_msg) do
73           @options[:exceptions] = true
74         end
75 
76         opts.on("-d", "--redirect-stderr-to-stdout", redirect_stderr_to_stdout_msg) do
77           @options[:redirect_stderr_to_stdout] = true
78         end
79 
80         opts.on("-gTYPES", "--geminstaller-output=TYPES", String, geminstaller_output_msg) do |geminstaller_output_flags|
81           @unparsed_geminstaller_output_flags = geminstaller_output_flags
82         end
83 
84         opts.on("-h", "--help", help_msg) do
85           @output = opts.to_s
86         end
87 
88         opts.on("-p", "--print-rogue-gems", print_rogue_gems_msg) do
89           @options[:print_rogue_gems] = true
90         end
91 
92         opts.on("-b", "--bundler-export", bundler_export_msg) do
93           @options[:bundler_export] = true
94         end
95 
96         opts.on("-rTYPES", "--rubygems-output=TYPES", String, rubygems_output_msg) do |rubygems_output_flags|
97           @unparsed_rubygems_output_flags = rubygems_output_flags
98         end
99 
100         opts.on("-s", "--sudo", sudo_msg) do
101           @options[:sudo] = true
102         end
103 
104         opts.on("-t", "--silent", silent_msg) do
105           @options[:silent] = true
106         end
107 
108         opts.on("-v", "--version", version_msg) do
109           @output = "#{GemInstaller::version}\n"
110         end
111       end
112 
113       begin
114         opts.parse!(args)
115       rescue(OptionParser::InvalidOption)
116         @output << opts.to_s
117         return 1
118       end
119       
120       if @options[:silent] and (@unparsed_geminstaller_output_flags or @unparsed_rubygems_output_flags)
121         @output = "The rubygems-output or geminstaller-output option cannot be specified if the silent option is true."
122         return 1
123       end
124 
125       if (@options[:sudo])
126         @output = "The sudo option is not (yet) supported when invoking GemInstaller programatically.  It is only supported when using the command line 'geminstaller' executable.  See the docs for more info."
127         return 1
128       end
129       
130       # TODO: remove duplication
131       if @unparsed_geminstaller_output_flags
132         flags = @unparsed_geminstaller_output_flags.split(',') 
133         flags.delete_if {|flag| flag == nil or flag == ''}
134         flags.map! {|flag| flag.downcase}
135         flags.sort!
136         flags.uniq!
137         flags.map! {|flag| flag.to_sym}
138         geminstaller_output_valid = true
139         flags.each do |flag|
140           unless VALID_GEMINSTALLER_OUTPUT_FLAGS.include?(flag)
141             @output = "Invalid geminstaller-output flag: #{flag}\n" 
142             geminstaller_output_valid = false
143           end
144         end
145         @options[:geminstaller_output] = flags if geminstaller_output_valid
146       end
147 
148       if @unparsed_rubygems_output_flags
149         flags = @unparsed_rubygems_output_flags.split(',') 
150         flags.delete_if {|flag| flag == nil or flag == ''}
151         flags.map! {|flag| flag.downcase}
152         flags.sort!
153         flags.uniq!
154         flags.map! {|flag| flag.to_sym}
155         rubygems_output_valid = true
156         flags.each do |flag|
157           unless VALID_RUBYGEMS_OUTPUT_FLAGS.include?(flag)
158             @output = "Invalid rubygems-output flag: #{flag}\n" 
159             rubygems_output_valid = false
160           end
161         end
162         @options[:rubygems_output] = flags if rubygems_output_valid
163       end
164 
165       # nil out @output if there was no output
166       @output = nil if @output == ""
167       return 0
168       
169     end
170   end
171 end

Generated on Mon May 10 23:40:28 -0700 2010 with rcov 0.9.8