From: Jim Freeze Date: 2005-11-08T15:57:59+09:00 Subject: Re: CommandLine-0.7.10 On 11/7/05, Gavin Sinclair wrote: > Jim Freeze wrote: > > > > * I want to write an application that inherits a different class. Can > > > I still use this library? > > > > Good question. Can you give me an example. > > Say I have a company-specific application class (which I don't, but > let's pretend) called AcmeApp, which all applications are to inherit. > Say I also want to use your library. I'd like to see the option > parsing be independent of the application. Perhaps something like > this: > > class AppOptions < CommandLine::OptionParser > author "Gavin Sinclair" > description "blah blah blah" > options :help, :debug > option :names => %w(--remove -R), # ... > expected_args :file > end > > class App < AcmeApp > def App.run(args) > options = AppOptions.parse(args) > if options.debug > ... > elsif options.remove > ... > end > end > end > > App.run(ARGV) Your AppOptions is basically playing the role of the Application class here. :) The author, description, etc.. are methods of Application. They add to the formatted output of OptionParser. All the hard work is done by OptionParser. You could use OptionParser similar to what you have above, but you won't get the convenience of the Application wrappers, unless of course you write your own. That is originally why this project started out as OptionParser. Then I started encapsulating some common scenarios, and Application was born. > Oh I see... > > A few small applications I'm working have a common base class. I'll > see if I can rearrange the code or otherwise get it working with the > CommandLine library. Otherwise I might have some more specific > suggestions. Yes. Your app class is just the interface to collect the arguments from the command line. You should be able to keep the app class completely separate. If not, I would be interesting in knowing why to see if we need to adjust some things. -- Jim Freeze