Skip to content

Commit b0091b2

Browse files
jsvdjordansissel
authored andcommitted
Remove the ability to run multiple commands
Addresses #1747. This removes the argument list iteration and spawning of multiple tasks. It's still possible to specify aditional arguments but now they're ignored. PR: #1752
1 parent 01e9f37 commit b0091b2

File tree

2 files changed

+16
-50
lines changed

2 files changed

+16
-50
lines changed

lib/logstash/runner.rb

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ def wait
6969
class LogStash::Runner
7070
include LogStash::Program
7171

72-
def initialize
73-
@runners = []
74-
end
75-
7672
def main(args)
7773
require "logstash/util"
7874
require "stud/trap"
@@ -89,23 +85,11 @@ def main(args)
8985

9086
Stud::untrap("INT", @startup_interruption_trap)
9187

92-
args = [nil] if args.empty?
93-
94-
while args != nil && !args.empty?
95-
args = run(args)
96-
end
97-
98-
status = []
99-
@runners.each do |r|
100-
#$stderr.puts "Waiting on #{r.wait.inspect}"
101-
status << r.wait
102-
end
103-
104-
# Avoid running test/unit's at_exit crap
105-
if status.empty? || status.first.nil?
88+
if args.empty? then
10689
exit(0)
10790
else
108-
exit(status.first)
91+
task = run(args)
92+
exit(task.wait)
10993
end
11094
end # def self.main
11195

@@ -118,14 +102,12 @@ def run(args)
118102
if args.include?("--verbose")
119103
agent_args << "--verbose"
120104
end
121-
LogStash::Agent.run($0, agent_args)
122-
return []
105+
return LogStash::Agent.run($0, agent_args)
123106
end,
124107
"web" => lambda do
125108
# Give them kibana.
126109
require "logstash/kibana"
127110
kibana = LogStash::Kibana::Runner.new
128-
@runners << kibana
129111
return kibana.run(args)
130112
end,
131113
"rspec" => lambda do
@@ -136,18 +118,11 @@ def run(args)
136118
require "test_utils"
137119
all_specs = Dir.glob(File.join(spec_path, "/**/*.rb"))
138120
rspec = LogStash::RSpecsRunner.new(args.empty? ? all_specs : args)
139-
rspec.run
140-
@runners << rspec
141-
return []
121+
return rspec.run
142122
end,
143123
"irb" => lambda do
144124
require "irb"
145-
IRB.start(__FILE__)
146-
return []
147-
end,
148-
"ruby" => lambda do
149-
require(args[0])
150-
return []
125+
return IRB.start(__FILE__)
151126
end,
152127
"pry" => lambda do
153128
require "pry"
@@ -158,17 +133,11 @@ def run(args)
158133
plugin_manager = LogStash::PluginManager::Main.new($0)
159134
begin
160135
plugin_manager.parse(args)
136+
return plugin_manager.execute
161137
rescue Clamp::HelpWanted => e
162138
show_help(e.command)
139+
return 0
163140
end
164-
165-
begin
166-
plugin_manager.execute
167-
rescue Clamp::HelpWanted => e
168-
show_help(e.command)
169-
end
170-
171-
return []
172141
end,
173142
"agent" => lambda do
174143
require "logstash/agent"
@@ -178,21 +147,20 @@ def run(args)
178147
agent.parse(args)
179148
rescue Clamp::HelpWanted => e
180149
show_help(e.command)
181-
return []
150+
return 0
182151
rescue Clamp::UsageError => e
183152
# If 'too many arguments' then give the arguments to
184153
# the next command. Otherwise it's a real error.
185154
raise if e.message != "too many arguments"
186155
remaining = agent.remaining_arguments
187156
end
188-
@runners << Stud::Task.new { agent.execute }
189157

190-
return remaining
158+
return agent.execute
191159
end
192160
} # commands
193161

194162
if commands.include?(command)
195-
args = commands[command].call
163+
return Stud::Task.new { commands[command].call }
196164
else
197165
if command.nil?
198166
$stderr.puts "No command given"

spec/runner_spec.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,22 @@ def run(args); end
1919
it "should run agent help" do
2020
expect(subject).to receive(:show_help).once.and_return(nil)
2121
args = ["agent", "-h"]
22-
expect(subject.run(args)).to eq([])
22+
expect(subject.run(args).wait).to eq(0)
2323
end
2424

2525
it "should run agent help and not run following commands" do
2626
expect(subject).to receive(:show_help).once.and_return(nil)
2727
args = ["agent", "-h", "web"]
28-
expect(subject.run(args)).to eq([])
28+
expect(subject.run(args).wait).to eq(0)
2929
end
3030

31-
it "should run agent and web" do
31+
it "should not run agent and web" do
3232
expect(Stud::Task).to receive(:new).once
3333
args = ["agent", "-e", "", "web"]
3434
args = subject.run(args)
35-
expect(args).to eq(["web"])
36-
37-
expect(LogStash::Kibana::Runner).to receive(:new).once.and_return(NullRunner.new)
38-
args = subject.run(args)
3935
expect(args).to eq(nil)
36+
37+
expect(LogStash::Kibana::Runner).to_not receive(:new)
4038
end
4139
end
4240
end

0 commit comments

Comments
 (0)