Ruby cli: Difference between revisions
From wikinotes
Line 21: | Line 21: | ||
puts(help_msg) | puts(help_msg) | ||
exit(0) | exit(0) | ||
else | else | ||
puts "error" | puts "error" | ||
exit(1) | exit(1) | ||
end | end | ||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Param Parsing --> | </blockquote><!-- Param Parsing --> |
Revision as of 15:22, 29 October 2022
Param Parsing, Raw
#!/usr/bin/env ruby EXECUTABLE = File.basename(__FILE__) ARGV.count.times do |index| case ARGV[index] when '-h', '--help' help_msg <<~HELP #{EXECUTABLE} [-h] DESCRIPTION: does things PARAMS: $1: foo HELP puts(help_msg) exit(0) else puts "error" exit(1) end end