Re: getopt Basic usage

2020-08-15 Thread James Gray via Digitalmars-d-learn

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 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


I will have a look at that. Thanks.


Re: getopt Basic usage

2020-08-15 Thread James Gray via Digitalmars-d-learn
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:
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.


Thanks a lot for the suggestion. But to me that will produce a 
program with very unusual behaviour (i.e. ignoring unrecognised 
arguments).


Re: getopt Basic usage

2020-08-15 Thread James Gray via Digitalmars-d-learn

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:
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


Thank you I will have a look at the link.


Cannot call @system funciton (stdout)

2020-08-15 Thread Joel via Digitalmars-d-learn
../../JMiscLib/source/jmisc/base.d(176,2): Error: @safe function 
jmisc.base.upDateStatus!string.upDateStatus cannot call @system 
function std.stdio.makeGlobal!"core.stdc.stdio.stdout".makeGlobal
/Library/D/dmd/src/phobos/std/stdio.d(4837,20):
std.stdio.makeGlobal!"core.stdc.stdio.stdout".makeGlobal is 
declared here


I got around it by avoiding 'stdout'.


Re: getopt Basic usage

2020-08-15 Thread Jon Degenhardt via Digitalmars-d-learn

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


Re: getopt Basic usage

2020-08-15 Thread MoonlightSentinel via Digitalmars-d-learn

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.