diff options
author | Andy Shevchenko <andy@smile.org.ua> | 2012-07-28 18:13:01 +0000 |
---|---|---|
committer | Andy Shevchenko <andy@smile.org.ua> | 2012-07-28 18:13:01 +0000 |
commit | db0f802fbe685cd1e40f09c3789f5ca241648f62 (patch) | |
tree | 1eb4cdec2a10deb178057f411e13f926acde3a30 /renrot | |
parent | d2dd2085024b382ee60c3fbdff8effcddda1d408 (diff) | |
download | renrot-db0f802fbe685cd1e40f09c3789f5ca241648f62.tar.gz renrot-db0f802fbe685cd1e40f09c3789f5ca241648f62.tar.bz2 |
doc: update usage() to cover few more cases
Now usage() will print either version or short list of options, or full
documentation via pod2usage.
Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
git-svn-id: file:///svnroot/renrot/trunk@614 fe2816f4-e837-0410-b10a-f608c9d244a1
Diffstat (limited to 'renrot')
-rwxr-xr-x | renrot | 47 |
1 files changed, 13 insertions, 34 deletions
@@ -302,6 +302,4 @@ sub die_renrot { | |||
302 | # See Also : Getopt::Long GetOptions() | 302 | # See Also : Getopt::Long GetOptions() |
303 | sub getOptions { | 303 | sub getOptions { |
304 | my $showVersion = 0; # need version | ||
305 | my $showHelp = 0; # need help | ||
306 | my @tmpTags = (); | 304 | my @tmpTags = (); |
307 | 305 | ||
@@ -327,5 +325,5 @@ sub getOptions { | |||
327 | }; | 325 | }; |
328 | 326 | ||
329 | my $getOptions = GetOptions ( | 327 | GetOptions ( |
330 | # AGGREGATION | 328 | # AGGREGATION |
331 | "aggr-opts=s" => \$s_aggr_opts, | 329 | "aggr-opts=s" => \$s_aggr_opts, |
@@ -385,5 +383,5 @@ sub getOptions { | |||
385 | "extension|e=s" => \$extToProcess, | 383 | "extension|e=s" => \$extToProcess, |
386 | "generate-thumb|g" => \$gen_thm, | 384 | "generate-thumb|g" => \$gen_thm, |
387 | "help|?" => \$showHelp, | 385 | "help|?" => sub { usage(0, 2) }, |
388 | "no-rename|norename" => \$noRename, | 386 | "no-rename|norename" => \$noRename, |
389 | "no-rotate|norotate" => \$noRotation, | 387 | "no-rotate|norotate" => \$noRotation, |
@@ -398,7 +396,7 @@ sub getOptions { | |||
398 | "user-comment=s" => \$userComment, | 396 | "user-comment=s" => \$userComment, |
399 | "v+" => \$verbose, | 397 | "v+" => \$verbose, |
400 | "version" => \$showVersion, | 398 | "version" => sub { usage(0, 0) }, |
401 | "work-directory|d=s" => \$workDir, | 399 | "work-directory|d=s" => \$workDir, |
402 | ); | 400 | ) or usage(1, 1); |
403 | 401 | ||
404 | # Set the verbosity first | 402 | # Set the verbosity first |
@@ -448,14 +446,4 @@ sub getOptions { | |||
448 | ldbg3("ARGV:\n", join("\n", @ARGV)) if ($fileCount > 0); | 446 | ldbg3("ARGV:\n", join("\n", @ARGV)) if ($fileCount > 0); |
449 | 447 | ||
450 | if ($showHelp != 0) { | ||
451 | usage(); | ||
452 | exit 0; | ||
453 | } | ||
454 | |||
455 | if ($showVersion != 0) { | ||
456 | infomsg ("RenRot version $VERSION (r$REVISION)\n"); | ||
457 | exit 0; | ||
458 | } | ||
459 | |||
460 | if ($extToProcess eq "" and ($fileCount == 0) and $subFileSet eq "") { | 448 | if ($extToProcess eq "" and ($fileCount == 0) and $subFileSet eq "") { |
461 | fatalmsg ("Extension of files is required!\n"); | 449 | fatalmsg ("Extension of files is required!\n"); |
@@ -467,9 +455,4 @@ sub getOptions { | |||
467 | } | 455 | } |
468 | 456 | ||
469 | if ($getOptions == 0) { | ||
470 | usage(); | ||
471 | exit 1; | ||
472 | } | ||
473 | |||
474 | if ($noRenRoTagMtm != 0) { | 457 | if ($noRenRoTagMtm != 0) { |
475 | $noRename = $noRotation = $noTags = 1; | 458 | $noRename = $noRotation = $noTags = 1; |
@@ -1576,13 +1559,10 @@ sub rotateThumbnail { | |||
1576 | # | 1559 | # |
1577 | sub usage { | 1560 | sub usage { |
1578 | # catch warnings if we have problems running perldoc | 1561 | my $exitcode = shift; |
1579 | my $evalWarning; | 1562 | my $verbose = shift; |
1580 | local $SIG{'__WARN__'} = sub { $evalWarning = $_[0] }; | 1563 | |
1581 | my $dummy = \*SAVEERR; # avoid "used only once" warning | 1564 | if ($verbose == 0) { |
1582 | unless ($^O eq 'os2') { | 1565 | infomsg ("RenRot version $VERSION (r$REVISION)\n"); |
1583 | open SAVEERR, ">&STDERR"; | 1566 | } elsif ($verbose == 1) { |
1584 | open STDERR, '>/dev/null'; | ||
1585 | } | ||
1586 | if (system('perldoc', $0)) { | ||
1587 | infomsg ( | 1567 | infomsg ( |
1588 | "Usage: renrot <--extension EXTENSION> [--quiet] [--no-rotate] [--no-rename] | 1568 | "Usage: renrot <--extension EXTENSION> [--quiet] [--no-rotate] [--no-rename] |
@@ -1619,9 +1599,8 @@ Consult the documentation for a full list of options. | |||
1619 | 1599 | ||
1620 | "); | 1600 | "); |
1601 | } elsif ($verbose == 2) { | ||
1602 | pod2usage(-verbose => 2); | ||
1621 | } | 1603 | } |
1622 | unless ($^O eq 'os2') { | 1604 | exit $exitcode; |
1623 | close STDERR; | ||
1624 | open STDERR, '>&SAVEERR'; | ||
1625 | } | ||
1626 | } | 1605 | } |
1627 | 1606 | ||