From 9c7b213f58fe533953953e90b5bc77087ca4d45d Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 13 Jul 2018 18:52:08 +0100 Subject: we can now parse boolean options --- lib/Getopt/Dakkar/Option.pm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'lib/Getopt/Dakkar/Option.pm') diff --git a/lib/Getopt/Dakkar/Option.pm b/lib/Getopt/Dakkar/Option.pm index 0dfd882..077f7be 100644 --- a/lib/Getopt/Dakkar/Option.pm +++ b/lib/Getopt/Dakkar/Option.pm @@ -1,5 +1,6 @@ package Getopt::Dakkar::Option; use Getopt::Dakkar::Style qw(class); +use Getopt::Dakkar::OptionValue; with 'Getopt::Dakkar::Role::Piece'; # VERSION # ABSTRACT: an option @@ -23,16 +24,26 @@ sub match($self,$arg) { sub parse($self,$args,$stash) { my $my_option = shift $args->@*; + # this will need to be extracted and made dependent on the type! + + my %arguments; # first, get arguments if needed for my $parameter ($self->parameters->@*) { my $argument = $parameter->parse($args,$stash); - # aaarg, + $arguments{$argument->name} = $argument; } # then, remove the option and put the bundle back, if needed - if ($my_option =~ /^-[^-]+/) { # we're in a bundle + if ($my_option =~ /^-[^-]{2,}/) { # we're in a bundle $my_option =~ s{^-.}{-}; unshift $args->@*, $my_option; } - return $the_option_argument; + + my $value = Getopt::Dakkar::OptionValue->new({ + name => $self->name, + # needs a way to negate a boolean! + value => %arguments ? \%arguments : 1, + }); + + return $value; } -- cgit v1.2.3