From 4b6936aa047158c98a9ac8861d51e5e09229f8c0 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 16 Jan 2024 16:30:32 +0900 Subject: [PATCH] Unbundled samples for getoptlong --- sample/getoptlong/abbrev.rb | 9 ---- sample/getoptlong/aliases.rb | 8 ---- sample/getoptlong/argv.rb | 12 ------ sample/getoptlong/each.rb | 12 ------ sample/getoptlong/fibonacci.rb | 62 ---------------------------- sample/getoptlong/permute.rb | 12 ------ sample/getoptlong/require_order.rb | 13 ------ sample/getoptlong/return_in_order.rb | 13 ------ sample/getoptlong/simple.rb | 7 ---- sample/getoptlong/types.rb | 10 ----- 10 files changed, 158 deletions(-) delete mode 100644 sample/getoptlong/abbrev.rb delete mode 100644 sample/getoptlong/aliases.rb delete mode 100644 sample/getoptlong/argv.rb delete mode 100644 sample/getoptlong/each.rb delete mode 100644 sample/getoptlong/fibonacci.rb delete mode 100644 sample/getoptlong/permute.rb delete mode 100644 sample/getoptlong/require_order.rb delete mode 100644 sample/getoptlong/return_in_order.rb delete mode 100644 sample/getoptlong/simple.rb delete mode 100644 sample/getoptlong/types.rb diff --git a/sample/getoptlong/abbrev.rb b/sample/getoptlong/abbrev.rb deleted file mode 100644 index 9b89863626..0000000000 --- a/sample/getoptlong/abbrev.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', GetoptLong::NO_ARGUMENT], - ['--xyz', GetoptLong::NO_ARGUMENT] -) -options.each do |option, argument| - p [option, argument] -end diff --git a/sample/getoptlong/aliases.rb b/sample/getoptlong/aliases.rb deleted file mode 100644 index 895254c6ae..0000000000 --- a/sample/getoptlong/aliases.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', '-x', '--aaa', '-a', '-p', GetoptLong::NO_ARGUMENT] -) -options.each do |option, argument| - p [option, argument] -end diff --git a/sample/getoptlong/argv.rb b/sample/getoptlong/argv.rb deleted file mode 100644 index 8efcad22ea..0000000000 --- a/sample/getoptlong/argv.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', GetoptLong::NO_ARGUMENT] -) -puts "Original ARGV: #{ARGV}" -options.each do |option, argument| - p [option, argument] -end -puts "Remaining ARGV: #{ARGV}" diff --git a/sample/getoptlong/each.rb b/sample/getoptlong/each.rb deleted file mode 100644 index 661e0a968f..0000000000 --- a/sample/getoptlong/each.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', '-x', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', '-y', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', '-z',GetoptLong::NO_ARGUMENT] -) -puts "Original ARGV: #{ARGV}" -options.each do |option, argument| - p [option, argument] -end -puts "Remaining ARGV: #{ARGV}" diff --git a/sample/getoptlong/fibonacci.rb b/sample/getoptlong/fibonacci.rb deleted file mode 100644 index 24a2aab3c3..0000000000 --- a/sample/getoptlong/fibonacci.rb +++ /dev/null @@ -1,62 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--number', '-n', GetoptLong::REQUIRED_ARGUMENT], - ['--verbose', '-v', GetoptLong::OPTIONAL_ARGUMENT], - ['--help', '-h', GetoptLong::NO_ARGUMENT] -) - -def help(status = 0) - puts <<~HELP - Usage: - - -n n, --number n: - Compute Fibonacci number for n. - -v [boolean], --verbose [boolean]: - Show intermediate results; default is 'false'. - -h, --help: - Show this help. - HELP - exit(status) -end - -def print_fibonacci (number) - return 0 if number == 0 - return 1 if number == 1 or number == 2 - i = 0 - j = 1 - (2..number).each do - k = i + j - i = j - j = k - puts j if @verbose - end - puts j unless @verbose -end - -options.each do |option, argument| - case option - when '--number' - @number = argument.to_i - when '--verbose' - @verbose = if argument.empty? - true - elsif argument.match(/true/i) - true - elsif argument.match(/false/i) - false - else - puts '--verbose argument must be true or false' - help(255) - end - when '--help' - help - end -end - -unless @number - puts 'Option --number is required.' - help(255) -end - -print_fibonacci(@number) diff --git a/sample/getoptlong/permute.rb b/sample/getoptlong/permute.rb deleted file mode 100644 index 8efcad22ea..0000000000 --- a/sample/getoptlong/permute.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', GetoptLong::NO_ARGUMENT] -) -puts "Original ARGV: #{ARGV}" -options.each do |option, argument| - p [option, argument] -end -puts "Remaining ARGV: #{ARGV}" diff --git a/sample/getoptlong/require_order.rb b/sample/getoptlong/require_order.rb deleted file mode 100644 index 357f667905..0000000000 --- a/sample/getoptlong/require_order.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', GetoptLong::NO_ARGUMENT] -) -options.ordering = GetoptLong::REQUIRE_ORDER -puts "Original ARGV: #{ARGV}" -options.each do |option, argument| - p [option, argument] -end -puts "Remaining ARGV: #{ARGV}" diff --git a/sample/getoptlong/return_in_order.rb b/sample/getoptlong/return_in_order.rb deleted file mode 100644 index 91ce1ef996..0000000000 --- a/sample/getoptlong/return_in_order.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', GetoptLong::NO_ARGUMENT] -) -options.ordering = GetoptLong::RETURN_IN_ORDER -puts "Original ARGV: #{ARGV}" -options.each do |option, argument| - p [option, argument] -end -puts "Remaining ARGV: #{ARGV}" diff --git a/sample/getoptlong/simple.rb b/sample/getoptlong/simple.rb deleted file mode 100644 index 1af6447632..0000000000 --- a/sample/getoptlong/simple.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--number', '-n', GetoptLong::REQUIRED_ARGUMENT], - ['--verbose', '-v', GetoptLong::OPTIONAL_ARGUMENT], - ['--help', '-h', GetoptLong::NO_ARGUMENT] -) diff --git a/sample/getoptlong/types.rb b/sample/getoptlong/types.rb deleted file mode 100644 index ac74bfe12e..0000000000 --- a/sample/getoptlong/types.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'getoptlong' - -options = GetoptLong.new( - ['--xxx', GetoptLong::REQUIRED_ARGUMENT], - ['--yyy', GetoptLong::OPTIONAL_ARGUMENT], - ['--zzz', GetoptLong::NO_ARGUMENT] -) -options.each do |option, argument| - p [option, argument] -end