[Top][All Lists]

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

Re: [help-gengetopt] Ambiguity elimination by using both command line op

From: Yegor Yefremov
Subject: Re: [help-gengetopt] Ambiguity elimination by using both command line options and configuration file
Date: Wed, 13 Jun 2007 09:34:18 +0200
User-agent: Thunderbird (Windows/20070326)

Lorenzo Bettini wrote:
Yegor Yefremov wrote:
Dear list,

I have following situation:
I have both command line parameters and configuration file and I want
prevent defining the same option in both command line and configuration
file. At first I parse the command line options to obtain the configfile
file name and then I parse the configfile. When I define the option in
both I don't get any error. The program can check if I defined two
options in the same command line but it can't check it if I defined them
both in command line and configuration file due to the fact, that only
local_args_info will be checked. I think it is important issue to reduce
debugging overhead when operating with both command line and
configuration file.

Hi there

as you proposed in a previous private email, one solution could be to
add a command line option


in order to make the parser check for these ambiguities...

another solution might be to use different args_info structures for
parsing the configuration file and the command line and use a function
generated by gengetopt, e.g., check_dup (similar to the check_required
generated function) that checks that non multiple options are not
specified in both structures, what do you think?

This would avoid overwhelming the parser function with many parameters...

or did you mean that, when --conf-parser-noambiguity is specified and
override is 0 when passed to the parser function, then a duplicate would
generate an error?  Did you mean that --conf-parser-noambiguity should
be a command line option or a gengetopt's command line option?


Hi Lorenzo

my suggestion about --conf-parser-noambiguity was for gengetopt's command line option as --conf-parser itself. I think it will be easier to implement as to define another structure. Here the example how to check the occurrence of the option:

       else if (strcmp (long_options[option_index].name, "cycles") == 0)
if (local_args_info.cycles_given || (args_info.cycles_given && !override)) // additional check
fprintf (stderr, "%s: `--cycles' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
               goto failure;

I think it would do the job.


reply via email to

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