Re: Help Required on Getopt

2017-09-01 Thread Jon Degenhardt via Digitalmars-d-learn

On Friday, 1 September 2017 at 19:04:39 UTC, Daniel Kozak wrote:
I have same issue.  How this help you?  Catching exception does 
not help. How do I catch exception and still print help message?


Your are correct, sorry about that. What my response showed is 
how to avoid printing the full stack trace and instead printing a 
more nicely formatted error message. And separately, how to print 
formatted help. But, you are correct in that you can't directly 
print the formatted help text from the catch block as shown.


In particular, the GetoptResult returned by getopt is not 
available. I don't have any examples that try to work around 
this. Presumably one could call getopt again to get the options 
list, then generate the formatted help. It'd be an annoyance, 
though perhaps judicious use of AliasSeq might make the code 
structure reasonable.


--Jon


Re: Help Required on Getopt

2017-09-01 Thread Daniel Kozak via Digitalmars-d-learn
I have same issue.  How this help you?  Catching exception does not help.
How do I catch exception and still print help message?

Dne 1. 9. 2017 8:10 odpoledne napsal uživatel "Vino.B via
Digitalmars-d-learn" :

On Friday, 1 September 2017 at 17:23:01 UTC, Jon Degenhardt wrote:

> On Friday, 1 September 2017 at 13:13:39 UTC, Vino.B wrote:
>
>> Hi All,
>>
>>   When i run the below program without any arguments "D1.d -r" it is
>> throwing error, but i need it to show the help menu
>>
>> [snip...]
>>
>
> Hi Vino,
>
> To get good error message behavior you need to put the construct in a
> try-catch block. Then you can choose how to respond. An example here:
> https://github.com/eBay/tsv-utils-dlang/blob/master/tsv-appe
> nd/src/tsv-append.d#L138-L194. This code prints outs the error message
> from the exception. In your case: "Missing value for argument -r.". But,
> you could also print out the help text as well. There is an example of that
> as well in the above code block, look for the 'if (r.helpWanted)' test.
>
> --Jon
>

Hi,

  Thank you very much, that helped me to resolve the issue.


Re: Help Required on Getopt

2017-09-01 Thread Vino.B via Digitalmars-d-learn

On Friday, 1 September 2017 at 17:23:01 UTC, Jon Degenhardt wrote:

On Friday, 1 September 2017 at 13:13:39 UTC, Vino.B wrote:

Hi All,

  When i run the below program without any arguments "D1.d -r" 
it is throwing error, but i need it to show the help menu


[snip...]


Hi Vino,

To get good error message behavior you need to put the 
construct in a try-catch block. Then you can choose how to 
respond. An example here: 
https://github.com/eBay/tsv-utils-dlang/blob/master/tsv-append/src/tsv-append.d#L138-L194. This code prints outs the error message from the exception. In your case: "Missing value for argument -r.". But, you could also print out the help text as well. There is an example of that as well in the above code block, look for the 'if (r.helpWanted)' test.


--Jon


Hi,

  Thank you very much, that helped me to resolve the issue.


Re: Help Required on Getopt

2017-09-01 Thread Jon Degenhardt via Digitalmars-d-learn

On Friday, 1 September 2017 at 13:13:39 UTC, Vino.B wrote:

Hi All,

  When i run the below program without any arguments "D1.d -r" 
it is throwing error, but i need it to show the help menu


[snip...]


Hi Vino,

To get good error message behavior you need to put the construct 
in a try-catch block. Then you can choose how to respond. An 
example here: 
https://github.com/eBay/tsv-utils-dlang/blob/master/tsv-append/src/tsv-append.d#L138-L194. This code prints outs the error message from the exception. In your case: "Missing value for argument -r.". But, you could also print out the help text as well. There is an example of that as well in the above code block, look for the 'if (r.helpWanted)' test.


--Jon