Merge lp:~percona-toolkit-dev/percona-toolkit/opt-parsing-exit-status-bug-1039074 into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 425
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/opt-parsing-exit-status-bug-1039074
Merge into: lp:percona-toolkit/2.1
Diff against target: 815 lines (+124/-70)
31 files modified
bin/pt-archiver (+2/-2)
bin/pt-config-diff (+2/-2)
bin/pt-deadlock-logger (+2/-2)
bin/pt-diskstats (+2/-2)
bin/pt-duplicate-key-checker (+2/-2)
bin/pt-fifo-split (+2/-2)
bin/pt-find (+2/-2)
bin/pt-fingerprint (+2/-2)
bin/pt-fk-error-logger (+2/-2)
bin/pt-heartbeat (+2/-2)
bin/pt-index-usage (+2/-2)
bin/pt-kill (+2/-2)
bin/pt-log-player (+2/-2)
bin/pt-online-schema-change (+2/-2)
bin/pt-query-advisor (+2/-2)
bin/pt-query-digest (+2/-2)
bin/pt-show-grants (+2/-2)
bin/pt-slave-delay (+2/-2)
bin/pt-slave-find (+2/-2)
bin/pt-slave-restart (+2/-2)
bin/pt-table-checksum (+2/-2)
bin/pt-table-sync (+2/-2)
bin/pt-table-usage (+10/-7)
bin/pt-tcp-model (+2/-2)
bin/pt-trend (+2/-2)
bin/pt-upgrade (+2/-2)
bin/pt-variable-advisor (+2/-2)
bin/pt-visual-explain (+24/-8)
lib/OptionParser.pm (+2/-2)
t/lib/OptionParser.t (+22/-0)
t/pt-deadlock-logger/option_sanity.t (+14/-1)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/opt-parsing-exit-status-bug-1039074
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+130872@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-archiver'
2--- bin/pt-archiver 2012-10-20 23:59:28 +0000
3+++ bin/pt-archiver 2012-10-22 18:26:45 +0000
4@@ -524,7 +524,7 @@
5 else {
6 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
7 }
8- exit 0;
9+ exit 1;
10 }
11
12 if ( @ARGV && $self->{strict} ) {
13@@ -779,7 +779,7 @@
14 }
15 elsif ( scalar @{$self->{errors}} ) {
16 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
17- exit 0 unless $return;
18+ exit 1 unless $return;
19 }
20
21 return;
22
23=== modified file 'bin/pt-config-diff'
24--- bin/pt-config-diff 2012-10-20 23:59:28 +0000
25+++ bin/pt-config-diff 2012-10-22 18:26:45 +0000
26@@ -523,7 +523,7 @@
27 else {
28 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
29 }
30- exit 0;
31+ exit 1;
32 }
33
34 if ( @ARGV && $self->{strict} ) {
35@@ -778,7 +778,7 @@
36 }
37 elsif ( scalar @{$self->{errors}} ) {
38 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
39- exit 0 unless $return;
40+ exit 1 unless $return;
41 }
42
43 return;
44
45=== modified file 'bin/pt-deadlock-logger'
46--- bin/pt-deadlock-logger 2012-10-20 23:59:28 +0000
47+++ bin/pt-deadlock-logger 2012-10-22 18:26:45 +0000
48@@ -521,7 +521,7 @@
49 else {
50 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
51 }
52- exit 0;
53+ exit 1;
54 }
55
56 if ( @ARGV && $self->{strict} ) {
57@@ -776,7 +776,7 @@
58 }
59 elsif ( scalar @{$self->{errors}} ) {
60 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
61- exit 0 unless $return;
62+ exit 1 unless $return;
63 }
64
65 return;
66
67=== modified file 'bin/pt-diskstats'
68--- bin/pt-diskstats 2012-10-20 23:59:28 +0000
69+++ bin/pt-diskstats 2012-10-22 18:26:45 +0000
70@@ -523,7 +523,7 @@
71 else {
72 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
73 }
74- exit 0;
75+ exit 1;
76 }
77
78 if ( @ARGV && $self->{strict} ) {
79@@ -778,7 +778,7 @@
80 }
81 elsif ( scalar @{$self->{errors}} ) {
82 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
83- exit 0 unless $return;
84+ exit 1 unless $return;
85 }
86
87 return;
88
89=== modified file 'bin/pt-duplicate-key-checker'
90--- bin/pt-duplicate-key-checker 2012-10-20 23:59:28 +0000
91+++ bin/pt-duplicate-key-checker 2012-10-22 18:26:45 +0000
92@@ -1425,7 +1425,7 @@
93 else {
94 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
95 }
96- exit 0;
97+ exit 1;
98 }
99
100 if ( @ARGV && $self->{strict} ) {
101@@ -1680,7 +1680,7 @@
102 }
103 elsif ( scalar @{$self->{errors}} ) {
104 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
105- exit 0 unless $return;
106+ exit 1 unless $return;
107 }
108
109 return;
110
111=== modified file 'bin/pt-fifo-split'
112--- bin/pt-fifo-split 2012-10-08 21:02:17 +0000
113+++ bin/pt-fifo-split 2012-10-22 18:26:45 +0000
114@@ -495,7 +495,7 @@
115 else {
116 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
117 }
118- exit 0;
119+ exit 1;
120 }
121
122 if ( @ARGV && $self->{strict} ) {
123@@ -750,7 +750,7 @@
124 }
125 elsif ( scalar @{$self->{errors}} ) {
126 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
127- exit 0 unless $return;
128+ exit 1 unless $return;
129 }
130
131 return;
132
133=== modified file 'bin/pt-find'
134--- bin/pt-find 2012-10-20 23:59:28 +0000
135+++ bin/pt-find 2012-10-22 18:26:45 +0000
136@@ -893,7 +893,7 @@
137 else {
138 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
139 }
140- exit 0;
141+ exit 1;
142 }
143
144 if ( @ARGV && $self->{strict} ) {
145@@ -1148,7 +1148,7 @@
146 }
147 elsif ( scalar @{$self->{errors}} ) {
148 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
149- exit 0 unless $return;
150+ exit 1 unless $return;
151 }
152
153 return;
154
155=== modified file 'bin/pt-fingerprint'
156--- bin/pt-fingerprint 2012-10-08 21:02:17 +0000
157+++ bin/pt-fingerprint 2012-10-22 18:26:45 +0000
158@@ -496,7 +496,7 @@
159 else {
160 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
161 }
162- exit 0;
163+ exit 1;
164 }
165
166 if ( @ARGV && $self->{strict} ) {
167@@ -751,7 +751,7 @@
168 }
169 elsif ( scalar @{$self->{errors}} ) {
170 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
171- exit 0 unless $return;
172+ exit 1 unless $return;
173 }
174
175 return;
176
177=== modified file 'bin/pt-fk-error-logger'
178--- bin/pt-fk-error-logger 2012-10-20 23:59:28 +0000
179+++ bin/pt-fk-error-logger 2012-10-22 18:26:45 +0000
180@@ -520,7 +520,7 @@
181 else {
182 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
183 }
184- exit 0;
185+ exit 1;
186 }
187
188 if ( @ARGV && $self->{strict} ) {
189@@ -775,7 +775,7 @@
190 }
191 elsif ( scalar @{$self->{errors}} ) {
192 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
193- exit 0 unless $return;
194+ exit 1 unless $return;
195 }
196
197 return;
198
199=== modified file 'bin/pt-heartbeat'
200--- bin/pt-heartbeat 2012-10-20 23:59:28 +0000
201+++ bin/pt-heartbeat 2012-10-22 18:26:45 +0000
202@@ -1256,7 +1256,7 @@
203 else {
204 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
205 }
206- exit 0;
207+ exit 1;
208 }
209
210 if ( @ARGV && $self->{strict} ) {
211@@ -1511,7 +1511,7 @@
212 }
213 elsif ( scalar @{$self->{errors}} ) {
214 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
215- exit 0 unless $return;
216+ exit 1 unless $return;
217 }
218
219 return;
220
221=== modified file 'bin/pt-index-usage'
222--- bin/pt-index-usage 2012-10-20 23:59:28 +0000
223+++ bin/pt-index-usage 2012-10-22 18:26:45 +0000
224@@ -1023,7 +1023,7 @@
225 else {
226 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
227 }
228- exit 0;
229+ exit 1;
230 }
231
232 if ( @ARGV && $self->{strict} ) {
233@@ -1278,7 +1278,7 @@
234 }
235 elsif ( scalar @{$self->{errors}} ) {
236 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
237- exit 0 unless $return;
238+ exit 1 unless $return;
239 }
240
241 return;
242
243=== modified file 'bin/pt-kill'
244--- bin/pt-kill 2012-10-20 23:59:28 +0000
245+++ bin/pt-kill 2012-10-22 18:26:45 +0000
246@@ -528,7 +528,7 @@
247 else {
248 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
249 }
250- exit 0;
251+ exit 1;
252 }
253
254 if ( @ARGV && $self->{strict} ) {
255@@ -783,7 +783,7 @@
256 }
257 elsif ( scalar @{$self->{errors}} ) {
258 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
259- exit 0 unless $return;
260+ exit 1 unless $return;
261 }
262
263 return;
264
265=== modified file 'bin/pt-log-player'
266--- bin/pt-log-player 2012-10-08 21:02:17 +0000
267+++ bin/pt-log-player 2012-10-22 18:26:45 +0000
268@@ -500,7 +500,7 @@
269 else {
270 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
271 }
272- exit 0;
273+ exit 1;
274 }
275
276 if ( @ARGV && $self->{strict} ) {
277@@ -755,7 +755,7 @@
278 }
279 elsif ( scalar @{$self->{errors}} ) {
280 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
281- exit 0 unless $return;
282+ exit 1 unless $return;
283 }
284
285 return;
286
287=== modified file 'bin/pt-online-schema-change'
288--- bin/pt-online-schema-change 2012-10-22 17:34:52 +0000
289+++ bin/pt-online-schema-change 2012-10-22 18:26:45 +0000
290@@ -534,7 +534,7 @@
291 else {
292 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
293 }
294- exit 0;
295+ exit 1;
296 }
297
298 if ( @ARGV && $self->{strict} ) {
299@@ -789,7 +789,7 @@
300 }
301 elsif ( scalar @{$self->{errors}} ) {
302 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
303- exit 0 unless $return;
304+ exit 1 unless $return;
305 }
306
307 return;
308
309=== modified file 'bin/pt-query-advisor'
310--- bin/pt-query-advisor 2012-10-20 23:59:28 +0000
311+++ bin/pt-query-advisor 2012-10-22 18:26:45 +0000
312@@ -904,7 +904,7 @@
313 else {
314 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
315 }
316- exit 0;
317+ exit 1;
318 }
319
320 if ( @ARGV && $self->{strict} ) {
321@@ -1159,7 +1159,7 @@
322 }
323 elsif ( scalar @{$self->{errors}} ) {
324 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
325- exit 0 unless $return;
326+ exit 1 unless $return;
327 }
328
329 return;
330
331=== modified file 'bin/pt-query-digest'
332--- bin/pt-query-digest 2012-10-20 23:59:28 +0000
333+++ bin/pt-query-digest 2012-10-22 18:26:45 +0000
334@@ -1042,7 +1042,7 @@
335 else {
336 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
337 }
338- exit 0;
339+ exit 1;
340 }
341
342 if ( @ARGV && $self->{strict} ) {
343@@ -1297,7 +1297,7 @@
344 }
345 elsif ( scalar @{$self->{errors}} ) {
346 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
347- exit 0 unless $return;
348+ exit 1 unless $return;
349 }
350
351 return;
352
353=== modified file 'bin/pt-show-grants'
354--- bin/pt-show-grants 2012-10-08 21:02:17 +0000
355+++ bin/pt-show-grants 2012-10-22 18:26:45 +0000
356@@ -496,7 +496,7 @@
357 else {
358 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
359 }
360- exit 0;
361+ exit 1;
362 }
363
364 if ( @ARGV && $self->{strict} ) {
365@@ -751,7 +751,7 @@
366 }
367 elsif ( scalar @{$self->{errors}} ) {
368 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
369- exit 0 unless $return;
370+ exit 1 unless $return;
371 }
372
373 return;
374
375=== modified file 'bin/pt-slave-delay'
376--- bin/pt-slave-delay 2012-10-20 23:59:28 +0000
377+++ bin/pt-slave-delay 2012-10-22 18:26:45 +0000
378@@ -521,7 +521,7 @@
379 else {
380 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
381 }
382- exit 0;
383+ exit 1;
384 }
385
386 if ( @ARGV && $self->{strict} ) {
387@@ -776,7 +776,7 @@
388 }
389 elsif ( scalar @{$self->{errors}} ) {
390 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
391- exit 0 unless $return;
392+ exit 1 unless $return;
393 }
394
395 return;
396
397=== modified file 'bin/pt-slave-find'
398--- bin/pt-slave-find 2012-10-08 21:02:17 +0000
399+++ bin/pt-slave-find 2012-10-22 18:26:45 +0000
400@@ -500,7 +500,7 @@
401 else {
402 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
403 }
404- exit 0;
405+ exit 1;
406 }
407
408 if ( @ARGV && $self->{strict} ) {
409@@ -755,7 +755,7 @@
410 }
411 elsif ( scalar @{$self->{errors}} ) {
412 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
413- exit 0 unless $return;
414+ exit 1 unless $return;
415 }
416
417 return;
418
419=== modified file 'bin/pt-slave-restart'
420--- bin/pt-slave-restart 2012-10-20 23:59:28 +0000
421+++ bin/pt-slave-restart 2012-10-22 18:26:45 +0000
422@@ -642,7 +642,7 @@
423 else {
424 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
425 }
426- exit 0;
427+ exit 1;
428 }
429
430 if ( @ARGV && $self->{strict} ) {
431@@ -897,7 +897,7 @@
432 }
433 elsif ( scalar @{$self->{errors}} ) {
434 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
435- exit 0 unless $return;
436+ exit 1 unless $return;
437 }
438
439 return;
440
441=== modified file 'bin/pt-table-checksum'
442--- bin/pt-table-checksum 2012-10-20 23:59:28 +0000
443+++ bin/pt-table-checksum 2012-10-22 18:26:45 +0000
444@@ -2190,7 +2190,7 @@
445 else {
446 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
447 }
448- exit 0;
449+ exit 1;
450 }
451
452 if ( @ARGV && $self->{strict} ) {
453@@ -2445,7 +2445,7 @@
454 }
455 elsif ( scalar @{$self->{errors}} ) {
456 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
457- exit 0 unless $return;
458+ exit 1 unless $return;
459 }
460
461 return;
462
463=== modified file 'bin/pt-table-sync'
464--- bin/pt-table-sync 2012-10-20 23:59:28 +0000
465+++ bin/pt-table-sync 2012-10-22 18:26:45 +0000
466@@ -537,7 +537,7 @@
467 else {
468 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
469 }
470- exit 0;
471+ exit 1;
472 }
473
474 if ( @ARGV && $self->{strict} ) {
475@@ -792,7 +792,7 @@
476 }
477 elsif ( scalar @{$self->{errors}} ) {
478 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
479- exit 0 unless $return;
480+ exit 1 unless $return;
481 }
482
483 return;
484
485=== modified file 'bin/pt-table-usage'
486--- bin/pt-table-usage 2012-10-19 23:14:07 +0000
487+++ bin/pt-table-usage 2012-10-22 18:26:45 +0000
488@@ -445,6 +445,7 @@
489 'default' => 1,
490 'cumulative' => 1,
491 'negatable' => 1,
492+ 'value_is_optional' => 1,
493 );
494
495 my $self = {
496@@ -686,9 +687,10 @@
497 $opt->{short} = undef;
498 }
499
500- $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
501- $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
502- $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
503+ $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
504+ $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
505+ $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;
506+ $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
507
508 $opt->{group} ||= 'default';
509 $self->{groups}->{ $opt->{group} }->{$long} = 1;
510@@ -824,7 +826,7 @@
511 if ( $opt->{is_cumulative} ) {
512 $opt->{value}++;
513 }
514- else {
515+ elsif ( !($opt->{optional_value} && !$val) ) {
516 $opt->{value} = $val;
517 }
518 $opt->{got} = 1;
519@@ -881,7 +883,7 @@
520 else {
521 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
522 }
523- exit 0;
524+ exit 1;
525 }
526
527 if ( @ARGV && $self->{strict} ) {
528@@ -1136,7 +1138,7 @@
529 }
530 elsif ( scalar @{$self->{errors}} ) {
531 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
532- exit 0 unless $return;
533+ exit 1 unless $return;
534 }
535
536 return;
537@@ -1365,11 +1367,12 @@
538 sub _parse_attribs {
539 my ( $self, $option, $attribs ) = @_;
540 my $types = $self->{types};
541+ my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
542 return $option
543 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
544 . ($attribs->{'negatable'} ? '!' : '' )
545 . ($attribs->{'cumulative'} ? '+' : '' )
546- . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
547+ . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );
548 }
549
550 sub _parse_synopsis {
551
552=== modified file 'bin/pt-tcp-model'
553--- bin/pt-tcp-model 2012-10-08 21:02:17 +0000
554+++ bin/pt-tcp-model 2012-10-22 18:26:45 +0000
555@@ -499,7 +499,7 @@
556 else {
557 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
558 }
559- exit 0;
560+ exit 1;
561 }
562
563 if ( @ARGV && $self->{strict} ) {
564@@ -754,7 +754,7 @@
565 }
566 elsif ( scalar @{$self->{errors}} ) {
567 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
568- exit 0 unless $return;
569+ exit 1 unless $return;
570 }
571
572 return;
573
574=== modified file 'bin/pt-trend'
575--- bin/pt-trend 2012-10-12 17:09:46 +0000
576+++ bin/pt-trend 2012-10-22 18:26:45 +0000
577@@ -499,7 +499,7 @@
578 else {
579 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
580 }
581- exit 0;
582+ exit 1;
583 }
584
585 if ( @ARGV && $self->{strict} ) {
586@@ -754,7 +754,7 @@
587 }
588 elsif ( scalar @{$self->{errors}} ) {
589 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
590- exit 0 unless $return;
591+ exit 1 unless $return;
592 }
593
594 return;
595
596=== modified file 'bin/pt-upgrade'
597--- bin/pt-upgrade 2012-10-20 23:59:28 +0000
598+++ bin/pt-upgrade 2012-10-22 18:26:45 +0000
599@@ -1444,7 +1444,7 @@
600 else {
601 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
602 }
603- exit 0;
604+ exit 1;
605 }
606
607 if ( @ARGV && $self->{strict} ) {
608@@ -1699,7 +1699,7 @@
609 }
610 elsif ( scalar @{$self->{errors}} ) {
611 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
612- exit 0 unless $return;
613+ exit 1 unless $return;
614 }
615
616 return;
617
618=== modified file 'bin/pt-variable-advisor'
619--- bin/pt-variable-advisor 2012-10-20 23:59:28 +0000
620+++ bin/pt-variable-advisor 2012-10-22 18:26:45 +0000
621@@ -525,7 +525,7 @@
622 else {
623 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
624 }
625- exit 0;
626+ exit 1;
627 }
628
629 if ( @ARGV && $self->{strict} ) {
630@@ -780,7 +780,7 @@
631 }
632 elsif ( scalar @{$self->{errors}} ) {
633 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
634- exit 0 unless $return;
635+ exit 1 unless $return;
636 }
637
638 return;
639
640=== modified file 'bin/pt-visual-explain'
641--- bin/pt-visual-explain 2012-10-12 17:09:46 +0000
642+++ bin/pt-visual-explain 2012-10-22 18:26:45 +0000
643@@ -6,7 +6,20 @@
644
645 use strict;
646 use warnings FATAL => 'all';
647-use constant PTDEBUG => $ENV{PTDEBUG} || 0;
648+
649+# This tool is "fat-packed": most of its dependent modules are embedded
650+# in this file. Setting %INC to this file for each module makes Perl aware
651+# of this so it will not try to load the module from @INC. See the tool's
652+# documentation for a full list of dependencies.
653+BEGIN {
654+ $INC{$_} = __FILE__ for map { (my $pkg = "$_.pm") =~ s!::!/!g; $pkg } (qw(
655+ ExplainParser
656+ ExplainTree
657+ OptionParser
658+ DSNParser
659+ Daemon
660+ ));
661+}
662
663 # ###########################################################################
664 # Converts text (e.g. saved output) to a "recordset" -- an array of hashrefs
665@@ -719,6 +732,7 @@
666 'default' => 1,
667 'cumulative' => 1,
668 'negatable' => 1,
669+ 'value_is_optional' => 1,
670 );
671
672 my $self = {
673@@ -960,9 +974,10 @@
674 $opt->{short} = undef;
675 }
676
677- $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
678- $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
679- $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
680+ $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
681+ $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
682+ $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;
683+ $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
684
685 $opt->{group} ||= 'default';
686 $self->{groups}->{ $opt->{group} }->{$long} = 1;
687@@ -1098,7 +1113,7 @@
688 if ( $opt->{is_cumulative} ) {
689 $opt->{value}++;
690 }
691- else {
692+ elsif ( !($opt->{optional_value} && !$val) ) {
693 $opt->{value} = $val;
694 }
695 $opt->{got} = 1;
696@@ -1155,7 +1170,7 @@
697 else {
698 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
699 }
700- exit 0;
701+ exit 1;
702 }
703
704 if ( @ARGV && $self->{strict} ) {
705@@ -1410,7 +1425,7 @@
706 }
707 elsif ( scalar @{$self->{errors}} ) {
708 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
709- exit 0 unless $return;
710+ exit 1 unless $return;
711 }
712
713 return;
714@@ -1639,11 +1654,12 @@
715 sub _parse_attribs {
716 my ( $self, $option, $attribs ) = @_;
717 my $types = $self->{types};
718+ my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
719 return $option
720 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
721 . ($attribs->{'negatable'} ? '!' : '' )
722 . ($attribs->{'cumulative'} ? '+' : '' )
723- . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
724+ . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );
725 }
726
727 sub _parse_synopsis {
728
729=== modified file 'lib/OptionParser.pm'
730--- lib/OptionParser.pm 2012-09-13 13:39:04 +0000
731+++ lib/OptionParser.pm 2012-10-22 18:26:45 +0000
732@@ -669,7 +669,7 @@
733 else {
734 print "Error parsing version. See the VERSION section of the tool's documentation.\n";
735 }
736- exit 0;
737+ exit 1;
738 }
739
740 if ( @ARGV && $self->{strict} ) {
741@@ -988,7 +988,7 @@
742 }
743 elsif ( scalar @{$self->{errors}} ) {
744 print $self->print_errors() or die "Cannot print errors: $OS_ERROR";
745- exit 0 unless $return;
746+ exit 1 unless $return;
747 }
748
749 return;
750
751=== modified file 't/lib/OptionParser.t'
752--- t/lib/OptionParser.t 2012-09-13 13:39:04 +0000
753+++ t/lib/OptionParser.t 2012-10-22 18:26:45 +0000
754@@ -2058,6 +2058,28 @@
755 );
756
757 # #############################################################################
758+# Bug 1039074: Tools exit 0 on error parsing options, should exit non-zero
759+# #############################################################################
760+
761+# pt-archiver requires at least one of --dest, --file or --purge, as well as
762+# --where and --source. So specifying no options should cause errors.
763+@ARGV = qw();
764+$o = new OptionParser(file => "$trunk/bin/pt-archiver");
765+$o->get_specs();
766+$o->get_opts();
767+
768+my $exit_status = 0;
769+($output, $exit_status) = full_output(
770+ sub { $o->usage_or_errors("$trunk/bin/pt-archiver"); },
771+);
772+
773+is(
774+ $exit_status,
775+ 1,
776+ "Non-zero exit status on error parsing options (bug 1039074)"
777+);
778+
779+# #############################################################################
780 # Done.
781 # #############################################################################
782 {
783
784=== modified file 't/pt-deadlock-logger/option_sanity.t'
785--- t/pt-deadlock-logger/option_sanity.t 2011-07-12 22:56:55 +0000
786+++ t/pt-deadlock-logger/option_sanity.t 2012-10-22 18:26:45 +0000
787@@ -9,7 +9,7 @@
788 use strict;
789 use warnings FATAL => 'all';
790 use English qw(-no_match_vars);
791-use Test::More tests => 3;
792+use Test::More tests => 4;
793
794 use PerconaTest;
795
796@@ -40,6 +40,19 @@
797 );
798
799 # #############################################################################
800+# Bug 1039074: Tools exit 0 on error parsing options, should exit non-zero
801+# #############################################################################
802+
803+system("$trunk/bin/pt-deadlock-logger --i-am-the-error >/dev/null 2>&1");
804+my $exit_status = $CHILD_ERROR >> 8;
805+
806+is(
807+ $exit_status,
808+ 1,
809+ "Non-zero exit on option error (bug 1039074)"
810+);
811+
812+# #############################################################################
813 # Done.
814 # #############################################################################
815 exit;

Subscribers

People subscribed via source and target branches