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

Add --host and --port flags for use in Docker. #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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-19

## 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
@@ -40,7 +48,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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
21 changes: 20 additions & 1 deletion bin/dredd-hooks-ruby
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
#!/usr/bin/env ruby
$LOAD_PATH.push File.join(File.dirname(__FILE__), "/../lib" )

require 'optparse'
require 'dredd_hooks/cli'

DreddHooks::CLI.start(ARGV)
options = {
host: '127.0.0.1',
port: 61321
}

OptionParser.new do |opts|
opts.banner = "Usage: dredd-hooks-ruby [options] files"

opts.on('-h', '--host HOST', String, 'The host to listen on (default: 127.0.0.1)') do |h|
options[:host] = h
end

opts.on('-p', '--port PORT', Integer, 'The port to listen on (default: 61321)') do |p|
options[:port] = p
end
end.parse!


DreddHooks::CLI.start(host = options[:host], port = options[:port], ARGV)
4 changes: 2 additions & 2 deletions lib/dredd_hooks/cli.rb
Original file line number Diff line number Diff line change
@@ -3,14 +3,14 @@
module DreddHooks
class CLI

def self.start(error=STDERR, out=STDOUT, files)
def self.start(host=DreddHooks::Server::HOST, port=DreddHooks::Server::PORT, error=STDERR, out=STDOUT, 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)
server = DreddHooks::Server.new(host, port, error, out)
server.run
end
end
6 changes: 4 additions & 2 deletions lib/dredd_hooks/server.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literals: true

require 'socket'

require 'dredd_hooks/server/buffer'
@@ -15,10 +17,10 @@ class Server
PORT = 61321
MESSAGE_DELIMITER = "\n"

def initialize(error=STDERR, out=STDOUT)
def initialize(host=HOST, port=PORT, error=STDERR, out=STDOUT)
@error = error
@out = out
@server = TCPServer.new(HOST, PORT)
@server = TCPServer.new(host, port)
@buffer = Buffer.new(MESSAGE_DELIMITER)
@events_handler = EventsHandler.new
end