Class: RubiGen::Scripts::Base

### Home Classes Methods

### In Files

- lib/rubigen/scripts.rb

### Parent

Object

### Methods

- #banner
- #run
- #usage_message

### Included Modules

- RubiGen::Options

### Files

- History.txt
- License.txt
- Manifest.txt
- Todo.txt
- README.txt
- index.txt
- version-raw.txt
- version.txt

### Class/Module Index

Quicksearch

- RubiGen
- RubiGen::AbstractGemSource
- RubiGen::Base
- RubiGen::Commands
- RubiGen::Commands::Base
- RubiGen::Commands::Create
- RubiGen::Commands::Destroy
- RubiGen::Commands::List
- RubiGen::Commands::RewindBase
- RubiGen::Commands::Update
- RubiGen::GemPathSource
- RubiGen::GeneratedAttribute
- RubiGen::GeneratorError
- RubiGen::GeneratorTestHelper
- RubiGen::Lookup
- RubiGen::Lookup::ClassMethods
- RubiGen::Manifest
- RubiGen::Options
- RubiGen::Options::ClassMethods
- RubiGen::PathFilteredSource
- RubiGen::PathSource
- RubiGen::Scripts
- RubiGen::Scripts::Base
- RubiGen::Scripts::Destroy
- RubiGen::Scripts::Generate
- RubiGen::Scripts::Update
- RubiGen::Source
- RubiGen::Spec
- RubiGen::UsageError
- Rubigen
- Rubigen::CLI
- Dir
- Object

No matching classes.

# RubiGen::Scripts::Base

Generator scripts handle command-line invocation. Each script responds to an invoke! class method which handles option parsing and generator invocation.

### Attributes

stdout[R]

### Public Instance Methods

run(args = [], runtime_options = {}) click to toggle source

Run the generator script. Takes an array of unparsed arguments and a hash of parsed arguments, takes the generator as an option or first remaining argument, and invokes the requested command.

    # File lib/rubigen/scripts.rb, line 17
    def run(args = [], runtime_options = {})
      @stdout = runtime_options[:stdout] || $stdout
      begin
        parse!(args.dup, runtime_options)
      rescue OptionParser::InvalidOption => e
        # Don't cry, script. Generators want what you think is invalid.
      end

      # Generator name is the only required option.
      unless options[:generator]
        usage if args.empty?
        options[:generator] ||= args.shift
      end

      # Look up generator instance and invoke command on it.
      RubiGen::Base.instance(options[:generator], args, options).command(options[:command]).invoke!
    rescue => e
      stdout.puts e
      stdout.puts "  #{e.backtrace.join("\n  ")}\n" if options[:backtrace]
      raise SystemExit unless options[:no_exit]
    end

### Protected Instance Methods

banner() click to toggle source

Override with your own script usage banner.

    # File lib/rubigen/scripts.rb, line 41
    def banner
      "Usage: #{$0} generator [options] [args]"
    end

usage_message() click to toggle source

    # File lib/rubigen/scripts.rb, line 45
    def usage_message
      usage = "\nInstalled Generators\n"
      RubiGen::Base.sources.inject([]) do |mem, source|
        # Using an association list instead of a hash to preserve order,
        # for aesthetic reasons more than anything else.
        label = source.label.to_s.capitalize
        pair = mem.assoc(label)
        mem << (pair = [label, []]) if pair.nil?
        pair[1] |= source.names(:visible)
        mem
      end.each do |label, names|
        usage << "  #{label}: #{names.join(', ')}\n" unless names.empty?
      end

      # TODO - extensible blurbs for rails/newgem/adhearsion etc
      # e.g. for rails http://github.com/rails/rails/tree/daee6fd92ac16878f6806c3382a9e74592aa9656/railties/lib/rails_generator/scripts.rb#L50-74
      usage << More are available at http://rubigen.rubyforge.org/

      usage << Run generate with no arguments for usage information     #{$0} test_unit
      return usage
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.