-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseArgs.pm
More file actions
58 lines (49 loc) · 880 Bytes
/
Copy pathParseArgs.pm
File metadata and controls
58 lines (49 loc) · 880 Bytes
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
use strict;
use warnings;
package ParseArgs;
sub new {
my ($class, $args) = @_;
my $self = {};
bless $self, $class;
$self->{SCHEMA} = $args;
$self->{VALUES} = {};
return $self;
}
sub Parse {
my ($self, @args) = @_;
my $schema = $self->{SCHEMA};
while (@args) {
my $arg = shift @args;
# command-line switch
if ($arg =~ /^-/) {
my $switchname = substr($arg, 1);
if ($schema->{$switchname}) {
if ($schema->{$switchname} eq 'bool'){
# write 1 to parsed values
}
else {
my $switcharg = shift @args;
# Process this arg
}
}
else {
die "invalid switch name $switchname";
}
}
# arg to switch
else {
die "Not a valid switch: $arg";
}
}
#$self->{VALUES} = {@{$self->{ARGS}}};
# foreach my $arg (@args) {
# if ($arg =~ /^-p/) {
# }
# #elsif
# # $self->{ARGS}
# }
}
sub Get {
return 1;
}
1;