override among command line and config file options
"Papp Gyozo (VBuster)" <[email protected]> Mon, 07 Apr 2008 16:17:11 +0200
| Newsgroups | gmane.comp.gnu.gengetopt.general |
|---|---|
| Message-ID | <[email protected]> |
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], ... ));
--
Papp, Gyozo
Virusbuster Kft