You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by do...@apache.org on 2013/10/09 13:19:28 UTC

svn commit: r1530566 - in /buildr/trunk/lib/buildr/core: application.rb console.rb generate.rb transports.rb

Author: donaldp
Date: Wed Oct  9 11:19:28 2013
New Revision: 1530566

URL: http://svn.apache.org/r1530566
Log:
Move the remaining usages of highline to be abstracted behind the Buildr::Console facade

Modified:
    buildr/trunk/lib/buildr/core/application.rb
    buildr/trunk/lib/buildr/core/console.rb
    buildr/trunk/lib/buildr/core/generate.rb
    buildr/trunk/lib/buildr/core/transports.rb

Modified: buildr/trunk/lib/buildr/core/application.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/application.rb?rev=1530566&r1=1530565&r2=1530566&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/application.rb (original)
+++ buildr/trunk/lib/buildr/core/application.rb Wed Oct  9 11:19:28 2013
@@ -387,25 +387,25 @@ module Buildr
     end
 
     def ask_generate_buildfile
-      source, fromEclipse = choose do |menu|
-        menu.header = "To use Buildr you need a buildfile. Do you want me to create one?"
-        menu.choice("From eclipse .project files") { [Dir.pwd, true] } if Generate.has_eclipse_project?
-        menu.choice("From Maven2 POM file") { ['pom.xml', false] } if File.exist?('pom.xml')
-        menu.choice("From directory structure") { [Dir.pwd, false] }
-        menu.choice("Cancel") {}
-      end
+      header = "To use Buildr you need a buildfile. Do you want me to create one?"
+      options = {}
+      options["From eclipse .project files"] = [Dir.pwd, true] if Generate.has_eclipse_project?
+      options["From Maven2 POM file"] = ['pom.xml', false] if File.exist?('pom.xml')
+      options["From directory structure"] = [Dir.pwd, false]
+      options["Cancel"]= nil
+      source, from_eclipse = Buildr::Console.present_menu(header, options)
       if source
-        buildfile = raw_generate_buildfile(source, fromEclipse)
+        buildfile = raw_generate_buildfile(source, from_eclipse)
         [buildfile, File.dirname(buildfile)]
       end
     end
 
-    def raw_generate_buildfile(source, fromEclipse=Generate.has_eclipse_project?)
+    def raw_generate_buildfile(source, from_eclipse=Generate.has_eclipse_project?)
       # We need rakefile to be known, for settings.build to be accessible.
       @rakefile = File.expand_path(DEFAULT_BUILDFILES.first)
       fail "Buildfile already exists" if File.exist?(@rakefile) && !(tty_output? && agree('Buildfile exists, overwrite?'))
       script = nil
-      if fromEclipse
+      if from_eclipse
         script = Generate.from_eclipse(source)
       elsif File.directory?(source)
         script = Generate.from_directory(source)

Modified: buildr/trunk/lib/buildr/core/console.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/console.rb?rev=1530566&r1=1530565&r2=1530566&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/console.rb (original)
+++ buildr/trunk/lib/buildr/core/console.rb Wed Oct  9 11:19:28 2013
@@ -66,6 +66,19 @@ module Buildr #nodoc
         d = console_dimensions
         d ? d[0] : nil
       end
+
+      def ask_password(prompt)
+        ask(prompt) { |q| q.echo = '*' }
+      end
+
+      def present_menu(header, options)
+        choose do |menu|
+          menu.header = header
+          options.each_pair do |message, result|
+            menu.choice(message) { result }
+          end
+        end
+      end
     end
   end
 end

Modified: buildr/trunk/lib/buildr/core/generate.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/generate.rb?rev=1530566&r1=1530565&r2=1530566&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/generate.rb (original)
+++ buildr/trunk/lib/buildr/core/generate.rb Wed Oct  9 11:19:28 2013
@@ -17,15 +17,18 @@ module Buildr #:nodoc:
   module Generate #:nodoc:
 
     task 'generate' do
-      script = nil
-      choose do |menu|
-        menu.header = "To use Buildr you need a buildfile. Do you want me to create one?"
-        menu.choice("From eclipse .project files") { script = Generate.from_eclipse(Dir.pwd).join("\n") } if has_eclipse_project?
-        menu.choice("From maven2 pom file") { script = Generate.from_maven2_pom('pom.xml').join("\n") } if File.exists?("pom.xml")
-        menu.choice("From directory structure") { script = Generate.from_directory(Dir.pwd).join("\n") }
-        menu.choice("Skip") { }
-      end
 
+      header = "To use Buildr you need a buildfile. Do you want me to create one?"
+      options = {}
+      if Generate.has_eclipse_project?
+        options["From eclipse .project files"] = Proc.new { Generate.from_eclipse(Dir.pwd).join("\n") }
+      end
+      if File.exist?('pom.xml')
+        options["From Maven2 POM file"] = Proc.new { Generate.from_maven2_pom('pom.xml').join("\n") }
+      end
+      options["From directory structure"] = Proc.new { Generate.from_directory(Dir.pwd).join("\n") }
+      options["Skip"]= nil
+      script = Buildr::Console.present_menu(header, options)
       if script
         buildfile = File.expand_path(Buildr::Application::DEFAULT_BUILDFILES.first)
         File.open(buildfile, "w") { |file| file.write script }

Modified: buildr/trunk/lib/buildr/core/transports.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/transports.rb?rev=1530566&r1=1530565&r2=1530566&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/transports.rb (original)
+++ buildr/trunk/lib/buildr/core/transports.rb Wed Oct  9 11:19:28 2013
@@ -422,7 +422,7 @@ module URI
       rescue Net::SSH::AuthenticationFailed=>ex
         # Only if running with console, prompt for password.
         if !ssh_options[:password] && $stdout.isatty
-          password = ask("Password for #{host}:") { |q| q.echo = '*' }
+          password = Buildr::Console.ask_password("Password for #{host}:") { |q| q.echo = '*' }
           ssh_options[:password] = password
           retry
         end
@@ -465,7 +465,7 @@ module URI
       rescue Net::SSH::AuthenticationFailed=>ex
         # Only if running with console, prompt for password.
         if !ssh_options[:password] && $stdout.isatty
-          password = ask("Password for #{host}:") { |q| q.echo = '*' }
+          password = Buildr::Console.ask_password("Password for #{host}:") { |q| q.echo = '*' }
           ssh_options[:password] = password
           retry
         end