Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to extend rails server command options parser #16142

Merged
merged 1 commit into from
Jul 15, 2014

Conversation

a-chernykh
Copy link
Contributor

With this change it will be possible to add additional options to the option_parser like this:

require 'rails/commands/server'
module Rails
  class Server < ::Rack::Server
    class Options
      def option_parser_with_open(options)
        parser = option_parser_without_open options
        parser.on('-o', '--open', 'Open in default browser') { options[:open] = true }
        parser
      end
      alias_method_chain :option_parser, :open
    end

    def start_with_open
      start_without_open do
        `open http://localhost:3000` if options[:open]
      end
    end
    alias_method_chain :start, :open
  end
end

With this change it will be possible to add additional options to the `option_parser` like this:

    require 'rails/commands/server'
    module Rails
      class Server < ::Rack::Server
        class Options
          def option_parser_with_open(options)
            parser = option_parser_without_open options
            parser.on('-o', '--open', 'Open in default browser') { options[:open] = true }
            parser
          end
          alias_method_chain :option_parser, :open
        end

        def start_with_open
          start_without_open do
            `open http://localhost:3000` if options[:open]
          end
        end
        alias_method_chain :start, :open
      end
    end
@a-chernykh
Copy link
Contributor Author

I really like to see rails server -o feature merged which opens server in a browser. Since #9396 have not received much traction I've decided to create a gem which adds this option, but I need OptionParser to be extendable first.

rafaelfranca added a commit that referenced this pull request Jul 15, 2014
Add ability to extend `rails server` command options parser
@rafaelfranca rafaelfranca merged commit ebb9501 into rails:master Jul 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants