Skip to content

Commit

Permalink
feat: do not require files until command is executing
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 9, 2020
1 parent d1878d1 commit ad54d0b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/pact/mock_service/cli.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
require 'thor'
require 'webrick/https'
require 'rack/handler/webrick'
require 'fileutils'
require 'pact/mock_service/server/wait_for_server_up'
require 'pact/mock_service/cli/pidfile'
require 'socket'

module Pact
module MockService
Expand Down Expand Up @@ -33,6 +27,7 @@ def self.exit_on_failure? # Thor 1.0 deprecation guard
method_option :monkeypatch, hide: true

def service
require_common_dependencies
require 'pact/mock_service/run'
Run.(options)
end
Expand All @@ -51,6 +46,7 @@ def service
method_option :sslkey, desc: "Specify the path to the SSL key to use when running the service over HTTPS"

def control
require_common_dependencies
require 'pact/mock_service/control_server/run'
ControlServer::Run.(options)
end
Expand All @@ -73,6 +69,7 @@ def control
method_option :monkeypatch, hide: true

def start
require_common_dependencies
start_server(mock_service_pidfile) do
service
end
Expand All @@ -83,6 +80,7 @@ def start
method_option :pid_dir, desc: "PID dir, defaults to tmp/pids", default: "tmp/pids"

def stop
require_common_dependencies
mock_service_pidfile.kill_process
end

Expand All @@ -103,6 +101,7 @@ def stop
method_option :sslkey, desc: "Specify the path to the SSL key to use when running the service over HTTPS"

def restart
require_common_dependencies
restart_server(mock_service_pidfile) do
service
end
Expand All @@ -123,6 +122,7 @@ def restart
method_option :pact_dir, aliases: "-d", desc: "Directory to which the pacts will be written", default: "."

def control_start
require_common_dependencies
start_server(control_server_pidfile) do
control
end
Expand All @@ -133,6 +133,7 @@ def control_start
method_option :pid_dir, desc: "PID dir, defaults to tmp/pids", default: "tmp/pids"

def control_stop
require_common_dependencies
control_server_pidfile.kill_process
end

Expand All @@ -151,6 +152,7 @@ def control_stop
method_option :sslkey, desc: "Specify the path to the SSL key to use when running the service over HTTPS"

def control_restart
require_common_dependencies
restart_server(control_server_pidfile) do
control
end
Expand All @@ -167,6 +169,15 @@ def version

no_commands do

def require_common_dependencies
require 'webrick/https'
require 'rack/handler/webrick'
require 'fileutils'
require 'pact/mock_service/server/wait_for_server_up'
require 'pact/mock_service/cli/pidfile'
require 'socket'
end

def control_server_pidfile
Pidfile.new(pid_dir: options[:pid_dir], name: control_pidfile_name)
end
Expand Down

0 comments on commit ad54d0b

Please sign in to comment.