Really Cheap Command-Line Option Parsing in Ruby

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

    I'm developing my own option parser gem called Acclaim.

    I wrote it because I wanted to create git-style command line interfaces and be able to cleanly separate the functionality of each command into separate classes, but it can also be used without the entire command framework as well:

    (options = []) << Acclaim::Option.new(:verbose, '-v', '--verbose')
    values = Acclaim::Option::Parser.new(ARGV, options).parse!
    puts 'Verbose.' if values.verbose?
    

    No stable release as of yet, but I've already implemented some features like:

    • custom option parser
    • flexible parsing of option's arguments that allows for both minimum and optional
    • support for many option styles
    • replace, append or raise on multiple instances of the same option
    • custom option handlers
    • custom type handlers
    • predefined handlers for the common standard library classes

    There's a lot of emphasis on commands so it might be a little heavy for simple command line parsing but it works well and I've been using it on all of my projects. If you're interested in the command interface aspect then check out the project's GitHub page for more information and examples.

提交回复
热议问题