On Fri, May 15, 2020 at 07:57:47AM +0300, Peter Pentchev wrote:
> On Thu, May 14, 2020 at 06:46:17PM -0700, ToddAndMargo via perl6-users wrote:
> > On 2020-05-11 21:19, Peter Pentchev wrote:
> > > #!/usr/bin/env raku
> > >
> > > use v6.d;
> > >
> > > use Getopt::Long;
> > >
> > > sub cmd_install($cmd, Array[Str] :$enablerepo = [], Bool :$y = False,
> > > *@rest --> int)
> > > {
> > > say 'install';
> > > dd $cmd;
> > > dd @rest;
> > > dd $enablerepo;
> > > dd $y;
> > > return 0;
> > > }
> > >
> > > sub cmd_list($cmd, Array[Str] :$enablerepo = [], *@rest --> int)
> > > {
> > > say 'list';
> > > dd $cmd;
> > > dd @rest;
> > > dd $enablerepo;
> > > return 42;
> > > }
> > >
> > > my %HANDLERS = (
> > > install => &cmd_install,
> > >
> > > # "list" doesn't care about the "-y" parameter, so skip it
> > > list => -> $cmd, :$enablerepo = [], :$y = False, *@rest --> int {
> > > cmd_list $cmd, :$enablerepo, |@rest
> > > },
> > > );
> > >
> > > sub note-fatal(Str:D $msg)
> > > {
> > > $msg.note;
> > > exit 1;
> > > }
> > >
> > > {
> > > my $opts = get-options(
> > > "enablerepo=s@",
> > > "y",
> > > );
> > > CATCH { when Getopt::Long::Exception { .message.note; exit 1 } };
> > > dd $opts;
> > >
> > > note-fatal 'No command specified' unless $opts.elems;
> > > my $cmd = $opts[0];
> > > my $handler = %HANDLERS{$cmd};
> > > note-fatal "Unknown command '$cmd'" unless $handler;
> > > exit $handler(|$opts);
> > > }
> >
> >
> > How do I use it? Where are the options declared?
>
> What does https://modules.raku.org/dist/Getopt::Long:cpan:LEONT (the
> link you posted at the top of your first message) say in the "SYNOPSIS"
> section?Oooookay, so that might have been something of a trick question, since it seems that synopsis does not have an example of the Capture-style invocation[1] :) You may have to actually read the "Simple options" section below to find out what get-options() returns :) G'luck, Peter [1] https://github.com/Leont/getopt-long6/pull/5 -- Peter Pentchev [email protected] [email protected] [email protected] PGP key: http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13
signature.asc
Description: PGP signature
