line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Goo::CommandLineManager; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# Nigel Hamilton |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2004 |
7
|
|
|
|
|
|
|
# All Rights Reserved |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
10
|
|
|
|
|
|
|
# Filename: Goo::CommandLineManager.pm |
11
|
|
|
|
|
|
|
# Description: Manage command line parameters |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Date Change |
14
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
# 31/10/2004 Auto generated file |
16
|
|
|
|
|
|
|
# 31/10/2004 Needed to reuse handling command lines |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
############################################################################### |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
7292
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
21
|
1
|
|
|
1
|
|
5
|
use Goo::Object; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
5
|
use base qw(Goo::Object); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
553
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
############################################################################### |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
# new - constructor |
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
############################################################################### |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new { |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
1
|
|
my ($class, @parameters) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $this = $class->SUPER::new(); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# the first parameter is the switch |
39
|
0
|
|
|
|
|
|
$this->{switch} = shift(@parameters); |
40
|
0
|
|
|
|
|
|
$this->{switch} =~ s/\-//g; |
41
|
0
|
|
|
|
|
|
$this->{parameters} = \@parameters; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return $this; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
############################################################################### |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# get_last_parameter - pop off the last parameter |
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
############################################################################### |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get_last_parameter { |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return pop @{ $this->{parameters} }; |
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
############################################################################### |
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
# get_parameters - return all the parameters |
66
|
|
|
|
|
|
|
# |
67
|
|
|
|
|
|
|
############################################################################### |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_parameters { |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return @{ $this->{parameters} }; |
|
0
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
############################################################################### |
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
# get_parameter - return an option that corresponds to the right switch |
81
|
|
|
|
|
|
|
# |
82
|
|
|
|
|
|
|
############################################################################### |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub get_parameter { |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
0
|
1
|
|
my ($this, $order) = @_; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$order--; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
#print join("<---array \n", @{ $this->{parameters} }); |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $parameter = @{ $this->{parameters} }[$order]; |
|
0
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
#print "parameter -- $order === --->$parameter<--\n"; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return $parameter; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
############################################################################### |
102
|
|
|
|
|
|
|
# |
103
|
|
|
|
|
|
|
# get_selected_option - return an option that corresponds to the right switch |
104
|
|
|
|
|
|
|
# |
105
|
|
|
|
|
|
|
############################################################################### |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub get_selected_option { |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $switch = $this->{switch}; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
$switch =~ s/\-//g; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
return $this->{switch}; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
############################################################################### |
121
|
|
|
|
|
|
|
# |
122
|
|
|
|
|
|
|
# add_option - add an option to manage on the command line |
123
|
|
|
|
|
|
|
# |
124
|
|
|
|
|
|
|
############################################################################### |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub add_option { |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
0
|
1
|
|
my ($this, $option) = @_; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# add the switch to this object |
131
|
0
|
|
|
|
|
|
$this->{options}->{$option->get_short_label()} = $option; |
132
|
0
|
|
|
|
|
|
$this->{options}->{$option->get_long_label()} = $option; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
############################################################################### |
138
|
|
|
|
|
|
|
# |
139
|
|
|
|
|
|
|
# get_switch - return the value of the switch |
140
|
|
|
|
|
|
|
# |
141
|
|
|
|
|
|
|
############################################################################### |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub get_switch { |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
return $this->{switch}; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
############################################################################### |
153
|
|
|
|
|
|
|
# |
154
|
|
|
|
|
|
|
# show_help - display the help for all the command options |
155
|
|
|
|
|
|
|
# |
156
|
|
|
|
|
|
|
############################################################################### |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub show_help { |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
0
|
1
|
|
my ($this) = @_; |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
foreach my $option (sort keys %{$this->{options}}) { |
|
0
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# print "option ==== $option \n"; |
165
|
0
|
|
|
|
|
|
print "\t\t-$option \t".$this->{options}->{$option}->get_help()."\n"; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
__END__ |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 NAME |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Goo::CommandLineManager - Manage command line parameters |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 SYNOPSIS |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
use Goo::CommandLineManager; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 DESCRIPTION |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Manage command line arguments. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 METHODS |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=over |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item new |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
constructor |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item get_last_parameter |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
pop off the last parameter on the command line |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item get_parameters |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
return all the parameters on the command line |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item get_parameter |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
return the parameter at a given position |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item get_selected_option |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
return the switch that is specified |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item add_option |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
add an option to manage on the command line |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=item get_switch |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
return the value of the switch |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item show_help |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
display the help for all the command options |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=back |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 AUTHOR |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 SEE ALSO |
231
|
|
|
|
|
|
|
|