digitalmars.D.learn - crash on args.getopt
- Suliman (40/40) Jan 24 2015 First of all it's seems bug in docs:
- Tobias Pankrath (2/21) Jan 24 2015 Look for "Passing unrecognized options through" in the
- Suliman (3/5) Jan 24 2015 Oh I see, but first part of question is still actual.
- ketmar (3/8) Jan 24 2015 well... you can skip writing custom parser and use `getopt` instead. the...
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (19/34) Jan 24 2015 What version is your compiler? The example compiles as is with git head
- Suliman (9/9) Jan 24 2015 Ali, you are right it's my error:
- ketmar (2/13) Jan 24 2015 exactly.=
- ketmar (2/13) Jan 24 2015 just a minor detail: "UFCS style", as "S" un "UFCS" means "syntax". ;-)=
- Suliman (5/5) Jan 25 2015 But is it good practice to fail with exception during passing
- Tobias Pankrath (3/8) Jan 25 2015 Almost all programs fail with an error message, if you pass
- FG (3/8) Jan 25 2015 It's much better to fail up front than to create the illusion that every...
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)
Jan 24 2015
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.
Jan 24 2015
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?
Jan 24 2015
On Sat, 24 Jan 2015 19:55:10 +0000, Suliman wrote:well... you can skip writing custom parser and use `getopt` instead. the=20 documentation has alot of examples of what `getopt` can do for you.=Look for "Passing unrecognized options through" in the documentation.Oh I see, but first part of question is still actual. =20 And also what is benefits of using getopt instead of parsing args[] manually?
Jan 24 2015
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 insteadWhat 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
Jan 24 2015
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?
Jan 24 2015
On Sun, 25 Jan 2015 05:34:15 +0000, Suliman wrote:Ali, you are right it's my error: =20 getopt( args, =20 and I did: args.getopt ( args, =20 =20 Am I right understand that "args" in "args.getopt" is UFCS syntax style?exactly.=
Jan 24 2015
On Sun, 25 Jan 2015 05:34:15 +0000, Suliman wrote:Ali, you are right it's my error: =20 getopt( args, =20 and I did: args.getopt ( args, =20 =20 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". ;-)=
Jan 24 2015
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.
Jan 25 2015
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.
Jan 25 2015
On 2015-01-25 at 11:42, Tobias Pankrath wrote:On Sunday, 25 January 2015 at 10:21:34 UTC, Suliman wrote:It's much better to fail up front than to create the illusion that everything is fine after the user has mistyped one of the parameters. Let's say "foo a b" copies from a to b, but "foo --reverse a b" does the opposite. Then, when someone types for example "foo --revrse a b", and it is silently accepted, the program does exactly the opposite of what the user expects! A side note: GTK applications accept extra parameters used to initialize GTK, but it is not passThrough. What really happens is that the app calls gtk_init(&argc, &argv) (or Main.init(args) in case of GtkD) before it starts parsing arguments on its own. The call to gtk_init removes the options recognized by GTK from the list of program arguments, and this filtered array can be then processed in a normal way -- which means that whichever parameters are still left unrecognised, the program should fail with an error message.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.
Jan 25 2015