Skip to content

Commit

Permalink
Working on command line exposure
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebayes committed Jan 4, 2011
1 parent e8859c0 commit 9129c26
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
7 changes: 7 additions & 0 deletions lib/sprout/command_line.rb
Expand Up @@ -17,6 +17,13 @@ def initialize
@logger = $stdout
end

def parse! options
if options.empty?
handle_parse_error Sprout::Errors::UsageError.new("At least one parameter is required.")
end
super
end

def execute
if version
logger.puts "sprout #{Sprout::VERSION::STRING}"
Expand Down
3 changes: 1 addition & 2 deletions lib/sprout/executable/base.rb
Expand Up @@ -503,8 +503,7 @@ def inheritance_chain

def add_help_param
option_parser.on '--help', 'Display this help message' do
puts option_parser.to_s
exit
abort option_parser.to_s
end
end

Expand Down
13 changes: 9 additions & 4 deletions test/unit/command_line_test.rb
Expand Up @@ -6,15 +6,20 @@ class CommandLineTest < Test::Unit::TestCase
context "a new command line ui" do

setup do
@instance = Sprout::CommandLine.new
@instance.logger = Sprout::OutputBuffer.new
@logger = Sprout::OutputBuffer.new
@instance = Sprout::CommandLine.new
@instance.logger = @logger
end

should "display the version number" do
@instance.version = true
@instance.parse! ['--version']
@instance.execute
assert_matches /sprout #{Sprout::VERSION::STRING}/, @logger.read
end

assert_matches /sprout #{Sprout::VERSION::STRING}/, @instance.logger.read
should "display helper if no options provided" do
@instance.expects :abort
@instance.parse! []
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/unit/executable_option_parser_test.rb
Expand Up @@ -42,8 +42,8 @@ class ExecutableOptionParserTest < Test::Unit::TestCase
end

should "always accept help option" do
@exe.expects :puts
assert_raises SystemExit do
@exe.expects :abort
assert_raises Sprout::Errors::MissingArgumentError do
@exe.parse! [ '--help' ]
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/unit/ruby_generator_test.rb
Expand Up @@ -55,14 +55,14 @@ class RubyGeneratorTest < Test::Unit::TestCase
test_dir = File.join project_dir, 'test'
assert_file test_dir

test_helper = File.join test_dir, 'test_helper.rb'
unit_dir = File.join test_dir, 'unit'
assert_file unit_dir

test_helper = File.join unit_dir, 'test_helper.rb'
assert_file test_helper do |content|
assert_matches /require 'some_project'/, content
end

unit_dir = File.join test_dir, 'unit'
assert_file unit_dir

test_case = File.join unit_dir, 'some_project_test.rb'
assert_file test_case do |content|
assert_matches /class SomeProjectTest/, content
Expand Down

0 comments on commit 9129c26

Please sign in to comment.