Skip to content

Commit

Permalink
We now parse the simplest negate case
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickas committed May 22, 2010
1 parent 1bd48f0 commit 12709a9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions process-cmd-args.p6
Expand Up @@ -3,7 +3,7 @@ use Test;

sub process-cmd-args(@args, %named) {
my (@positional-arguments, %named-arguments);
my ($looking_for , $no_more_switches);
my ($looking_for , $no_more_switches , $negate);
for @args -> $passed_value {
if $no_more_switches {
@positional-arguments.push: $passed_value;
Expand All @@ -13,6 +13,11 @@ sub process-cmd-args(@args, %named) {

} elsif substr($passed_value,0,2) eq '--' {
my $arg = $passed_value.substr(2);
if $arg.match(/^\//) {
$arg .= substr(1) ;
$negate = $arg;
}

if $arg eq '' {
$no_more_switches=True;
} elsif %named{$arg} ~~ Bool {
Expand All @@ -31,7 +36,7 @@ sub process-cmd-args(@args, %named) {
} else {
%named-arguments{$name} = $value;
}
} else {
} elsif !$negate {
$looking_for=$arg;
}

Expand All @@ -40,6 +45,11 @@ sub process-cmd-args(@args, %named) {
}
}

if $negate {
%named-arguments{$negate} = False;
$negate = '';
}

if $looking_for {
%named-arguments{$looking_for} = '';
}
Expand Down

0 comments on commit 12709a9

Please sign in to comment.