Skip to content

Commit 5618eeb

Browse files
Enhanced doc for option parameters (#11)
1 parent 84dfd92 commit 5618eeb

37 files changed

+1106
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'optparse'
2+
parser = OptionParser.new
3+
parser.on('-x', '--xxx', :REQUIRED, 'Required argument') do |value|
4+
p ['--xxx', value]
5+
end
6+
parser.parse!

doc/option_params/argument_strings.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'optparse'
2+
parser = OptionParser.new
3+
parser.on('-x', '--xxx', '=XXX', 'Required argument') do |value|
4+
p ['--xxx', value]
5+
end
6+
parser.parse!

doc/option_params/array.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'optparse'
2+
parser = OptionParser.new
3+
parser.on('--array=ARRAY', Array) do |value|
4+
p [value, value.class]
5+
end
6+
parser.parse!

doc/option_params/block.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'optparse'
2+
parser = OptionParser.new
3+
parser.on('--xxx', 'Option with no argument') do |value|
4+
p ['Handler block for -xxx called with value:', value]
5+
end
6+
parser.on('--yyy YYY', 'Option with required argument') do |value|
7+
p ['Handler block for -yyy called with value:', value]
8+
end
9+
parser.parse!

doc/option_params/date.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'optparse/date'
2+
parser = OptionParser.new
3+
parser.on('--date=DATE', Date) do |value|
4+
p [value, value.class]
5+
end
6+
parser.parse!

doc/option_params/datetime.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'optparse/date'
2+
parser = OptionParser.new
3+
parser.on('--datetime=DATETIME', DateTime) do |value|
4+
p [value, value.class]
5+
end
6+
parser.parse!

doc/option_params/decimal_integer.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'optparse'
2+
include OptionParser::Acceptables
3+
parser = OptionParser.new
4+
parser.on('--decimal_integer=DECIMAL_INTEGER', DecimalInteger) do |value|
5+
p [value, value.class]
6+
end
7+
parser.parse!

doc/option_params/decimal_numeric.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'optparse'
2+
include OptionParser::Acceptables
3+
parser = OptionParser.new
4+
parser.on('--decimal_numeric=DECIMAL_NUMERIC', DecimalNumeric) do |value|
5+
p [value, value.class]
6+
end
7+
parser.parse!

doc/option_params/descriptions.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'optparse'
2+
parser = OptionParser.new
3+
description = <<-EOT
4+
Lorem ipsum dolor sit amet, consectetuer
5+
adipiscing elit. Aenean commodo ligula eget.
6+
Aenean massa. Cum sociis natoque penatibus
7+
et magnis dis parturient montes, nascetur
8+
ridiculus mus. Donec quam felis, ultricies
9+
nec, pellentesque eu, pretium quis, sem.
10+
EOT
11+
descriptions = description.split($/)
12+
parser.on('--xxx', *descriptions) do |value|
13+
p ['--xxx', value]
14+
end
15+
parser.parse!
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'optparse'
2+
parser = OptionParser.new
3+
parser.on('-xXXX', ['foo', 'bar'], 'Values for required argument' ) do |value|
4+
p ['-x', value]
5+
end
6+
parser.on('-y [YYY]', ['baz', 'bat'], 'Values for optional argument') do |value|
7+
p ['-y', value]
8+
end
9+
parser.parse!

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy