Skip to content

Commit

Permalink
spec the absense and wrong commands
Browse files Browse the repository at this point in the history
-
PR: #1752
  • Loading branch information
jsvd authored and jordansissel committed Sep 27, 2014
1 parent c13552c commit f86287d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
33 changes: 14 additions & 19 deletions lib/logstash/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -170,21 +166,20 @@ def run(args)
$stderr.puts "No such command #{command.inspect}"
end
end
$stderr.puts "Usage: logstash <command> [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> [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
Expand Down
14 changes: 14 additions & 0 deletions spec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit f86287d

Please sign in to comment.