digitalmars.D.learn - getopt Basic usage
- James Gray (31/31) Aug 14 2020 I am trying to use getopt and would not like the program to throw
- mw (4/8) Aug 14 2020 life is short, use a good library (instead of the raw std lib, or
- James Gray (2/10) Aug 15 2020 I will have a look at that. Thanks.
- MoonlightSentinel (3/5) Aug 15 2020 Try passing config.passThrough, it should disable the exception
- James Gray (5/10) Aug 15 2020 Thanks a lot for the suggestion. But to me that will produce a
- Jon Degenhardt (5/9) Aug 15 2020 I use the approach you showed, except for writing errors to
- James Gray (2/11) Aug 15 2020 Thank you I will have a look at the link.
I am trying to use getopt and would not like the program to throw an unhandled exception when parsing command line options. Is the following, adapted from the first example in the getopt documentation, a reasonable approach? import std.getopt; string data = "file.dat"; int length = 24; bool verbose; enum Color { no, yes }; Color color; void main(string[] args) { try { auto helpInformation = getopt( args, std.getopt.config.stopOnFirstNonOption, "length", &length, // numeric "file", &data, // string "verbose", &verbose, // flag "color", "Information about this color", &color); // enum if (helpInformation.helpWanted) { defaultGetoptPrinter("Some information about the program.", helpInformation.options); } } catch(Exception e) { import std.stdio : writeln; writeln(e.msg, "\nFor more information use --help"); } }
Aug 14 2020
On Saturday, 15 August 2020 at 04:09:19 UTC, James Gray wrote:I am trying to use getopt and would not like the program to throw an unhandled exception when parsing command line options. Is the following, adapted from the first example in the getopt documentation, a reasonable approach?life is short, use a good library (instead of the raw std lib, or re-invent the wheels): https://code.dlang.org/packages/commandr
Aug 14 2020
On Saturday, 15 August 2020 at 04:39:58 UTC, mw wrote:On Saturday, 15 August 2020 at 04:09:19 UTC, James Gray wrote:I will have a look at that. Thanks.I am trying to use getopt and would not like the program to throw an unhandled exception when parsing command line options. Is the following, adapted from the first example in the getopt documentation, a reasonable approach?life is short, use a good library (instead of the raw std lib, or re-invent the wheels): https://code.dlang.org/packages/commandr
Aug 15 2020
On Saturday, 15 August 2020 at 04:09:19 UTC, James Gray wrote:I am trying to use getopt and would not like the program to throw an unhandled exception when parsing command line options.Try passing config.passThrough, it should disable the exception for unknown arguments.
Aug 15 2020
On Saturday, 15 August 2020 at 09:48:26 UTC, MoonlightSentinel wrote:On Saturday, 15 August 2020 at 04:09:19 UTC, James Gray wrote:Thanks a lot for the suggestion. But to me that will produce a program with very unusual behaviour (i.e. ignoring unrecognised arguments).I am trying to use getopt and would not like the program to throw an unhandled exception when parsing command line options.Try passing config.passThrough, it should disable the exception for unknown arguments.
Aug 15 2020
On Saturday, 15 August 2020 at 04:09:19 UTC, James Gray wrote:I am trying to use getopt and would not like the program to throw an unhandled exception when parsing command line options. Is the following, adapted from the first example in the getopt documentation, a reasonable approach?I use the approach you showed, except for writing errors to stderr and returning an exit status. This has worked fine. An example: https://github.com/eBay/tsv-utils/blob/master/number-lines/src/tsv_utils/number-lines.d#L48
Aug 15 2020
On Saturday, 15 August 2020 at 17:04:17 UTC, Jon Degenhardt wrote:On Saturday, 15 August 2020 at 04:09:19 UTC, James Gray wrote:Thank you I will have a look at the link.I am trying to use getopt and would not like the program to throw an unhandled exception when parsing command line options. Is the following, adapted from the first example in the getopt documentation, a reasonable approach?I use the approach you showed, except for writing errors to stderr and returning an exit status. This has worked fine. An example: https://github.com/eBay/tsv-utils/blob/master/number-lines/src/tsv_utils/number-lines.d#L48
Aug 15 2020