class RR::GenerateRunner

This class implements the functionality of the 'generate' command.

Constants

CONFIG_TEMPLATE

Attributes

options[RW]

Provided options. Possible values:

  • :config_file: path to config file

Public Class Methods

run(args) click to toggle source

Entry points for executing a processing run. args: the array of command line options that were provided by the user.

# File lib/rubyrep/generate_runner.rb, line 92
def self.run(args)
  runner = new

  status = runner.process_options(args)
  if runner.options
    runner.execute
  end
  status
end

Public Instance Methods

execute() click to toggle source

Generates a configuration file template.

# File lib/rubyrep/generate_runner.rb, line 81
def execute
  if File.exists?(options[:file_name])
    raise("Cowardly refuse to overwrite existing file '#{options[:file_name]}'")
  end
  File.open(options[:file_name], 'w') do |f|
    f.write CONFIG_TEMPLATE
  end
end
process_options(args) click to toggle source

Parses the given command line parameter array. Returns the status (as per UNIX conventions: 1 if parameters were invalid, 0 otherwise)

# File lib/rubyrep/generate_runner.rb, line 45
    def process_options(args)
      status = 0
      self.options = {}

      parser = OptionParser.new do |opts|
        opts.banner = <<EOS
Usage: #{$0} generate [file_name]

  Generates a configuration file template under name [file_name].
EOS
        opts.separator ""
        opts.separator "  Specific options:"

        opts.on_tail("--help", "Show this message") do
          $stderr.puts opts
          self.options = nil
        end
      end

      begin
        unprocessed_args = parser.parse!(args)
        if options # this will be +nil+ if the --help option is specified
          raise("Please specify the name of the configuration file") if unprocessed_args.empty?
          options[:file_name] = unprocessed_args[0]
        end
      rescue Exception => e
        $stderr.puts "Command line parsing failed: #{e}"
        $stderr.puts parser.help
        self.options = nil
        status = 1
      end

      return status
    end