vncserver: CLI optional option arg support (-select-de=[DE])

This commit is contained in:
Dmitry Maksyoma 2021-08-20 22:33:34 +12:00
parent 36ffbe1572
commit 551f292144

View File

@ -27,6 +27,13 @@
use v5.10;
use Time::HiRes qw (sleep);
use Switch;
use constant {
NO_ARG_VALUE => 0,
REQUIRED_ARG_VALUE => 1,
OPTIONAL_ARG_VALUE => 2
};
&CheckWeCanRunInThisEnvironment();
@ -419,16 +426,33 @@ sub ParseOptionsAndRemoveMatchesFromARGV
foreach $opt (@opts) {
if ($arg eq $opt) {
push(@optArgs, $arg);
if ($valFollows{$opt}) {
if (@ARGV == 0) {
&Usage();
switch($valFollows{$opt}) {
case NO_ARG_VALUE {
$opt{$opt} = 1;
next arg;
}
case REQUIRED_ARG_VALUE {
if (@ARGV == 0) {
&Usage();
}
$opt{$opt} = shift(@ARGV);
push(@optArgs, $opt{$opt});
next arg;
}
case OPTIONAL_ARG_VALUE {
if (scalar @ARGV == 0 || $ARGV[0] =~ /^-/) {
$opt{$opt} = 1;
next arg;
}
$opt{$opt} = shift(@ARGV);
push(@optArgs, $opt{$opt});
next arg;
}
$opt{$opt} = shift(@ARGV);
push(@optArgs, $opt{$opt});
} else {
$opt{$opt} = 1;
}
next arg;
}
}
push(@newargs,$arg);