help-gengetopt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [help-gengetopt] override among command line and config file options


From: Lorenzo Bettini
Subject: Re: [help-gengetopt] override among command line and config file options
Date: Sun, 20 Apr 2008 12:27:45 +0200
User-agent: Thunderbird 2.0.0.12 (X11/20080227)

Papp Gyozo (VBuster) wrote:
Hi there,
I have another problem with no proper solution up to now.

The basic logic of my app is the following:

1) parse commandline (getoptions_ext)
2) try to locate a config file (depends on command line options)
3) parse configfile with no override and no initialize to the same cmdline 
structure
4) check required fields

We stated in the docs for a while that commandline options take precedence over 
config file. It causes me a little problem at least with group options (these 
are the old mutual exclusive options, Lorenzo ;)

If an option from a group is given in commandline and in the config file, the generatad parser returns an error:
"vbscan: 2 options of group ... were given. At most one is required. in 
configuration file vbscan.ini" (*)

Of course, if I allow override during config file parsing, this error won't raise. However config file options should not override any previously set options.
I think what I came to my mind so far would not be not so popular.

i) move all (or almost all) checking to a dedicated function like require and 
call this function at the very end of parsing when nothing modifies the option 
structure. Well actually it may cause compatibility breaks in many 
applications. However I think it would be great anyway apart from the current 
situation.

ii) use two different option structure one for commandline and an other for configfile, and then merge manually or
iii) by tweaking the current logic:
  - parse commandline into temporary struct to get out the name of the 
configfile
  - parse config file into final struct
  - parse again commandline into final struct with override(!)

Do you know a better approach to circumvent this situation?



(*) there is a small typo in the error message string. The closing dot is 
before the %s format argument. It should be:

      fprintf (stderr, "%s: %d options of group ... were given. At most one is 
required%s.\n", argv[0], ... ));





Hi there

sorry for my silence but it was a busy week :-)

are you suggesting something to be implemented in the generated code or proposing some programming idioms? I just want to be sure I understand correctly...

cheers
        Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134     (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net





reply via email to

[Prev in Thread] Current Thread [Next in Thread]