Permalink
Browse files

Add --help switch to Sparkr::CLI

  • Loading branch information...
1 parent 8473311 commit fb7d78c41f67f63452490b991e92f75905cb526b @rrrene committed Feb 4, 2014
Showing with 9 additions and 8 deletions.
  1. +1 −1 lib/sparkr/cli.rb
  2. +8 −7 test/sparkr/cli_test.rb
View
2 lib/sparkr/cli.rb
@@ -15,7 +15,7 @@ def self.run(*args)
# Runs sparkr with the given +args+
# @return [void]
def run(*args)
- if args.empty?
+ if args.empty? || (args.size == 1 && %w(-h --help).include?(args.first))
puts help
else
sparkline = Sparkline.new(args.map(&:to_f))
View
15 test/sparkr/cli_test.rb
@@ -13,13 +13,14 @@
assert_equal "▁▁▁▁▃▁▁▁▂█\n", out
end
- it ".run should print usage information if args are missing" do
- string_numbers = %w()
- out, err = capture_io do
- ::Sparkr::CLI.run(*string_numbers)
+ it ".run should print usage information if args are missing or '-h'" do
+ [[], ['-h'], ['--help']].each do |args|
+ out, err = capture_io do
+ ::Sparkr::CLI.run(*args)
+ end
+ refute out.empty?, "there should be some output"
+ assert err.empty?, "there should be no errors"
+ assert_match /USAGE\:/, out
end
- refute out.empty?, "there should be some output"
- assert err.empty?, "there should be no errors"
- assert_match /USAGE\:/, out
end
end

0 comments on commit fb7d78c

Please sign in to comment.