diff --git a/lib/logstash/runner.rb b/lib/logstash/runner.rb index aa179946db5..6bd2fc87949 100644 --- a/lib/logstash/runner.rb +++ b/lib/logstash/runner.rb @@ -85,12 +85,8 @@ def main(args) Stud::untrap("INT", @startup_interruption_trap) - if args.empty? then - exit(0) - else - task = run(args) - exit(task.wait) - end + task = run(args) + exit(task.wait) end # def self.main def run(args) @@ -170,21 +166,20 @@ def run(args) $stderr.puts "No such command #{command.inspect}" end end - $stderr.puts "Usage: logstash [command args]" - $stderr.puts "Run a command with the --help flag to see the arguments." - $stderr.puts "For example: logstash agent --help" - $stderr.puts - # hardcode the available commands to reduce confusion. - $stderr.puts "Available commands:" - $stderr.puts " agent - runs the logstash agent" - $stderr.puts " version - emits version info about this logstash" - $stderr.puts " web - runs the logstash web ui (called Kibana)" - $stderr.puts " rspec - runs tests" + $stderr.puts %q[ +Usage: logstash [command args] +Run a command with the --help flag to see the arguments. +For example: logstash agent --help + +Available commands: + agent - runs the logstash agent + version - emits version info about this logstash + web - runs the logstash web ui (called Kibana) + rspec - runs tests + ] #$stderr.puts commands.keys.map { |s| " #{s}" }.join("\n") - exit 1 + return Stud::Task.new { 1 } end - - return args end # def run # @return true if this file is the main file being run and not via rspec diff --git a/spec/runner_spec.rb b/spec/runner_spec.rb index a379f3d49a5..01c7587f63e 100644 --- a/spec/runner_spec.rb +++ b/spec/runner_spec.rb @@ -22,6 +22,20 @@ def run(args); end expect(subject.run(args).wait).to eq(0) end + it "should show help with no arguments" do + expect($stderr).to receive(:puts).once.and_return("No command given") + expect($stderr).to receive(:puts).once + args = [] + expect(subject.run(args).wait).to eq(1) + end + + it "should show help for unknown commands" do + expect($stderr).to receive(:puts).once.and_return("No such command welp") + expect($stderr).to receive(:puts).once + args = ["welp"] + expect(subject.run(args).wait).to eq(1) + 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"]