Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
August 26, 2013 std.getopt error | ||||
---|---|---|---|---|
| ||||
There seems to be a bug in std.getopt. D doc says: "To set timeout to 5, use either of the following: --timeout=5, --timeout 5, --t=5, --t 5, or ** -t5 **. Forms such as -t 5 and -timeout=5 will be not accepted." However bool reverseOrder = false, helpFlag = false; int colOrder = 1; getopt(args, std.getopt.config.bundling, "reverse|r", &reverseOrder, "column|c", &colOrder,"help|?", &helpFlag); sets colOrder to -1 rather than to +1 when the commandline has "-c1" as arg. Funnily, when the arg is *illegally* "-c 1", the variable is set correctly to +1. This is not an urgent issue because there is a very simple workaround: colorder = - colorder; But I thought it should be mentioned anyway and, if not noticed it can create troublesome situations. Being at that, the official rule "-t 5" is not acceptable is problematic because that form is pretty commonly used on unix and even sometimes used in docs. - R |
August 26, 2013 Re: std.getopt error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ramon | On Monday, 26 August 2013 at 06:58:41 UTC, Ramon wrote: > There seems to be a bug in std.getopt. > > D doc says: > "To set timeout to 5, use either of the following: --timeout=5, --timeout 5, --t=5, --t 5, or ** -t5 **. Forms such as -t 5 and -timeout=5 will be not accepted." > > However > > bool reverseOrder = false, helpFlag = false; > int colOrder = 1; > > getopt(args, std.getopt.config.bundling, "reverse|r", &reverseOrder, "column|c", &colOrder,"help|?", &helpFlag); > > sets colOrder to -1 rather than to +1 when the commandline has "-c1" as arg. > > Funnily, when the arg is *illegally* "-c 1", the variable is set correctly to +1. > Given: int colOrder = 1; ... Could it be that "-c 1" is ignored because it is in invalid and the default colOrder value is used? > This is not an urgent issue because there is a very simple workaround: > colorder = - colorder; > > But I thought it should be mentioned anyway and, if not noticed it can create troublesome situations. > > Being at that, the official rule "-t 5" is not acceptable is problematic because that form is pretty commonly used on unix and even sometimes used in docs. +1 I've noticed this before when using getopt. It is low priority and a documented limitation but it would be nice if "-t 5" worked. G. |
August 26, 2013 Re: std.getopt error | ||||
---|---|---|---|---|
| ||||
Posted in reply to growler | On Monday, 26 August 2013 at 07:06:07 UTC, growler wrote:
> Given:
>
> int colOrder = 1;
> ...
> Could it be that "-c 1" is ignored because it is in invalid and the default colOrder value is used?
Sorry for expressing myself clumsily.
if the commandline arg is "-c 1" (which according to getopt doc is illegal) it actually *does* work properly.
if the commandline arg is "-c1" (which according to getopt doc is legal) then the result of getopt is false/wrong.
"-c 1" then sets the variable to -1.
Same with 2. So the problem is not 1 or 1 being the var default.
Thanks - R
|
August 26, 2013 Re: std.getopt error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ramon | On Monday, 26 August 2013 at 07:20:11 UTC, Ramon wrote:
> On Monday, 26 August 2013 at 07:06:07 UTC, growler wrote:
>> Given:
>>
>> int colOrder = 1;
>> ...
>> Could it be that "-c 1" is ignored because it is in invalid and the default colOrder value is used?
>
> Sorry for expressing myself clumsily.
>
> if the commandline arg is "-c 1" (which according to getopt doc is illegal) it actually *does* work properly.
>
> if the commandline arg is "-c1" (which according to getopt doc is legal) then the result of getopt is false/wrong.
> "-c 1" then sets the variable to -1.
>
> Same with 2. So the problem is not 1 or 1 being the var default.
>
> Thanks - R
Cool, sorry for the noise. I was in a hurry leaving work and didn't have time to test the idea.
Cheers,
G
|
August 28, 2013 Re: std.getopt error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ramon | On Mon, Aug 26, 2013 at 09:20:09AM +0200, Ramon wrote: > On Monday, 26 August 2013 at 07:06:07 UTC, growler wrote: > >Given: > > > >int colOrder = 1; > >... > >Could it be that "-c 1" is ignored because it is in invalid and > >the default colOrder value is used? > > Sorry for expressing myself clumsily. > > if the commandline arg is "-c 1" (which according to getopt doc is illegal) it actually *does* work properly. > > if the commandline arg is "-c1" (which according to getopt doc is > legal) then the result of getopt is false/wrong. > "-c 1" then sets the variable to -1. > > Same with 2. So the problem is not 1 or 1 being the var default. [...] I'd say file a bug for this, since the docs claim that -c1 works, but actually it doesn't. T -- It only takes one twig to burn down a forest. |
Copyright © 1999-2021 by the D Language Foundation