From: "Jesús Gabriel y Galán" Date: 2007-10-09T01:07:03+09:00 Subject: Re: optparse and required switches On 10/8/07, Felix Windt wrote: > > [mailto:list-bounce@example.com] On Behalf Of Roger Nordqvist > > Im lost with optparse. > > > > Got a couple of questions if its OK. > > > > 1. I've been reading the documentation but I cant get it into my thick > > head how I tell an option that it is required or optional? I guess all > > opts are optional initially, but how do I say that an option is > > required. > > > > I don't think support for that is built into optparse - you'll have to set > flags from the options parsed and then throw an error if a certain flag > isn't set. For this it might be worth to look into CodeForPeople's main gem (gem install main). I've been using it in a couple of things lately and am quite happy. You can specify if an option is required or not, and if it has arguments which are required or not, etc. in a very simple syntax. require 'main' main { option("verbose", "v") { required } } Hope this helps, Jesus.