aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Shevchenko <andy@smile.org.ua>2012-07-28 18:13:01 +0000
committerAndy Shevchenko <andy@smile.org.ua>2012-07-28 18:13:01 +0000
commitdb0f802fbe685cd1e40f09c3789f5ca241648f62 (patch)
tree1eb4cdec2a10deb178057f411e13f926acde3a30
parentd2dd2085024b382ee60c3fbdff8effcddda1d408 (diff)
downloadrenrot-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
-rwxr-xr-xrenrot47
1 files changed, 13 insertions, 34 deletions
diff --git a/renrot b/renrot
index 3fbbf31..f1dc4ec 100755
--- a/renrot
+++ b/renrot
@@ -298,14 +298,12 @@ sub die_renrot {
298# Returns : nothing 298# Returns : nothing
299# Parameters : many of them, look bellow 299# Parameters : many of them, look bellow
300# Throws : no exceptions 300# Throws : no exceptions
301# Comments : none 301# Comments : none
302# See Also : Getopt::Long GetOptions() 302# See Also : Getopt::Long GetOptions()
303sub getOptions { 303sub getOptions {
304 my $showVersion = 0; # need version
305 my $showHelp = 0; # need help
306 my @tmpTags = (); 304 my @tmpTags = ();
307 305
308 # For 'aggregation' 306 # For 'aggregation'
309 my $s_aggr_opts; 307 my $s_aggr_opts;
310 my %h_aggr_opts; 308 my %h_aggr_opts;
311 309
@@ -323,13 +321,13 @@ sub getOptions {
323 my $ll_opts = { 321 my $ll_opts = {
324 'aggregation' => { 's' => \$s_aggr_opts, 'h' => \%h_aggr_opts }, 322 'aggregation' => { 's' => \$s_aggr_opts, 'h' => \%h_aggr_opts },
325 'contact sheet' => { 's' => \$s_cs_opts, 'h' => \%h_cs_opts }, 323 'contact sheet' => { 's' => \$s_cs_opts, 'h' => \%h_cs_opts },
326 'keywords' => { 's' => \$s_kw_opts, 'h' => \%h_kw_opts }, 324 'keywords' => { 's' => \$s_kw_opts, 'h' => \%h_kw_opts },
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,
332 "aggr-delta=i" => \$h_aggr_opts{'delta'}, 330 "aggr-delta=i" => \$h_aggr_opts{'delta'},
333 "aggr-directory=s" => \$h_aggr_opts{'directory'}, 331 "aggr-directory=s" => \$h_aggr_opts{'directory'},
334 "aggr-mode=s" => \$h_aggr_opts{'mode'}, 332 "aggr-mode=s" => \$h_aggr_opts{'mode'},
335 "aggr-template|a=s" => \$h_aggr_opts{'template'}, 333 "aggr-template|a=s" => \$h_aggr_opts{'template'},
@@ -381,28 +379,28 @@ sub getOptions {
381 "counter-start=i" => \$countStart, 379 "counter-start=i" => \$countStart,
382 "counter-step=i" => \$countStep, 380 "counter-step=i" => \$countStep,
383 "dry-run" => \$dryRun, 381 "dry-run" => \$dryRun,
384 "exclude=s" => \@excludeList, 382 "exclude=s" => \@excludeList,
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,
390 "no-tags|notags" => \$noTags, 388 "no-tags|notags" => \$noTags,
391 "no-renrot|nochg" => \$noRenRoTagMtm, 389 "no-renrot|nochg" => \$noRenRoTagMtm,
392 "only-orientation" => \$orientTag, 390 "only-orientation" => \$orientTag,
393 "quiet|q" => \$quiet, 391 "quiet|q" => \$quiet,
394 "rotate-angle|r=i" => \$rotateAngle, 392 "rotate-angle|r=i" => \$rotateAngle,
395 "rotate-thumb=i" => \$rotateThumbnail, 393 "rotate-thumb=i" => \$rotateThumbnail,
396 "sub-fileset=s" => \$subFileSet, 394 "sub-fileset=s" => \$subFileSet,
397 "tag|t=s" => \@tmpTags, 395 "tag|t=s" => \@tmpTags,
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
405 Image::RenRot::Logging->set(Quiet => $quiet, 403 Image::RenRot::Logging->set(Quiet => $quiet,
406 Verbose => $verbose); 404 Verbose => $verbose);
407 405
408 my $fileCount = scalar(@ARGV); 406 my $fileCount = scalar(@ARGV);
@@ -444,36 +442,21 @@ sub getOptions {
444 ldbg3("--rotate-thumb: $rotateThumbnail") if (defined $rotateThumbnail); 442 ldbg3("--rotate-thumb: $rotateThumbnail") if (defined $rotateThumbnail);
445 ldbg3("--sub-fileset: $subFileSet") if ($subFileSet ne ""); 443 ldbg3("--sub-fileset: $subFileSet") if ($subFileSet ne "");
446 ldbg3("--tag:\n", join("\n", @tmpTags)) if (scalar(@tmpTags) > 0); 444 ldbg3("--tag:\n", join("\n", @tmpTags)) if (scalar(@tmpTags) > 0);
447 ldbg3("--work-directory: $workDir"); 445 ldbg3("--work-directory: $workDir");
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");
462 exit 1; 450 exit 1;
463 } 451 }
464 452
465 if ($extToProcess ne "" and ($fileCount != 0)) { 453 if ($extToProcess ne "" and ($fileCount != 0)) {
466 warnmsg ("Extension of files will be ignored!\n"); 454 warnmsg ("Extension of files will be ignored!\n");
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;
476 update_cfg_value($config_opts->{'general'}{'mtime'}, 0); 459 update_cfg_value($config_opts->{'general'}{'mtime'}, 0);
477 } 460 }
478 461
479 # is there ImageMagick? 462 # is there ImageMagick?
@@ -1572,21 +1555,18 @@ sub rotateThumbnail {
1572 1555
1573######################################################################################## 1556########################################################################################
1574# 1557#
1575# usage() prints the instructions how to use the script 1558# usage() prints the instructions how to use the script
1576# 1559#
1577sub usage { 1560sub 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]
1589 [--name-template TPL] [--comment-file FILE] [--work-directory DIR] 1569 [--name-template TPL] [--comment-file FILE] [--work-directory DIR]
1590 [[--] FILE1 FILE2 ...] 1570 [[--] FILE1 FILE2 ...]
1591 1571
1592Options: 1572Options:
@@ -1615,17 +1595,16 @@ Misc options:
1615i.e. prefixed by 'no'. E.g. '--mtime' sets file mtime value, while '--nomtime' 1595i.e. prefixed by 'no'. E.g. '--mtime' sets file mtime value, while '--nomtime'
1616or '--no-mtime' disables setting it. 1596or '--no-mtime' disables setting it.
1617 1597
1618Consult the documentation for a full list of options. 1598Consult 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
1628######################################################################################## 1607########################################################################################
1629# Usage : $name = template2name(...); 1608# Usage : $name = template2name(...);
1630# Purpose : builds file name according to the template 1609# Purpose : builds file name according to the template
1631# Returns : name as string 1610# Returns : name as string

Return to:

Send suggestions and report system problems to the System administrator.