Really Cheap Command-Line Option Parsing in Ruby

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

    EasyOptions does not require any option parsing code at all. Just write the help text, require, done.

    ## Options:
    ##   -i, --interactive  Interactive mode
    ##   -q, --quiet        Silent mode
    
    require 'easyoptions'
    unless EasyOptions.options[:quiet]
        puts 'Interactive mode enabled' if EasyOptions.options[:interactive]
        EasyOptions.arguments.each { |item| puts "Argument: #{item}" }
    end
    

提交回复
热议问题