Really Cheap Command-Line Option Parsing in Ruby

前端 未结 20 1077
野的像风
野的像风 2020-11-30 16:57

EDIT: Please, please, please read the two requirements listed at the bottom of this post before replying. People keep posting their new gems and li

20条回答
  •  一整个雨季
    2020-11-30 17:20

    Here's my favorite quick-and-dirty option parser:

    case ARGV.join
    when /-h/
      puts "help message"
      exit
    when /-opt1/
      puts "running opt1"
    end
    

    The options are regular expressions, so "-h" also would match "--help".

    Readable, easy to remember, no external library, and minimal code.

提交回复
热议问题