develooper Front page | perl.perl6.language | Postings from February 2005

CLI signature?

Thread Next
From:
Juerd
Date:
February 5, 2005 07:58
Subject:
CLI signature?
Message ID:
20050205155755.GJ14718@c4.convolution.nl
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  *@files = <->
    );

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?
    

Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About