(this is a resubmission, adding an rspec test and fixing a bug it has found)

This patch adds the ability to run buildr as 'buildr -p <project name>',
instead of 'cd' to the project's base directory. This is more
comfortable when building several projects and when using buildr as a
tool from an ide (since specifying an argument is easier than specifying
a working dir)



---
 lib/buildr/core/application_cli.rb |    6 +++++-
 lib/buildr/core/project.rb         |    8 ++++++--
 spec/project_spec.rb               |   10 ++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/lib/buildr/core/application_cli.rb b/lib/buildr/core/application_cli.rb
index 3a19cf9..3d275d4 100644
--- a/lib/buildr/core/application_cli.rb
+++ b/lib/buildr/core/application_cli.rb
@@ -59,7 +59,9 @@ module Buildr
         ['--version',  '-v', GetoptLong::NO_ARGUMENT,
           'Display the program version.'],
         ['--environment', '-e', GetoptLong::REQUIRED_ARGUMENT,
-          'Environment name (e.g. development, test, production).']
+          'Environment name (e.g. development, test, production).'],
+        ['--project',  '-p', GetoptLong::REQUIRED_ARGUMENT,
+          'Project name, can be relative to current directory']
       ]

     def collect_tasks
@@ -99,6 +101,8 @@ module Buildr
         options.show_task_pattern = Regexp.new(value || '.')
       when '--nosearch', '--quiet', '--trace'
         super
+      when '--project'
+         options.project = value.gsub(Regexp.quote(File::SEPARATOR), ':')
       end
     end

diff --git a/lib/buildr/core/project.rb b/lib/buildr/core/project.rb
index 6a37751..7256084 100644
--- a/lib/buildr/core/project.rb
+++ b/lib/buildr/core/project.rb
@@ -336,8 +336,12 @@ module Buildr
       end

       def local_projects(dir = nil, &block) #:nodoc:
-        dir = File.expand_path(dir || Buildr.application.original_dir)
- projects = Project.projects.select { |project| project.base_dir == dir }
+        if dir.nil? and Buildr.application.options.project
+ projects = local_projects('.').map{|p| project("#{p}:#{Buildr.application.options.project}")}
+        else
+          dir = File.expand_path(dir || Buildr.application.original_dir)
+ projects = Project.projects.select { |project| project.base_dir == dir }
+        end
         if projects.empty? && dir != Dir.pwd && File.dirname(dir) != dir
           local_projects(File.dirname(dir), &block)
         elsif block
diff --git a/spec/project_spec.rb b/spec/project_spec.rb
index a2f451c..5e749de 100644
--- a/spec/project_spec.rb
+++ b/spec/project_spec.rb
@@ -621,6 +621,16 @@ describe Rake::Task, ' local directory' do
     @task.should_receive(:from).with('foo:bar')
     in_original_dir('bar/src/main') { @task.invoke }
   end
+
+  it 'should invoke sub project with -p' do
+    Buildr.application.options.project = 'bar'
+    mkpath 'bar/src/main'
+    define('foo') { define 'bar' }
+    @task.should_receive(:from).with('foo:bar')
+    @task.invoke
+  end
+
+
 end


--
1.6.0.36.g3814c



--
--
Ittay Dror <[EMAIL PROTECTED]>


Reply via email to