Command-line arguments

superdan super at dan.org
Sat Jul 5 11:50:47 PDT 2008


Lars Ivar Igesund Wrote:

> superdan wrote:
> 
> > Lars Ivar Igesund Wrote:
> > 
> >> superdan wrote:
> >> 
> >> > Lars Ivar Igesund Wrote:
> >> > 
> >> >> 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.
> >> 
> >> No.
> > 
> > then parse this using tango arguments please:
> > 
> > ssh -v ls -la
> > 
> > thanks.
> 
> Everything until ls is easy (including the hostname which is required by
> ssh), but it appears to ignore the -la part which I have noted to the
> implementors. I believe I did say that although the requirments document (I
> probably wrongly said design document) mandates that this should be
> possible, the implementation and design is not fully reviewed yet and may
> have bugs.
> 
> The order is completely preserved and enforcable though.

rats! i forgot the hostname indeed. ok let me fix:

ssh -v host ls -la

my question is, assuming all bugs are fixed, how does the code for parsing this look like with tango arguments?

to make things more interesting, let's use this example:

ssh -v host -v ls -la

everything before and after host but before command is an option for ssh. everything after command is passed to the command. 

could you show how this is coded (assuming bugs are fixed) in both tango arguments apis. thanks.

here's my std.getopt implementation for the example. let's see how others fare.

void main(string[] args) 
{
    auto offset = find!("a.length && a[0] == '-'")(args) - begin(args);
    enforce(offset != args.length, "Hostname not specified");
    auto host = args[offset];
    args = args[0 .. offset] ~ args[offset + 1 .. $];
    uint verbosityLevel;
    ............
    getopt(args,
        std.getopt.config.stopOnFirstNonOption,
        "v+", &verbosityLevel,
        ......... more stuff ......);
    if (args.length) 
    {
        ........... start shell session on host .........
    }
    else
    {
        ........... run command on host ..........
    }
}




More information about the Digitalmars-d mailing list