-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added example in "Argument Converters"; it doesn't seem right for a tutorial to have no example in one of its topics (and instead just linking elsewhere). - Added section "Command-Line Abbreviations." - Added section "Keyword Argument into," showing how to: - Collect options. - Check for missing options. - Provide option defaults.
- Loading branch information
1 parent
c91ed8d
commit 39d3967
Showing
6 changed files
with
180 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'optparse' | ||
parser = OptionParser.new | ||
parser.on('-n', '--dry-run',) do |value| | ||
p ['--dry-run', value] | ||
end | ||
parser.on('-d', '--draft',) do |value| | ||
p ['--draft', value] | ||
end | ||
parser.parse! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'optparse' | ||
parser = OptionParser.new | ||
parser.on('-x', '--xxx', 'Short and long, no argument') | ||
parser.on('-yYYY', '--yyy', 'Short and long, required argument') | ||
parser.on('-z [ZZZ]', '--zzz', 'Short and long, optional argument') | ||
options = {} | ||
parser.parse!(into: options) | ||
p options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'optparse' | ||
parser = OptionParser.new | ||
parser.on('-x', '--xxx', 'Short and long, no argument') | ||
parser.on('-yYYY', '--yyy', 'Short and long, required argument') | ||
parser.on('-z [ZZZ]', '--zzz', 'Short and long, optional argument') | ||
options = {yyy: 'AAA', zzz: 'BBB'} | ||
parser.parse!(into: options) | ||
p options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'optparse' | ||
parser = OptionParser.new | ||
parser.on('-x', '--xxx', 'Short and long, no argument') | ||
parser.on('-yYYY', '--yyy', 'Short and long, required argument') | ||
parser.on('-z [ZZZ]', '--zzz', 'Short and long, optional argument') | ||
options = {} | ||
parser.parse!(into: options) | ||
required_options = [:xxx, :zzz] | ||
missing_options = required_options - options.keys | ||
unless missing_options.empty? | ||
fail "Missing required options: #{missing_options}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'optparse' | ||
parser = OptionParser.new | ||
parser.on('-n', '--dry-run',) do |value| | ||
p ['--dry-run', value] | ||
end | ||
parser.on('-d', '--draft',) do |value| | ||
p ['--draft', value] | ||
end | ||
parser.require_exact = true | ||
parser.parse! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters