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

ruby-changes:65810

From: Burdette <ko1@a...>
Date: Thu, 8 Apr 2021 12:18:42 +0900 (JST)
Subject: [ruby-changes:65810] 5891159f96 (master): [ruby/optparse] Enhanced doc for option parameters (#11)

https://git.ruby-lang.org/ruby.git/commit/?id=5891159f96

From 5891159f9608f058b3fb2ba96a9874fc81f3d7b3 Mon Sep 17 00:00:00 2001
From: Burdette Lamar <BurdetteLamar@Y...>
Date: Wed, 7 Apr 2021 09:01:52 -0500
Subject: [ruby/optparse] Enhanced doc for option parameters (#11)

https://github.com/ruby/optparse/commit/5618eeb49e
---
 doc/option_params/argument_keywords.rb     |   6 +
 doc/option_params/argument_strings.rb      |   6 +
 doc/option_params/array.rb                 |   6 +
 doc/option_params/block.rb                 |   9 +
 doc/option_params/date.rb                  |   6 +
 doc/option_params/datetime.rb              |   6 +
 doc/option_params/decimal_integer.rb       |   7 +
 doc/option_params/decimal_numeric.rb       |   7 +
 doc/option_params/descriptions.rb          |  15 +
 doc/option_params/explicit_array_values.rb |   9 +
 doc/option_params/explicit_hash_values.rb  |   9 +
 doc/option_params/false_class.rb           |   6 +
 doc/option_params/float.rb                 |   6 +
 doc/option_params/integer.rb               |   6 +
 doc/option_params/long_binary.rb           |   6 +
 doc/option_params/long_optional.rb         |   6 +
 doc/option_params/long_required.rb         |   6 +
 doc/option_params/long_simple.rb           |   9 +
 doc/option_params/matched_values.rb        |   6 +
 doc/option_params/method.rb                |  11 +
 doc/option_params/mixed_names.rb           |  12 +
 doc/option_params/numeric.rb               |   6 +
 doc/option_params/object.rb                |   6 +
 doc/option_params/octal_integer.rb         |   7 +
 doc/option_params/option_params.rdoc       | 845 +++++++++++++++++++++++++++++
 doc/option_params/proc.rb                  |  13 +
 doc/option_params/regexp.rb                |   6 +
 doc/option_params/shellwords.rb            |   6 +
 doc/option_params/short_optional.rb        |   6 +
 doc/option_params/short_range.rb           |   6 +
 doc/option_params/short_required.rb        |   6 +
 doc/option_params/short_simple.rb          |   9 +
 doc/option_params/string.rb                |   6 +
 doc/option_params/terminator.rb            |   6 +
 doc/option_params/time.rb                  |   6 +
 doc/option_params/true_class.rb            |   6 +
 doc/option_params/uri.rb                   |   6 +
 37 files changed, 1106 insertions(+)
 create mode 100644 doc/option_params/argument_keywords.rb
 create mode 100644 doc/option_params/argument_strings.rb
 create mode 100644 doc/option_params/array.rb
 create mode 100644 doc/option_params/block.rb
 create mode 100644 doc/option_params/date.rb
 create mode 100644 doc/option_params/datetime.rb
 create mode 100644 doc/option_params/decimal_integer.rb
 create mode 100644 doc/option_params/decimal_numeric.rb
 create mode 100644 doc/option_params/descriptions.rb
 create mode 100644 doc/option_params/explicit_array_values.rb
 create mode 100644 doc/option_params/explicit_hash_values.rb
 create mode 100644 doc/option_params/false_class.rb
 create mode 100644 doc/option_params/float.rb
 create mode 100644 doc/option_params/integer.rb
 create mode 100644 doc/option_params/long_binary.rb
 create mode 100644 doc/option_params/long_optional.rb
 create mode 100644 doc/option_params/long_required.rb
 create mode 100644 doc/option_params/long_simple.rb
 create mode 100644 doc/option_params/matched_values.rb
 create mode 100644 doc/option_params/method.rb
 create mode 100644 doc/option_params/mixed_names.rb
 create mode 100644 doc/option_params/numeric.rb
 create mode 100644 doc/option_params/object.rb
 create mode 100644 doc/option_params/octal_integer.rb
 create mode 100644 doc/option_params/option_params.rdoc
 create mode 100644 doc/option_params/proc.rb
 create mode 100644 doc/option_params/regexp.rb
 create mode 100644 doc/option_params/shellwords.rb
 create mode 100644 doc/option_params/short_optional.rb
 create mode 100644 doc/option_params/short_range.rb
 create mode 100644 doc/option_params/short_required.rb
 create mode 100644 doc/option_params/short_simple.rb
 create mode 100644 doc/option_params/string.rb
 create mode 100644 doc/option_params/terminator.rb
 create mode 100644 doc/option_params/time.rb
 create mode 100644 doc/option_params/true_class.rb
 create mode 100644 doc/option_params/uri.rb

diff --git a/doc/option_params/argument_keywords.rb b/doc/option_params/argument_keywords.rb
new file mode 100644
index 0000000..8533257
--- /dev/null
+++ b/doc/option_params/argument_keywords.rb
@@ -0,0 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/doc/option_params/argument_keywords.rb#L1
+require 'optparse'
+parser = OptionParser.new
+parser.on('-x', '--xxx', :REQUIRED, 'Required argument') do |value|
+  p ['--xxx', value]
+end
+parser.parse!
diff --git a/doc/option_params/argument_strings.rb b/doc/option_params/argument_strings.rb
new file mode 100644
index 0000000..77861dd
--- /dev/null
+++ b/doc/option_params/argument_strings.rb
@@ -0,0 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/doc/option_params/argument_strings.rb#L1
+require 'optparse'
+parser = OptionParser.new
+parser.on('-x', '--xxx', '=XXX', 'Required argument') do |value|
+  p ['--xxx', value]
+end
+parser.parse!
diff --git a/doc/option_params/array.rb b/doc/option_params/array.rb
new file mode 100644
index 0000000..7c6c14f
--- /dev/null
+++ b/doc/option_params/array.rb
@@ -0,0 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/doc/option_params/array.rb#L1
+require 'optparse'
+parser = OptionParser.new
+parser.on('--array=ARRAY', Array) do |value|
+  p [value, value.class]
+end
+parser.parse!
diff --git a/doc/option_params/block.rb b/doc/option_params/block.rb
new file mode 100644
index 0000000..c4dfdeb
--- /dev/null
+++ b/doc/option_params/block.rb
@@ -0,0 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/doc/option_params/block.rb#L1
+require 'optparse'
+parser = OptionParser.new
+parser.on('--xxx', 'Option with no argument') do |value|
+  p ['Handler block for -xxx called with value:', value]
+end
+parser.on('--yyy YYY', 'Option with required argument') do |value|
+  p ['Handler block for -yyy called with value:', value]
+end
+parser.parse!
diff --git a/doc/option_params/date.rb b/doc/option_params/date.rb
new file mode 100644
index 0000000..5994ad6
--- /dev/null
+++ b/doc/option_params/date.rb
@@ -0,0 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/doc/option_params/date.rb#L1
+require 'optparse/date'
+parser = OptionParser.new
+parser.on('--date=DATE', Date) do |value|
+  p [value, value.class]
+end
+parser.parse!
diff --git a/doc/option_params/datetime.rb b/doc/option_params/datetime.rb
new file mode 100644
index 0000000..b9b591d
--- /dev/null
+++ b/doc/option_params/datetime.rb
@@ -0,0 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/doc/option_params/datetime.rb#L1
+require 'optparse/date'
+parser = OptionParser.new
+parser.on('--datetime=DATETIME', DateTime) do |value|
+  p [value, value.class]
+end
+parser.parse!
diff --git a/doc/option_params/decimal_integer.rb b/doc/option_params/decimal_integer.rb
new file mode 100644
index 0000000..360bd28
--- /dev/null
+++ b/doc/option_params/decimal_integer.rb
@@ -0,0 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/doc/option_params/decimal_integer.rb#L1
+require 'optparse'
+include OptionParser::Acceptables
+parser = OptionParser.new
+parser.on('--decimal_integer=DECIMAL_INTEGER', DecimalInteger) do |value|
+  p [value, value.class]
+end
+parser.parse!
diff --git a/doc/option_params/decimal_numeric.rb b/doc/option_params/decimal_numeric.rb
new file mode 100644
index 0000000..954da13
--- /dev/null
+++ b/doc/option_params/decimal_numeric.rb
@@ -0,0 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/doc/option_params/decimal_numeric.rb#L1
+require 'optparse'
+include OptionParser::Acceptables
+parser = OptionParser.new
+parser.on('--decimal_numeric=DECIMAL_NUMERIC', DecimalNumeric) do |value|
+  p [value, value.class]
+end
+parser.parse!
diff --git a/doc/option_params/descriptions.rb b/doc/option_params/descriptions.rb
new file mode 100644
index 0000000..9aec80a
--- /dev/null
+++ b/doc/option_params/descriptions.rb
@@ -0,0 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/doc/option_params/descriptions.rb#L1
+require 'optparse'
+parser = OptionParser.new
+description = <<-EOT
+Lorem ipsum dolor sit amet, consectetuer
+adipiscing elit. Aenean commodo ligula eget.
+Aenean massa. Cum sociis natoque penatibus
+et magnis dis parturient montes, nascetur
+ridiculus mus. Donec quam felis, ultricies
+nec, pellentesque eu, pretium quis, sem.
+EOT
+descriptions = description.split($/)
+parser.on('--xxx', *descriptions) do |value|
+  p ['--xxx', value]
+end
+parser.parse!
diff --git a/doc/option_params/explicit_array_values.rb b/doc/option_params/explicit_array_values.rb
new file mode 100644
index 0000000..64f930a
--- /dev/null
+++ b/doc/option_params/explicit_array_values.rb
@@ -0,0 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/doc/option_params/explicit_array_values.rb#L1
+require 'optparse'
+parser = OptionParser.new
+parser.on('-xXXX', ['foo', 'bar'], 'Values for required argument' ) do |value|
+  p ['-x', value]
+end
+parser.on('-y [YYY]', ['baz', 'bat'], 'Values for optional argument') do |value|
+  p ['-y', value]
+end
+parser.parse!
diff --git a/doc/option_params/explicit_hash_values.rb b/doc/option_params/explicit_hash_values.rb
new file mode 100644
index 0000000..9c9e6a4
--- /dev/null
+++ b/doc/option_params/explicit_hash_values.rb
@@ -0,0 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/doc/option_params/explicit_hash_values.rb#L1
+require 'optparse'
+parser = OptionParser.new
+parser.on('-xXXX', {foo: 0, bar: 1}, 'Values for required argument' ) do |value|
+  p ['-x', value]
+end
+parser.on('-y [YYY]', {baz: 2, bat: 3}, 'Values for optional argument') do |value|
+  p ['-y', value]
+end
+parser.parse!
diff --git a/doc/option_params/false_class.rb b/doc/option_params/false_class.rb
new file mode 100644
index 0000000..04fe335
--- /dev/null
+++ b/doc/option_params/false_class.rb
@@ -0,0 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/doc/option_params/false_class.rb#L1
+require  (... truncated)

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

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