Juerd wrote:
This probably goes against everything a shell based platform wants, but
would it be possible to give the program a sub-like signature?

I ask this after another painful session of forgetting how things
work, reading Getopt::Long's documentation.

    signature (
        Rule  $pattern,
        bool +$help    :short('h'),
        Int  +$verbose :short('v'),
        Str  [EMAIL PROTECTED] = <->
    );

With GNU-like parsing, this'd make
@*ARGS = < foo|bar --verbose 2 first second third >;
@*ARGS = < foo|bar -vv first second third >;


result in the lexical variables

    $pattern = rx/foo|bar/;
    $help    = false;
    $verbose = 2;
    @files   = < first second third >;

and

    @*ARGS = < foo -- -v --verbose --help forth fifth sixth >;

in

    $pattern = rx/foo/;
    $help    = false;
    $verbose = undef;
    @files   = < -v --verbose --help forth fifth sixth >;

and

    @*ARGS = < pattern >

in
$pattern = rx/pattern/;
$help = false;
$verbose = undef;
@files = ('-');



Probably a macro can handle this, but does (will) Perl parse a signature-like argument list and hand the macro something it can use, or would this require source-filter like trickery?

Would this actually be any better than the interface provided by Getopt::Long? I suspect that it's possible, and I also suspect that Getopt::Long can be written in a much friendlier manner for Perl 6 (not that I have any particular complaints about how it handles things now, but it can certainly be better).


I do feel that command-line option parsing should not be built into the language though - let modules take care of it, then we'll never have to worry about pushing some built-in mechanism aside when we want to do something peculiar.

What you want may well be possible with a module though - or something similar to it.

Reply via email to