Re: What's the proper way to use std.getopt?

2017-12-13 Thread bauss via Digitalmars-d-learn
On Wednesday, 13 December 2017 at 07:37:17 UTC, Jonathan M Davis wrote: On Wednesday, December 13, 2017 06:55:46 bauss via Digitalmars-d-learn wrote: [...] If it works, it's a bug related to code lowering (since scope statements are always lowered to try-catch-finally blocks). You're not

Re: What's the proper way to use std.getopt?

2017-12-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, December 13, 2017 06:55:46 bauss via Digitalmars-d-learn wrote: > On Tuesday, 12 December 2017 at 18:34:26 UTC, Mike Wey wrote: > > On 12-12-17 00:35, Seb wrote: > >> D style would be to use sth. like this (instead of try/catch): > >> > >> ``` > >> scope(failure) { > >> > >>

Re: What's the proper way to use std.getopt?

2017-12-12 Thread bauss via Digitalmars-d-learn
On Tuesday, 12 December 2017 at 18:34:26 UTC, Mike Wey wrote: On 12-12-17 00:35, Seb wrote: D style would be to use sth. like this (instead of try/catch): ``` scope(failure) {   e.msg.writeln;   1.exit; } ``` I might have missed something, but where is `e` defined in this case? I was

Re: What's the proper way to use std.getopt?

2017-12-12 Thread Jordi Gutiérrez Hermoso via Digitalmars-d-learn
On Tuesday, 12 December 2017 at 20:57:28 UTC, Jon Degenhardt wrote: On Monday, 11 December 2017 at 20:58:25 UTC, Jordi Gutiérrez Hermoso wrote: What's the proper style, then? Can someone show me a good example of how to use getopt and the docstring it automatically generates? [snip] See:

Re: What's the proper way to use std.getopt?

2017-12-12 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 11 December 2017 at 20:58:25 UTC, Jordi Gutiérrez Hermoso wrote: What's the proper style, then? Can someone show me a good example of how to use getopt and the docstring it automatically generates? The command line tools I published use the approach described in a number of the

Re: What's the proper way to use std.getopt?

2017-12-12 Thread Mike Wey via Digitalmars-d-learn
On 12-12-17 00:35, Seb wrote: D style would be to use sth. like this (instead of try/catch): ``` scope(failure) {   e.msg.writeln;   1.exit; } ``` I might have missed something, but where is `e` defined in this case? -- Mike Wey

Re: OT (Was: Re: What's the proper way to use std.getopt?)

2017-12-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, December 11, 2017 15:38:44 H. S. Teoh via Digitalmars-d-learn wrote: > On Mon, Dec 11, 2017 at 11:35:53PM +, Seb via Digitalmars-d-learn > wrote: [...] > > > D style would be to use sth. like this (instead of try/catch): > > > > ``` > > scope(failure) { > > > > e.msg.writeln; > >

Re: What's the proper way to use std.getopt?

2017-12-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 11 December 2017 at 20:58:25 UTC, Jordi Gutiérrez Hermoso wrote: I don't quite understand what to do if getopt throws. I would have hoped for something like I might have already said this to you on IRC but the way I'd do it (if you must do this) is: void main(string[] args) {

OT (Was: Re: What's the proper way to use std.getopt?)

2017-12-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 11, 2017 at 11:35:53PM +, Seb via Digitalmars-d-learn wrote: [...] > D style would be to use sth. like this (instead of try/catch): > > ``` > scope(failure) { > e.msg.writeln; > 1.exit; > } > ``` Frankly, much as I love UFCS syntax, I think this is taking it a little too far.

Re: What's the proper way to use std.getopt?

2017-12-11 Thread Jordi Gutiérrez Hermoso via Digitalmars-d-learn
On Monday, 11 December 2017 at 21:24:41 UTC, Mike Wey wrote: try { auto helpInformation = getopt( args, "input|i", "The input", , "output|o", "The output", ); if (helpInformation.helpWanted) {

Re: What's the proper way to use std.getopt?

2017-12-11 Thread Seb via Digitalmars-d-learn
On Monday, 11 December 2017 at 21:24:41 UTC, Mike Wey wrote: On 11-12-17 21:58, Jordi Gutiérrez Hermoso wrote: [...] I would use something like this, print the help information for --help, print an error for invalid arguments: ``` try { auto helpInformation = getopt(

Re: What's the proper way to use std.getopt?

2017-12-11 Thread Mike Wey via Digitalmars-d-learn
On 11-12-17 21:58, Jordi Gutiérrez Hermoso wrote: but instead, the docstring from getopt is only generated if all arguments are valid, i.e. when it's the least needed because the user already knew what to input. What's the proper style, then? Can someone show me a good example of how to use

What's the proper way to use std.getopt?

2017-12-11 Thread Jordi Gutiérrez Hermoso via Digitalmars-d-learn
I don't quite understand what to do if getopt throws. I would have hoped for something like int arg1; string arg2; auto parser = getopt("opt1", "docstring 1", , "opt2", "docstring 2", ); try { auto opts = parser.parse(args) } except(BadArguments) {