-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
show headers by default. Add table_output #29
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,37 @@ | ||
require 'yaml' | ||
require 'lsperfm/core' | ||
require 'terminal-table' | ||
|
||
module LogStash | ||
module PerformanceMeter | ||
|
||
extend self | ||
|
||
def invoke | ||
debug = !!ENV['DEBUG'] | ||
headers = !!ENV['HEADERS'] | ||
debug = 'false' != ENV.fetch('DEBUG', 'false') | ||
display_headers = 'false' != ENV.fetch('HEADERS', 'true') | ||
table_output = 'false' != ENV.fetch('TABLE_OUTPUT', 'false') | ||
|
||
install_path = ARGV.size > 1 ? ARGV[1] : Dir.pwd | ||
definition = ARGV.size > 0 ? ARGV[0] : "" | ||
install_path = ARGV.size > 1 ? ARGV[1] : Dir.pwd | ||
definition = ARGV.size > 0 ? ARGV[0] : "" | ||
|
||
runner = LogStash::PerformanceMeter::Core.new(definition, install_path) | ||
runner.config = '.lsperfm' if File.exist?('.lsperfm.yml') | ||
puts runner.run(debug, headers).join("\n") | ||
|
||
results = runner.run(debug) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes the runner/core return all it's info - headers & results; letting this method deal with how to display it. |
||
headings = results.slice!(0) | ||
|
||
puts '' | ||
if table_output | ||
table = Terminal::Table.new | ||
table.headings = headings.split(',') if display_headers | ||
table.rows = results.map { |result| result.split(',') } | ||
|
||
puts table | ||
else | ||
puts headings if display_headers | ||
puts results.join('\n') | ||
end | ||
end | ||
|
||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
let(:command) { [File.join(Dir.pwd, LogStash::PerformanceMeter::Runner::LOGSTASH_BIN), "-f", "spec/fixtures/simple.conf"]} | ||
|
||
it "invokes the logstash command" do | ||
Open3.should_receive(:popen3).with(*command).and_return(true) | ||
expect(Open3).to receive(:popen3).with(*command).and_return(true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deprecation notice for using 'should(a)' syntax |
||
runner.run(events, 0, lines) | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was surprised to learn the ENV hash didn't have a better structure to deal with true or false values, instead of by presence & stringifying everything - making !!'false' => true . This fixes that case.