# class Camping::Server::Options

### Public Instance Methods

parse!(args) click to toggle source

    # File lib/camping/server.rb, line 32
    def parse!(args)
      args = args.dup
      options = {}
      opt_parser = OptionParser.new("", 24, '  ') do |opts|
        opts.banner = "Usage: camping Or: camping my-camping-app.rb"

        # opts.define_head "#{File.basename($0)}, the microframework ON-button for ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"

        opts.separator ""
        opts.separator "Specific options:"

        opts.on("-h", "--host HOSTNAME",
        "Host for web server to bind to (default is all IPs)") { |v| options[:Host] = v }

        opts.on("-p", "--port NUM",
        "Port for web server (defaults to 3301)") { |v| options[:Port] = v }

        opts.on("-c", "--console",
        "Run in console mode with IRB") { options[:server] = "console" }

        opts.on("-e", "--env ENVIRONMENT",
        "Sets the environment. (defaults: development)") { |v| options[:environment] = ENV['environment'] = v }

        server_list = ["thin", "webrick", "console", "puma", "tipi", "falcon"]
        opts.on("-s", "--server NAME",
        "Server to force (#{server_list.join(', ')})") { |v| options[:server] = v }

        opts.separator ""
        opts.separator "Common options:"

        # No argument, shows at tail.  This will print an options summary.
        # Try it and see!
        opts.on("-?", "--help", "Show this message") do
          puts opts
          exit
        end

        # Another typical switch to print the version.
        opts.on("-v", "--version", "Show version") { options[:version] = true }

        # Show Routes
        opts.on("-r", "--routes", "Show Routes") { options[:routes] = true }

      end

      opt_parser.parse!(args)

      if args.empty?
        args << "camp.rb"
      end

      options[:script] = args.shift
      options
    end