Sha256: 96858917684a9434050b8d5e3e356eaab029be987b41e9fef0959eb6dea42638

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

module TomcatRails
  require 'optparse'
  
  class CommandLineParser
    def self.parse
      default_options = {
        :port => '3000',
        :environment => 'development',
        :context_path => '/',
        :libs_dir => 'lib',
        :classes_dir => 'classes'
      }
      
      parser = OptionParser.new do |opts|
        opts.banner = 'Tomcat server default options:'
        opts.separator ''

        opts.on('-e', '--env ENVIRONMENT', 'Rails environment', 
            "default: #{default_options[:environment]}") do |v| 
          default_options[:environment] = v
        end
        
        opts.on('-p', '--port PORT', 'Port to bind to', 
            "default: #{default_options[:port]}") do |v| 
          default_options[:port] = v
        end
        
        opts.on('-c', '--context CONTEXT_PATH', 'The application context path', 
            "default: #{default_options[:context_path]}") do |v| 
          default_options[:context_path] = v
        end
        
        opts.on('--lib', '--jars LIBS_DIR', 'Directory containing jars used by the application', 
            "default: #{default_options[:libs_dir]}") do |v| 
          default_options[:libs_dir] = v
        end
        
        opts.on('--classes', '--classes CLASSES_DIR', 'Directory containing classes used by the application', 
            "default: #{default_options[:classes_dir]}") do |v| 
          default_options[:classes_dir] = v
        end
        
        opts.on('-v', '--version', 'display the current version') do
          puts File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
          exit
        end
        
        opts.on('-h', '--help', 'display the help') do
          puts opts
          exit
        end
          
        opts.parse!(ARGV)
      end
      
        default_options
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
calavera-tomcat-rails-0.1.2 lib/tomcat-rails/command_line_parser.rb