/usr/share/perl5/Rex/Args.pm is in rex 1.4.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | #
# (c) Jan Gehring <jan.gehring@gmail.com>
#
# vim: set ts=2 sw=2 tw=0:
# vim: set expandtab:
package Rex::Args;
use strict;
use warnings;
our $VERSION = '1.4.1'; # VERSION
use vars qw(%rex_opts);
use Rex::Logger;
use Data::Dumper;
our $CLEANUP = 1;
sub args_spec {
return (
C => {},
c => {},
q => {},
Q => {},
F => {},
T => {},
h => {},
v => {},
d => {},
s => {},
m => {},
y => {},
w => {},
S => { type => "string" },
E => { type => "string" },
o => { type => "string" },
f => { type => "string" },
M => { type => "string" },
b => { type => "string" },
e => { type => "string" },
H => { type => "string" },
u => { type => "string" },
p => { type => "string" },
P => { type => "string" },
K => { type => "string" },
G => { type => "string" },
g => { type => "string" },
z => { type => "string" },
O => { type => "string" },
t => { type => "string" },
);
}
sub parse_rex_opts {
my ($class) = @_;
my %args = $class->args_spec;
#### clean up @ARGV
my $runner = 0;
for (@ARGV) {
if ( /^\-[A-Za-z]+/ && length($_) > 2 && $CLEANUP ) {
my @args = map { "-$_" } split( //, substr( $_, 1 ) );
splice( @ARGV, $runner, 1, @args );
}
$runner++;
}
#### parse rex options
my @params = @ARGV;
for my $p (@params) {
# shift off @ARGV
my $shift = shift @ARGV;
if ( length($p) >= 2 && substr( $p, 0, 1 ) eq "-" ) {
my $name_param = substr( $p, 1, 2 );
# found a parameter
if ( exists $args{$name_param} ) {
Rex::Logger::debug("Option found: $name_param ($p)");
my $type = "Single";
if ( exists $args{$name_param}->{type} ) {
$type = $args{$name_param}->{type};
Rex::Logger::debug(" is a $type");
shift @params; # remove the next parameter, because it must be an option
if (
!exists $ARGV[0]
|| ( length( $ARGV[0] ) == 2
&& exists $args{ substr( $ARGV[0], 1, 2 ) }
&& substr( $ARGV[0], 0, 1 ) eq "-" )
)
{
# this is a typed parameter without an option!
Rex::Logger::debug(" but there is no parameter");
Rex::Logger::debug( Dumper( \@params ) );
print("No parameter for $name_param\n");
CORE::exit 1;
}
}
elsif ( exists $args{$name_param}->{func} ) {
Rex::Logger::debug(" is a function - executing now");
$args{$name_param}->{func}->();
}
my $c = "Rex::Args::\u$type";
eval "use $c";
if ($@) {
die("No Argumentclass $type found!");
}
if ( exists $rex_opts{$name_param} && $type eq "Single" ) {
$rex_opts{$name_param}++;
}
else {
# multiple params defined, create an array
if ( exists $rex_opts{$name_param} ) {
if ( !ref $rex_opts{$name_param} ) {
$rex_opts{$name_param} = [ $rex_opts{$name_param} ];
}
push @{ $rex_opts{$name_param} }, $c->get;
}
else {
$rex_opts{$name_param} = $c->get;
}
}
}
else {
Rex::Logger::debug("Option not known: $name_param ($p)");
next;
}
}
else {
# unshift the last parameter
unshift @ARGV, $shift;
last;
}
}
}
sub getopts { return %rex_opts; }
sub is_opt {
my ( $class, $opt ) = @_;
if ( exists $rex_opts{$opt} ) {
return $rex_opts{$opt};
}
}
sub get {
my ($class) = @_;
my $task = Rex::TaskList->create->current_task;
if ($task) {
return $task->get_opts();
}
else {
return _read_old_way();
}
}
sub _read_old_way {
#### parse task options
my %task_opts;
for my $p (@ARGV) {
my ( $key, $val ) = split( /=/, $p, 2 );
$key =~ s/^--//;
if ( defined $val ) { $task_opts{$key} = $val; next; }
$task_opts{$key} = 1;
}
return %task_opts;
}
1;
|