[前][次][番号順一覧][スレッド一覧]

ruby-changes:57625

From: Nobuyoshi <ko1@a...>
Date: Sat, 7 Sep 2019 11:40:25 +0900 (JST)
Subject: [ruby-changes:57625] 799de9122e (master): Separated VCS.define_options for common VCS options

https://git.ruby-lang.org/ruby.git/commit/?id=799de9122e

From 799de9122e2bd9c2f4cc7e0611f6f8313876ca1d Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 7 Sep 2019 00:36:08 +0900
Subject: Separated VCS.define_options for common VCS options


diff --git a/tool/lib/vcs.rb b/tool/lib/vcs.rb
index 3fe3eb5..73ef0a3 100644
--- a/tool/lib/vcs.rb
+++ b/tool/lib/vcs.rb
@@ -131,14 +131,15 @@ class VCS https://github.com/ruby/ruby/blob/trunk/tool/lib/vcs.rb#L131
     @@dirs << [dir, self, pred]
   end
 
-  def self.detect(path = '.', options = {}, argv = ::ARGV)
+  def self.detect(path = '.', options = {}, parser = nil)
     uplevel_limit = options.fetch(:uplevel_limit, 0)
     curr = path
     begin
       @@dirs.each do |dir, klass, pred|
         if pred ? pred[curr, dir] : File.directory?(File.join(curr, dir))
           vcs = klass.new(curr)
-          vcs.parse_options(argv)
+          vcs.define_options(parser) if parser
+          vcs.set_options(options)
           return vcs
         end
       end
@@ -155,6 +156,13 @@ class VCS https://github.com/ruby/ruby/blob/trunk/tool/lib/vcs.rb#L156
     String === path or path.respond_to?(:to_path)
   end
 
+  def self.define_options(parser, opts = {})
+    parser.separator("  VCS common options:")
+    parser.define("--[no-]dryrun") {|v| opts[:dryrun] = v}
+    parser.define("--[no-]debug") {|v| opts[:debug] = v}
+    opts
+  end
+
   attr_reader :srcdir
 
   def initialize(path)
@@ -166,21 +174,12 @@ class VCS https://github.com/ruby/ruby/blob/trunk/tool/lib/vcs.rb#L174
     @srcdir = path
   end
 
-  def parse_options(opts, parser = OptionParser.new)
-    case opts
-    when Array
-      parser.on("--[no-]dryrun") {|v| @dryrun = v}
-      parser.on("--[no-]debug") {|v| @debug = v}
-      parser.parse(opts)
-      @debug = $DEBUG unless defined?(@debug)
-      @dryrun = @debug unless defined?(@dryrun)
-    when Hash
-      unless (keys = opts.keys - [:debug, :dryrun]).empty?
-        raise "Unknown options: #{keys.join(', ')}"
-      end
-      @debug = opts.fetch(:debug) {$DEBUG}
-      @dryrun = opts.fetch(:dryrun) {@debug}
-    end
+  def define_options(parser)
+  end
+
+  def set_options(opts)
+    @debug = opts.fetch(:debug) {$DEBUG}
+    @dryrun = opts.fetch(:dryrun) {@debug}
   end
 
   attr_reader :dryrun, :debug
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]