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