mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
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
This commit is contained in:
parent
01e9f37591
commit
b0091b242c
2 changed files with 16 additions and 50 deletions
|
@ -69,10 +69,6 @@ end
|
||||||
class LogStash::Runner
|
class LogStash::Runner
|
||||||
include LogStash::Program
|
include LogStash::Program
|
||||||
|
|
||||||
def initialize
|
|
||||||
@runners = []
|
|
||||||
end
|
|
||||||
|
|
||||||
def main(args)
|
def main(args)
|
||||||
require "logstash/util"
|
require "logstash/util"
|
||||||
require "stud/trap"
|
require "stud/trap"
|
||||||
|
@ -89,23 +85,11 @@ class LogStash::Runner
|
||||||
|
|
||||||
Stud::untrap("INT", @startup_interruption_trap)
|
Stud::untrap("INT", @startup_interruption_trap)
|
||||||
|
|
||||||
args = [nil] if args.empty?
|
if args.empty? then
|
||||||
|
|
||||||
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?
|
|
||||||
exit(0)
|
exit(0)
|
||||||
else
|
else
|
||||||
exit(status.first)
|
task = run(args)
|
||||||
|
exit(task.wait)
|
||||||
end
|
end
|
||||||
end # def self.main
|
end # def self.main
|
||||||
|
|
||||||
|
@ -118,14 +102,12 @@ class LogStash::Runner
|
||||||
if args.include?("--verbose")
|
if args.include?("--verbose")
|
||||||
agent_args << "--verbose"
|
agent_args << "--verbose"
|
||||||
end
|
end
|
||||||
LogStash::Agent.run($0, agent_args)
|
return LogStash::Agent.run($0, agent_args)
|
||||||
return []
|
|
||||||
end,
|
end,
|
||||||
"web" => lambda do
|
"web" => lambda do
|
||||||
# Give them kibana.
|
# Give them kibana.
|
||||||
require "logstash/kibana"
|
require "logstash/kibana"
|
||||||
kibana = LogStash::Kibana::Runner.new
|
kibana = LogStash::Kibana::Runner.new
|
||||||
@runners << kibana
|
|
||||||
return kibana.run(args)
|
return kibana.run(args)
|
||||||
end,
|
end,
|
||||||
"rspec" => lambda do
|
"rspec" => lambda do
|
||||||
|
@ -136,18 +118,11 @@ class LogStash::Runner
|
||||||
require "test_utils"
|
require "test_utils"
|
||||||
all_specs = Dir.glob(File.join(spec_path, "/**/*.rb"))
|
all_specs = Dir.glob(File.join(spec_path, "/**/*.rb"))
|
||||||
rspec = LogStash::RSpecsRunner.new(args.empty? ? all_specs : args)
|
rspec = LogStash::RSpecsRunner.new(args.empty? ? all_specs : args)
|
||||||
rspec.run
|
return rspec.run
|
||||||
@runners << rspec
|
|
||||||
return []
|
|
||||||
end,
|
end,
|
||||||
"irb" => lambda do
|
"irb" => lambda do
|
||||||
require "irb"
|
require "irb"
|
||||||
IRB.start(__FILE__)
|
return IRB.start(__FILE__)
|
||||||
return []
|
|
||||||
end,
|
|
||||||
"ruby" => lambda do
|
|
||||||
require(args[0])
|
|
||||||
return []
|
|
||||||
end,
|
end,
|
||||||
"pry" => lambda do
|
"pry" => lambda do
|
||||||
require "pry"
|
require "pry"
|
||||||
|
@ -158,17 +133,11 @@ class LogStash::Runner
|
||||||
plugin_manager = LogStash::PluginManager::Main.new($0)
|
plugin_manager = LogStash::PluginManager::Main.new($0)
|
||||||
begin
|
begin
|
||||||
plugin_manager.parse(args)
|
plugin_manager.parse(args)
|
||||||
|
return plugin_manager.execute
|
||||||
rescue Clamp::HelpWanted => e
|
rescue Clamp::HelpWanted => e
|
||||||
show_help(e.command)
|
show_help(e.command)
|
||||||
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
|
||||||
plugin_manager.execute
|
|
||||||
rescue Clamp::HelpWanted => e
|
|
||||||
show_help(e.command)
|
|
||||||
end
|
|
||||||
|
|
||||||
return []
|
|
||||||
end,
|
end,
|
||||||
"agent" => lambda do
|
"agent" => lambda do
|
||||||
require "logstash/agent"
|
require "logstash/agent"
|
||||||
|
@ -178,21 +147,20 @@ class LogStash::Runner
|
||||||
agent.parse(args)
|
agent.parse(args)
|
||||||
rescue Clamp::HelpWanted => e
|
rescue Clamp::HelpWanted => e
|
||||||
show_help(e.command)
|
show_help(e.command)
|
||||||
return []
|
return 0
|
||||||
rescue Clamp::UsageError => e
|
rescue Clamp::UsageError => e
|
||||||
# If 'too many arguments' then give the arguments to
|
# If 'too many arguments' then give the arguments to
|
||||||
# the next command. Otherwise it's a real error.
|
# the next command. Otherwise it's a real error.
|
||||||
raise if e.message != "too many arguments"
|
raise if e.message != "too many arguments"
|
||||||
remaining = agent.remaining_arguments
|
remaining = agent.remaining_arguments
|
||||||
end
|
end
|
||||||
@runners << Stud::Task.new { agent.execute }
|
|
||||||
|
|
||||||
return remaining
|
return agent.execute
|
||||||
end
|
end
|
||||||
} # commands
|
} # commands
|
||||||
|
|
||||||
if commands.include?(command)
|
if commands.include?(command)
|
||||||
args = commands[command].call
|
return Stud::Task.new { commands[command].call }
|
||||||
else
|
else
|
||||||
if command.nil?
|
if command.nil?
|
||||||
$stderr.puts "No command given"
|
$stderr.puts "No command given"
|
||||||
|
|
|
@ -19,24 +19,22 @@ describe LogStash::Runner do
|
||||||
it "should run agent help" do
|
it "should run agent help" do
|
||||||
expect(subject).to receive(:show_help).once.and_return(nil)
|
expect(subject).to receive(:show_help).once.and_return(nil)
|
||||||
args = ["agent", "-h"]
|
args = ["agent", "-h"]
|
||||||
expect(subject.run(args)).to eq([])
|
expect(subject.run(args).wait).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should run agent help and not run following commands" do
|
it "should run agent help and not run following commands" do
|
||||||
expect(subject).to receive(:show_help).once.and_return(nil)
|
expect(subject).to receive(:show_help).once.and_return(nil)
|
||||||
args = ["agent", "-h", "web"]
|
args = ["agent", "-h", "web"]
|
||||||
expect(subject.run(args)).to eq([])
|
expect(subject.run(args).wait).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should run agent and web" do
|
it "should not run agent and web" do
|
||||||
expect(Stud::Task).to receive(:new).once
|
expect(Stud::Task).to receive(:new).once
|
||||||
args = ["agent", "-e", "", "web"]
|
args = ["agent", "-e", "", "web"]
|
||||||
args = subject.run(args)
|
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(args).to eq(nil)
|
||||||
|
|
||||||
|
expect(LogStash::Kibana::Runner).to_not receive(:new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue