Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Allow custom host and ports via CLI #34

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.1.3] - 2019-03-14

## Added

- Allow `--host` and `--port` to be set via CLI.
- Ex: `dredd-hooks-ruby hooks.rb --host 0.0.0.0 --port 12345`
- See https://github.com/apiaryio/dredd/issues/748#issuecomment-473010416 for more context.

## [0.1.2] - 2016-12-30

## Fixed
Expand Down Expand Up @@ -41,6 +49,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
The original [proof of concept][poc] was written by @netmilk.


[0.1.3]: https://github.com/apiaryio/dredd-hooks-ruby/compare/v0.1.2...v0.1.3
[0.1.2]: https://github.com/apiaryio/dredd-hooks-ruby/compare/v0.1.1...v0.1.2
[0.1.1]: https://github.com/apiaryio/dredd-hooks-ruby/compare/v0.1.0...v0.1.1
[0.1.0]: https://github.com/apiaryio/dredd-hooks-ruby/compare/v0.0.1...v0.1.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Add the gem to your `Gemfile`:
```ruby
# Gemfile

gem 'dredd_hooks', '0.1.2' # see semver.org
gem 'dredd_hooks', '0.1.3' # see semver.org
```

Usage
Expand Down
15 changes: 14 additions & 1 deletion bin/dredd-hooks-ruby
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,18 @@
$LOAD_PATH.push File.join(File.dirname(__FILE__), "/../lib" )

require 'dredd_hooks/cli'
require 'optparse'

DreddHooks::CLI.start(ARGV)
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: hooks.rb [options]"

opts.on("-h", "--host [HOST]", "Pass in host IP") do |host|
options[:host] = host
end
opts.on("-p", "--port [PORT]", Integer, "Pass in port number") do |port|
options[:port] = port
end
end.parse!

DreddHooks::CLI.start(options, ARGV)
6 changes: 3 additions & 3 deletions lib/dredd_hooks/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
module DreddHooks
class CLI

def self.start(error=STDERR, out=STDOUT, files)
def self.start(error=STDERR, out=STDOUT, options, files)

# Load all files given on the command-line
DreddHooks::FileLoader.load(files)

# Run the server
out.puts 'Starting Ruby Dredd Hooks Worker...'
server = DreddHooks::Server.new(error, out)
out.print 'Starting Ruby Dredd Hooks Worker...'
server = DreddHooks::Server.new(error, out, options)
server.run
end
end
Expand Down
9 changes: 7 additions & 2 deletions lib/dredd_hooks/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ class Server
PORT = 61321
MESSAGE_DELIMITER = "\n"

def initialize(error=STDERR, out=STDOUT)
def initialize(error=STDERR, out=STDOUT, options={})
@error = error
@out = out
@server = TCPServer.new(HOST, PORT)

## Set host/port if they are passed in through CLI
host = options[:host] || HOST
port = options[:port] || PORT
out.puts "on host:port #{host}:#{port}..."
@server = TCPServer.new(host, port)
@buffer = Buffer.new(MESSAGE_DELIMITER)
@events_handler = EventsHandler.new
end
Expand Down