Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 24, 2015 crash on args.getopt | ||||
---|---|---|---|---|
| ||||
First of all it's seems bug in docs: void main(string[] args) { getopt( args, "length", &length, // numeric "file", &data, // string "verbose", &verbose, // flag "color", &color); // enum ... } with args inside getopt I am getting: C:\D\dmd2\windows\bin\..\..\src\phobos\std\getopt.d(547): Deprecation: using * o n an array is deprecated; use *(receiver).ptr instead C:\D\dmd2\windows\bin\..\..\src\phobos\std\getopt.d(547): Error: cannot modify i mmutable expression *cast(immutable(char)*)receiver C:\D\dmd2\windows\bin\..\..\src\phobos\std\getopt.d(548): Deprecation: using * o n an array is deprecated; use *(receiver).ptr instead http://dlang.org/phobos/std_getopt.html But problem that I do not know how handle not existing values: void main(string[] args) { args.getopt ( "help", &help ); } app.exe -sss causes crash: std.getopt.GetOptException@C:\D\dmd2\windows\bin\..\..\src\phobos\std\getopt.d(4 63): Unrecognized option -sss ---------------- 0x00453F0E in @safe void std.getopt.getoptImpl!().getoptImpl(ref immutable(char) [][], ref std.getopt.configuration) at C:\D\dmd2\windows\bin\..\..\src\phobos\st d\getopt.d(463) |
January 24, 2015 Re: crash on args.getopt | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | > http://dlang.org/phobos/std_getopt.html
>
> But problem that I do not know how handle not existing values:
>
> void main(string[] args)
> {
> args.getopt
> (
> "help", &help
> );
> }
>
> app.exe -sss
> causes crash:
> std.getopt.GetOptException@C:\D\dmd2\windows\bin\..\..\src\phobos\std\getopt.d(4
> 63): Unrecognized option -sss
> ----------------
> 0x00453F0E in @safe void std.getopt.getoptImpl!().getoptImpl(ref immutable(char)
> [][], ref std.getopt.configuration) at C:\D\dmd2\windows\bin\..\..\src\phobos\st
> d\getopt.d(463)
Look for "Passing unrecognized options through" in the documentation.
|
January 24, 2015 Re: crash on args.getopt | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tobias Pankrath | > Look for "Passing unrecognized options through" in the documentation.
Oh I see, but first part of question is still actual.
And also what is benefits of using getopt instead of parsing args[] manually?
|
January 24, 2015 Re: crash on args.getopt | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman Attachments: | On Sat, 24 Jan 2015 19:55:10 +0000, Suliman wrote:
>> Look for "Passing unrecognized options through" in the documentation.
> Oh I see, but first part of question is still actual.
>
> And also what is benefits of using getopt instead of parsing args[] manually?
well... you can skip writing custom parser and use `getopt` instead. the documentation has alot of examples of what `getopt` can do for you.
|
January 24, 2015 Re: crash on args.getopt | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On 01/24/2015 11:39 AM, Suliman wrote: > First of all it's seems bug in docs: > void main(string[] args) > { > getopt( > args, > "length", &length, // numeric > "file", &data, // string > "verbose", &verbose, // flag > "color", &color); // enum > ... > } > > with args inside getopt I am getting: > C:\D\dmd2\windows\bin\..\..\src\phobos\std\getopt.d(547): Deprecation: > using * o > n an array is deprecated; use *(receiver).ptr instead What version is your compiler? The example compiles as is with git head dmd (after removing the ellipsis): import std.getopt; string data = "file.dat"; int length = 24; bool verbose; enum Color { no, yes }; Color color; void main(string[] args) { getopt( args, "length", &length, // numeric "file", &data, // string "verbose", &verbose, // flag "color", &color); // enum } Ali |
January 25, 2015 Re: crash on args.getopt | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | Ali, you are right it's my error: getopt( args, and I did: args.getopt ( args, Am I right understand that "args" in "args.getopt" is UFCS syntax style? |
January 25, 2015 Re: crash on args.getopt | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman Attachments: | On Sun, 25 Jan 2015 05:34:15 +0000, Suliman wrote:
> Ali, you are right it's my error:
>
> getopt(
> args,
>
> and I did:
> args.getopt (
> args,
>
>
> Am I right understand that "args" in "args.getopt" is UFCS syntax style?
exactly.
|
January 25, 2015 Re: crash on args.getopt | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman Attachments: | On Sun, 25 Jan 2015 05:34:15 +0000, Suliman wrote:
> Ali, you are right it's my error:
>
> getopt(
> args,
>
> and I did:
> args.getopt (
> args,
>
>
> Am I right understand that "args" in "args.getopt" is UFCS syntax style?
just a minor detail: "UFCS style", as "S" un "UFCS" means "syntax". ;-)
|
January 25, 2015 Re: crash on args.getopt | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | But is it good practice to fail with exception during passing unknown parameters? Maybe std.getopt.config.passThrough should be as default? I really can't remember Apps that crush if pass to in unknown parameters. |
January 25, 2015 Re: crash on args.getopt | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | On Sunday, 25 January 2015 at 10:21:34 UTC, Suliman wrote:
> But is it good practice to fail with exception during passing unknown parameters? Maybe std.getopt.config.passThrough should be as default?
>
> I really can't remember Apps that crush if pass to in unknown parameters.
Almost all programs fail with an error message, if you pass unknown parameter. Just catch that exception.
|
Copyright © 1999-2021 by the D Language Foundation