Refactored readArguments

This commit is contained in:
Emmanuel BENOîT 2022-10-30 10:13:59 +01:00
parent b17a9b8713
commit 98bf21fc88

View file

@ -911,21 +911,22 @@ EOF
sub readArguments sub readArguments
{ {
printBashInit if @ARGV == 1 && $ARGV[0] eq 'init'; return {} unless @ARGV;
my $state = {}; my $state = {};
if (@ARGV == 1 && $ARGV[0] =~ /^\d+$/) { if ($ARGV[0] eq 'init') {
printBashInit; # (will exit)
} elsif ($ARGV[0] =~ /^\d+$/) {
# Backward compatibility # Backward compatibility
$INPUT{rc} = $ARGV[0]; $INPUT{rc} = $ARGV[0];
} else { } else {
if (@ARGV && $ARGV[0] eq 'prevstate') {
shift @ARGV;
$state = eval $ENV{GPROMPT_STATE};
$state = {} if $!;
}
foreach my $arg (@ARGV) { foreach my $arg (@ARGV) {
next unless $arg =~ /^([a-z]+):(.*)$/; if ($arg eq 'prevstate') {
$INPUT{$1} = $2; $state = eval $ENV{GPROMPT_STATE};
$state = {} if $!;
} elsif ($arg =~ /^([a-z]+):(.*)$/) {
$INPUT{$1} = $2;
}
} }
} }