Ruby cli

From wikinotes
Revision as of 15:21, 29 October 2022 by Will (talk | contribs) (Created page with " = Param Parsing, Raw = <blockquote> <syntaxhighlight lang="ruby"> #!/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 </syntaxhighlight> </blockquote><!-- Param Parsing -->")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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