Really Cheap Command-Line Option Parsing in Ruby

前端 未结 20 1123
野的像风
野的像风 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:00

    I totally understand why you want to avoid optparse - it can get too much. But there are a few far "lighter" solutions (compared to OptParse) that come as libraries but are simple enough to make a single gem installation worthwhile.

    For example, check out this OptiFlag example. Just a few lines for the processing. A slightly truncated example tailored to your case:

    require 'optiflag'
    
    module Whatever extend OptiFlagSet
      flag "f"
      and_process!
    end 
    
    ARGV.flags.f # => .. whatever ..
    

    There are tons of customized examples too. I recall using another that was even easier, but it has escaped me for now but I will come back and add a comment here if I find it.

提交回复
热议问题