Skip to content

Commit ad54d0b

Browse files
committed
feat: do not require files until command is executing
1 parent d1878d1 commit ad54d0b

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lib/pact/mock_service/cli.rb

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
require 'thor'
2-
require 'webrick/https'
3-
require 'rack/handler/webrick'
4-
require 'fileutils'
5-
require 'pact/mock_service/server/wait_for_server_up'
6-
require 'pact/mock_service/cli/pidfile'
7-
require 'socket'
82

93
module Pact
104
module MockService
@@ -33,6 +27,7 @@ def self.exit_on_failure? # Thor 1.0 deprecation guard
3327
method_option :monkeypatch, hide: true
3428

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

5348
def control
49+
require_common_dependencies
5450
require 'pact/mock_service/control_server/run'
5551
ControlServer::Run.(options)
5652
end
@@ -73,6 +69,7 @@ def control
7369
method_option :monkeypatch, hide: true
7470

7571
def start
72+
require_common_dependencies
7673
start_server(mock_service_pidfile) do
7774
service
7875
end
@@ -83,6 +80,7 @@ def start
8380
method_option :pid_dir, desc: "PID dir, defaults to tmp/pids", default: "tmp/pids"
8481

8582
def stop
83+
require_common_dependencies
8684
mock_service_pidfile.kill_process
8785
end
8886

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

105103
def restart
104+
require_common_dependencies
106105
restart_server(mock_service_pidfile) do
107106
service
108107
end
@@ -123,6 +122,7 @@ def restart
123122
method_option :pact_dir, aliases: "-d", desc: "Directory to which the pacts will be written", default: "."
124123

125124
def control_start
125+
require_common_dependencies
126126
start_server(control_server_pidfile) do
127127
control
128128
end
@@ -133,6 +133,7 @@ def control_start
133133
method_option :pid_dir, desc: "PID dir, defaults to tmp/pids", default: "tmp/pids"
134134

135135
def control_stop
136+
require_common_dependencies
136137
control_server_pidfile.kill_process
137138
end
138139

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

153154
def control_restart
155+
require_common_dependencies
154156
restart_server(control_server_pidfile) do
155157
control
156158
end
@@ -167,6 +169,15 @@ def version
167169

168170
no_commands do
169171

172+
def require_common_dependencies
173+
require 'webrick/https'
174+
require 'rack/handler/webrick'
175+
require 'fileutils'
176+
require 'pact/mock_service/server/wait_for_server_up'
177+
require 'pact/mock_service/cli/pidfile'
178+
require 'socket'
179+
end
180+
170181
def control_server_pidfile
171182
Pidfile.new(pid_dir: options[:pid_dir], name: control_pidfile_name)
172183
end

0 commit comments

Comments
 (0)