Object
# File lib/templater/cli/generator.rb, line 7 7: def initialize(generator_name, generator_class, destination_root, name, version) 8: @generator_name = generator_name 9: @destination_root = destination_root 10: @generator_class = generator_class 11: @name = name 12: @version = version 13: end
outputs a helpful message and quits
# File lib/templater/cli/generator.rb, line 21 21: def help 22: puts "Usage: #{@name} #{@generator_name} [options] [args]" 23: puts '' 24: puts @generator_class.desc 25: puts '' 26: puts @options[:opts] 27: puts '' 28: exit 29: end
# File lib/templater/cli/generator.rb, line 31 31: def run(arguments) 32: generator_class = @generator_class # FIXME: closure wizardry, there has got to be a better way than this? 33: 34: @options = Templater::CLI::Parser.parse(arguments) do |opts, options| 35: opts.separator "Options specific for this generator:" 36: # the reason this is reversed is so that the 'main' generator will always have the last word 37: # on the description of the option 38: generator_class.generators.reverse.each do |generator| 39: # Loop through this generator's options and add them as valid command line options 40: # so that they show up in help messages and such 41: generator.options.each do |option| 42: name = option.name.to_s.gsub('_', '-') 43: if option.options[:as] == :boolean 44: opts.on("--#{name}", option.options[:desc]) do |s| 45: options[option.name] = s 46: end 47: else 48: opts.on("--#{name}=value", option.options[:desc]) do |s| 49: options[option.name] = s.gsub('-', '_').to_sym 50: end 51: end 52: end 53: end 54: end 55: 56: self.help if @options[:help] 57: self.version if @options[:version] 58: 59: # Try to instantiate a generator, if the arguments to it were incorrect: show a help message 60: begin 61: @generator = @generator_class.new(@destination_root, @options, *arguments) 62: rescue Templater::ArgumentError => e 63: if @options[:debug] 64: raise e 65: else 66: self.help 67: end 68: end 69: 70: if @options[:pretend] 71: puts "Generating with #{@generator_name} generator (just pretending):" 72: else 73: puts "Generating with #{@generator_name} generator:" 74: end 75: step_through_templates 76: 77: # Run hooks 78: @generator.after_run 79: @generator.after_generation unless @options[:delete] 80: @generator.after_deletion if @options[:delete] 81: end
# File lib/templater/cli/generator.rb, line 83 83: def step_through_templates 84: @generator.all_actions.each do |action| 85: if @options[:delete] 86: action.revoke! unless @options[:pretend] 87: say_status('deleted', action, :red) 88: else 89: if action.identical? 90: say_status('identical', action, :blue) 91: elsif action.exists? 92: if @options[:force] 93: action.invoke! unless @options[:pretend] 94: say_status('forced', action, :yellow) 95: elsif @options[:skip] 96: say_status('skipped', action, :yellow) 97: else 98: say_status('conflict', action, :red) 99: conflict_menu(action) 100: end 101: else 102: action.invoke! unless @options[:pretend] 103: say_status('added', action, :green) 104: end 105: end 106: end 107: end
# File lib/templater/cli/generator.rb, line 163 163: def output_diff_line(diff) 164: case diff.action 165: when '-' 166: say "<%= color( %(- #{diff.element.chomp}), :red) %>" 167: when '+' 168: say "<%= color( %(+ #{diff.element.chomp}), :green) %>" 169: else 170: say "#{diff.action} #{diff.element.chomp}" 171: end 172: end
# File lib/templater/cli/generator.rb, line 154 154: def say_status(status, template, color = nil) 155: status_flag = "[#{status.to_s.upcase}]".rjust(12) 156: if color and not @options[:no_color] 157: say "<%= color('#{status_flag}', :#{color}) %> " + template.relative_destination 158: else 159: say "#{status_flag} " + template.relative_destination 160: end 161: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.