summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-09-07 00:36:08 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-09-07 11:38:38 +0900
commit799de9122e2bd9c2f4cc7e0611f6f8313876ca1d (patch)
tree7fc758e9c7264010fe643ef43a20e23d476cc498
parent4068be1d9f60d8a9ac063c4871986dc26bdd0d56 (diff)
Separated VCS.define_options for common VCS options
-rw-r--r--tool/lib/vcs.rb33
1 files changed, 16 insertions, 17 deletions
diff --git a/tool/lib/vcs.rb b/tool/lib/vcs.rb
index 3fe3eb508c..73ef0a3553 100644
--- a/tool/lib/vcs.rb
+++ b/tool/lib/vcs.rb
@@ -131,14 +131,15 @@ class VCS
@@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
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
@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