diff --git a/lib/logstash/runner.rb b/lib/logstash/runner.rb index 82862748d9a..aa179946db5 100644 --- a/lib/logstash/runner.rb +++ b/lib/logstash/runner.rb @@ -69,10 +69,6 @@ def wait class LogStash::Runner include LogStash::Program - def initialize - @runners = [] - end - def main(args) require "logstash/util" require "stud/trap" @@ -89,23 +85,11 @@ def main(args) Stud::untrap("INT", @startup_interruption_trap) - args = [nil] if args.empty? - - while args != nil && !args.empty? - args = run(args) - end - - status = [] - @runners.each do |r| - #$stderr.puts "Waiting on #{r.wait.inspect}" - status << r.wait - end - - # Avoid running test/unit's at_exit crap - if status.empty? || status.first.nil? + if args.empty? then exit(0) else - exit(status.first) + task = run(args) + exit(task.wait) end end # def self.main @@ -118,14 +102,12 @@ def run(args) if args.include?("--verbose") agent_args << "--verbose" end - LogStash::Agent.run($0, agent_args) - return [] + return LogStash::Agent.run($0, agent_args) end, "web" => lambda do # Give them kibana. require "logstash/kibana" kibana = LogStash::Kibana::Runner.new - @runners << kibana return kibana.run(args) end, "rspec" => lambda do @@ -136,18 +118,11 @@ def run(args) require "test_utils" all_specs = Dir.glob(File.join(spec_path, "/**/*.rb")) rspec = LogStash::RSpecsRunner.new(args.empty? ? all_specs : args) - rspec.run - @runners << rspec - return [] + return rspec.run end, "irb" => lambda do require "irb" - IRB.start(__FILE__) - return [] - end, - "ruby" => lambda do - require(args[0]) - return [] + return IRB.start(__FILE__) end, "pry" => lambda do require "pry" @@ -158,17 +133,11 @@ def run(args) plugin_manager = LogStash::PluginManager::Main.new($0) begin plugin_manager.parse(args) + return plugin_manager.execute rescue Clamp::HelpWanted => e show_help(e.command) + return 0 end - - begin - plugin_manager.execute - rescue Clamp::HelpWanted => e - show_help(e.command) - end - - return [] end, "agent" => lambda do require "logstash/agent" @@ -178,21 +147,20 @@ def run(args) agent.parse(args) rescue Clamp::HelpWanted => e show_help(e.command) - return [] + return 0 rescue Clamp::UsageError => e # If 'too many arguments' then give the arguments to # the next command. Otherwise it's a real error. raise if e.message != "too many arguments" remaining = agent.remaining_arguments end - @runners << Stud::Task.new { agent.execute } - return remaining + return agent.execute end } # commands if commands.include?(command) - args = commands[command].call + return Stud::Task.new { commands[command].call } else if command.nil? $stderr.puts "No command given" diff --git a/spec/runner_spec.rb b/spec/runner_spec.rb index 5250747f354..a379f3d49a5 100644 --- a/spec/runner_spec.rb +++ b/spec/runner_spec.rb @@ -19,24 +19,22 @@ def run(args); end it "should run agent help" do expect(subject).to receive(:show_help).once.and_return(nil) args = ["agent", "-h"] - expect(subject.run(args)).to eq([]) + expect(subject.run(args).wait).to eq(0) end it "should run agent help and not run following commands" do expect(subject).to receive(:show_help).once.and_return(nil) args = ["agent", "-h", "web"] - expect(subject.run(args)).to eq([]) + expect(subject.run(args).wait).to eq(0) end - it "should run agent and web" do + it "should not run agent and web" do expect(Stud::Task).to receive(:new).once args = ["agent", "-e", "", "web"] args = subject.run(args) - expect(args).to eq(["web"]) - - expect(LogStash::Kibana::Runner).to receive(:new).once.and_return(NullRunner.new) - args = subject.run(args) expect(args).to eq(nil) + + expect(LogStash::Kibana::Runner).to_not receive(:new) end end end