diff options
Diffstat (limited to 'lib/optparse')
| -rw-r--r-- | lib/optparse/ac.rb | 8 | ||||
| -rw-r--r-- | lib/optparse/date.rb | 1 | ||||
| -rw-r--r-- | lib/optparse/kwargs.rb | 22 | ||||
| -rw-r--r-- | lib/optparse/optparse.gemspec | 29 | ||||
| -rw-r--r-- | lib/optparse/shellwords.rb | 1 | ||||
| -rw-r--r-- | lib/optparse/time.rb | 1 | ||||
| -rw-r--r-- | lib/optparse/uri.rb | 1 | ||||
| -rw-r--r-- | lib/optparse/version.rb | 3 |
8 files changed, 63 insertions, 3 deletions
diff --git a/lib/optparse/ac.rb b/lib/optparse/ac.rb index 6a8626094d..9d520101aa 100644 --- a/lib/optparse/ac.rb +++ b/lib/optparse/ac.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require 'optparse' class OptionParser::AC < OptionParser @@ -12,6 +13,8 @@ class OptionParser::AC < OptionParser end end + ARG_CONV = proc {|val| val.nil? ? true : val} + def _ac_arg_enable(prefix, name, help_string, block) _check_ac_args(name, block) @@ -19,8 +22,9 @@ class OptionParser::AC < OptionParser ldesc = ["--#{prefix}-#{name}"] desc = [help_string] q = name.downcase - enable = Switch::NoArgument.new(nil, proc {true}, sdesc, ldesc, nil, desc, block) - disable = Switch::NoArgument.new(nil, proc {false}, sdesc, ldesc, nil, desc, block) + ac_block = proc {|val| block.call(ARG_CONV.call(val))} + enable = Switch::PlacedArgument.new(nil, ARG_CONV, sdesc, ldesc, nil, desc, ac_block) + disable = Switch::NoArgument.new(nil, proc {false}, sdesc, ldesc, nil, desc, ac_block) top.append(enable, [], ["enable-" + q], disable, ['disable-' + q]) enable end diff --git a/lib/optparse/date.rb b/lib/optparse/date.rb index d680559f37..d6649c83f1 100644 --- a/lib/optparse/date.rb +++ b/lib/optparse/date.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require 'optparse' require 'date' diff --git a/lib/optparse/kwargs.rb b/lib/optparse/kwargs.rb new file mode 100644 index 0000000000..ccf20c65e9 --- /dev/null +++ b/lib/optparse/kwargs.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true +require 'optparse' + +class OptionParser + # :call-seq: + # define_by_keywords(options, method, **params) + # + # :include: ../../doc/optparse/creates_option.rdoc + # + def define_by_keywords(options, meth, **opts) + meth.parameters.each do |type, name| + case type + when :key, :keyreq + op, cl = *(type == :key ? %w"[ ]" : ["", ""]) + define("--#{name}=#{op}#{name.upcase}#{cl}", *opts[name]) do |o| + options[name] = o + end + end + end + options + end +end diff --git a/lib/optparse/optparse.gemspec b/lib/optparse/optparse.gemspec new file mode 100644 index 0000000000..ae6596678c --- /dev/null +++ b/lib/optparse/optparse.gemspec @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +name = File.basename(__FILE__, ".gemspec") +version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir| + break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line| + /^\s*OptionParser::Version\s*=\s*"(.*)"/ =~ line and break $1 + end rescue nil +end + +Gem::Specification.new do |spec| + spec.name = name + spec.version = version + spec.authors = ["Nobu Nakada"] + spec.email = ["nobu@ruby-lang.org"] + + spec.summary = %q{OptionParser is a class for command-line option analysis.} + spec.description = %q{OptionParser is a class for command-line option analysis.} + spec.homepage = "https://github.com/ruby/optparse" + spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0") + spec.licenses = ["Ruby", "BSD-2-Clause"] + + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = spec.homepage + + spec.files = Dir["{doc,lib,misc}/**/*"] + %w[README.md ChangeLog COPYING] + spec.bindir = "exe" + spec.executables = [] + spec.require_paths = ["lib"] +end diff --git a/lib/optparse/shellwords.rb b/lib/optparse/shellwords.rb index 0422d7c887..bf31701b96 100644 --- a/lib/optparse/shellwords.rb +++ b/lib/optparse/shellwords.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false # -*- ruby -*- require 'shellwords' diff --git a/lib/optparse/time.rb b/lib/optparse/time.rb index 402cadcf16..ffc6ff000d 100644 --- a/lib/optparse/time.rb +++ b/lib/optparse/time.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require 'optparse' require 'time' diff --git a/lib/optparse/uri.rb b/lib/optparse/uri.rb index 024dc69eac..51550cf91b 100644 --- a/lib/optparse/uri.rb +++ b/lib/optparse/uri.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false # -*- ruby -*- require 'optparse' diff --git a/lib/optparse/version.rb b/lib/optparse/version.rb index 76ed564287..b869d8fe51 100644 --- a/lib/optparse/version.rb +++ b/lib/optparse/version.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false # OptionParser internal utility class << OptionParser @@ -51,7 +52,7 @@ class << OptionParser raise NameError, path unless Module === klass klass.constants.grep(/#{name}/i) do |c| klass.const_defined?(c) or next - c = klass.const_get(c) + klass.const_get(c) end end end |
