Command-line arguments

superdan super at dan.org
Fri Jul 4 14:58:17 PDT 2008


Lars Ivar Igesund Wrote:

> superdan wrote:
> 
> > Steven Schveighoffer Wrote:
> > 
> >> "superdan" <super at dan.org> wrote in message
> >> news:g4k9tr$34r$1 at digitalmars.com...
> >> > Bill Baxter Wrote:
> >> >
> >> >> Jarrett Billingsley wrote:
> >> >> > "Matt" <no-one at none.nowhere.com> wrote in message
> >> >> > news:g4jqum$269v$1 at digitalmars.com...
> >> >> >> Is there an established library in D for handling command-line
> >> >> >> arguments?
> >> >> >>
> >> >> >> In particular:
> >> >> >> - handling differences between Windows and UNIX shells (i.e.
> >> >> >> wildcard expansion)
> >> >> >> - handling equivalent options such as "-n 10" === --count=10
> >> >> >> - handling combination of multiple flags, e.g. "-lcf" == "-l -f -c"
> >> >> >>
> >> >> >> Thanks
> >> >> >>
> >> >> >> Matt
> >> >> >
> >> >> > I don't believe there is an argument parser in either Phobos 1 or
> >> >> > Phobos 2.
> >> >> > However, there is one in Tango.
> >> >> >
> >> >> >
> >> >>
> >> >> doost has one that works with Phobos.
> >> >> (http://dsource.org/projects/doost)
> >> >>
> >> >> D2/Phobos2 has std.getopt.
> >> >>
> >> >> There's a port std.getopt to D1 in the std2 project:
> >> >> http://www.dsource.org/projects/std2
> >> >>
> >> >> There's a simple port of BSD's getopt in OpenMesh/D:
> >> >>
> http://www.dsource.org/projects/openmeshd/browser/trunk/OpenMeshD/OpenMesh/Tools/Utils/getopt.d
> >> >>
> >> >> --bb
> >> >
> >> > there's one in tango too but it takes 20 lines to do anything, as most
> >> > others do. create a freakin' "command line object". give me a lunch
> >> > break. std.getopt in phobos is best in the world for my money. and
> >> > across all languages for that matter. could never imagine do so much
> >> > shit in one call.
> >> 
> >> There is a new one in Tango as of the latest release called Arguments. 
> >> It's very simple to use:
> >> 
> >> auto args = new Arguments(argv[1..$]);
> >> 
> >> if(args.contains("c")) {} // test for -c
> >> auto filename = args["f"]; // get parameter for -f filename
> >> 
> >> Of course, you can also configure it to be more strict, or to change
> >> every detail, down to the switch character (instead of '-'), but it is
> >> easy to use to get something up and running quickly.
> >> 
> >>
> http://www.dsource.org/projects/tango/docs/current/tango.util.Arguments.html
> > 
> > yarp looked over it. with all due respect, what a piece of crap that is.
> > with that i can't even hope to parse the command line of ssh or rdmd. it
> > loses the original order. it doesn't understand -- which in unix means
> > that options stop here. generally does not obey new unix conventions.
> > defines all sort of useless shit like conflicts that i could care less
> > about. i could write one test expression after parsing thank you very
> > much. but it cannot force the types of its arguments so i must make sure i
> > validate /all/ that shit which is much more voluminous. geez. finally it
> > defines so many types and functions anyone will need a fucking graduate
> > course to use it. no thanks. std.getopt mops the floor with it.
> 
> I suspect you are serious, but it is hard to tell with the above language.
> Even criticism should try to be respectful.

i mean no disrespect. but if something is a piece of crap i will definItely say it's a piece of crap. and yes i am serious when it comes about design. 

> As for Arguments; even though it is present in Tango trunk (and the previous
> release), it was not announced as it is still expected to go through
> further review. It is definately easy to use for the usecases I've thrown
> at it though.

that kinda puts the fault on the review process. after having seen the buick 2008, i'd have my doubts about buick 2009. yet another also, have you ever given std.getopt a test drive? 

> As for preserving and enforcing order, that was one of the design goals for
> this implementation and thus it should be considered a bug if not easily
> done.

put in layman's terms: making it unusable for applications that launch secondary commands was a design goal. and you seem to prefer defending it as it is. you know what. do me a favor. you keep tango arguments. i'll use std.getopt.



More information about the Digitalmars-d mailing list