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 | |
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
-rwxr-xr-x | renrot | 47 |
1 files changed, 13 insertions, 34 deletions
@@ -292,50 +292,48 @@ sub die_renrot { ### GETTINNG OPTIONS FROM CLI ### ######################################################################################## ######################################################################################## # Usage : getOptions(...) # Purpose : parses command line arguments # Returns : nothing # Parameters : many of them, look bellow # Throws : no exceptions # Comments : none # See Also : Getopt::Long GetOptions() sub getOptions { - my $showVersion = 0; # need version - my $showHelp = 0; # need help my @tmpTags = (); # For 'aggregation' my $s_aggr_opts; my %h_aggr_opts; # For 'contact sheet' my $s_cs_opts; my %h_cs_opts; # For 'general' my %h_g_opts; # For 'keywords' my $s_kw_opts; my %h_kw_opts; my $ll_opts = { 'aggregation' => { 's' => \$s_aggr_opts, 'h' => \%h_aggr_opts }, 'contact sheet' => { 's' => \$s_cs_opts, 'h' => \%h_cs_opts }, 'keywords' => { 's' => \$s_kw_opts, 'h' => \%h_kw_opts }, }; - my $getOptions = GetOptions ( + GetOptions ( # AGGREGATION "aggr-opts=s" => \$s_aggr_opts, "aggr-delta=i" => \$h_aggr_opts{'delta'}, "aggr-directory=s" => \$h_aggr_opts{'directory'}, "aggr-mode=s" => \$h_aggr_opts{'mode'}, "aggr-template|a=s" => \$h_aggr_opts{'template'}, "aggr-virtual!" => \$h_aggr_opts{'virtual'}, # CONTACT SHEET "contact-sheet-opts|cs-opts=s" => \$s_cs_opts, "contact-sheet-bg|cs-bg=s" => \$h_cs_opts{'background'}, "contact-sheet-bd|cs-bd=s" => \$h_cs_opts{'bordercolor'}, @@ -375,40 +373,40 @@ sub getOptions { # OTHERS "backup!" => \$backup, "comment-file=s" => \$comfile, "config-file|c=s" => \$configFile, "counter-fixed-field!" => \$countFF, "counter-start=i" => \$countStart, "counter-step=i" => \$countStep, "dry-run" => \$dryRun, "exclude=s" => \@excludeList, "extension|e=s" => \$extToProcess, "generate-thumb|g" => \$gen_thm, - "help|?" => \$showHelp, + "help|?" => sub { usage(0, 2) }, "no-rename|norename" => \$noRename, "no-rotate|norotate" => \$noRotation, "no-tags|notags" => \$noTags, "no-renrot|nochg" => \$noRenRoTagMtm, "only-orientation" => \$orientTag, "quiet|q" => \$quiet, "rotate-angle|r=i" => \$rotateAngle, "rotate-thumb=i" => \$rotateThumbnail, "sub-fileset=s" => \$subFileSet, "tag|t=s" => \@tmpTags, "user-comment=s" => \$userComment, "v+" => \$verbose, - "version" => \$showVersion, + "version" => sub { usage(0, 0) }, "work-directory|d=s" => \$workDir, - ); + ) or usage(1, 1); # Set the verbosity first Image::RenRot::Logging->set(Quiet => $quiet, Verbose => $verbose); my $fileCount = scalar(@ARGV); foreach my $key (keys %$ll_opts) { # Parse long list option if (defined ${$ll_opts->{$key}{'s'}}) { update_cfg_value($config_opts->{$key}{'enabled'}, 1); parse2hash(${$ll_opts->{$key}{'s'}}, $config_opts, $key); @@ -438,48 +436,33 @@ sub getOptions { ldbg3("--no-rename: ", bool2str($noRename), " --no-rotate: ", bool2str($noRotation), " --no-tags: ", bool2str($noTags), " --no-renrot: ", bool2str($noRenRoTagMtm)); ldbg3("--only-orientation: ", bool2str($orientTag)); ldbg3("--rotate-angle: $rotateAngle") if (defined $rotateAngle); ldbg3("--rotate-thumb: $rotateThumbnail") if (defined $rotateThumbnail); ldbg3("--sub-fileset: $subFileSet") if ($subFileSet ne ""); ldbg3("--tag:\n", join("\n", @tmpTags)) if (scalar(@tmpTags) > 0); ldbg3("--work-directory: $workDir"); ldbg3("ARGV:\n", join("\n", @ARGV)) if ($fileCount > 0); - if ($showHelp != 0) { - usage(); - exit 0; - } - - if ($showVersion != 0) { - infomsg ("RenRot version $VERSION (r$REVISION)\n"); - exit 0; - } - if ($extToProcess eq "" and ($fileCount == 0) and $subFileSet eq "") { fatalmsg ("Extension of files is required!\n"); exit 1; } if ($extToProcess ne "" and ($fileCount != 0)) { warnmsg ("Extension of files will be ignored!\n"); } - if ($getOptions == 0) { - usage(); - exit 1; - } - if ($noRenRoTagMtm != 0) { $noRename = $noRotation = $noTags = 1; update_cfg_value($config_opts->{'general'}{'mtime'}, 0); } # is there ImageMagick? if ($isThereIM == 1) { dbgmsg (1, "We have Image::Magick package and could proceed with --contact-sheet related functionality.\n"); } elsif (get_cfg_value($co_cs, 'enabled') == 1) { errmsg ("To use --contact-sheet related functionality you need Image::Magick package!\n", "Contact Sheet generation disabled.\n"); } elsif ($gen_thm != 0) { @@ -1566,33 +1549,30 @@ sub rotateThumbnail { dbgmsg (3, "$cmd\n"); # write the just rotated thumbnail back to file thumbWriter($file, Image::RenRot::FileUtil->piper($origThumb, $cmd)); } } ######################################################################################## # # usage() prints the instructions how to use the script # sub usage { - # catch warnings if we have problems running perldoc - my $evalWarning; - local $SIG{'__WARN__'} = sub { $evalWarning = $_[0] }; - my $dummy = \*SAVEERR; # avoid "used only once" warning - unless ($^O eq 'os2') { - open SAVEERR, ">&STDERR"; - open STDERR, '>/dev/null'; - } - if (system('perldoc', $0)) { + my $exitcode = shift; + my $verbose = shift; + + if ($verbose == 0) { + infomsg ("RenRot version $VERSION (r$REVISION)\n"); + } elsif ($verbose == 1) { infomsg ( "Usage: renrot <--extension EXTENSION> [--quiet] [--no-rotate] [--no-rename] [--name-template TPL] [--comment-file FILE] [--work-directory DIR] [[--] FILE1 FILE2 ...] Options: -c, --config-file <FILE> configuration file to use -d, --work-directory <DIR> set working directory -e, --extension <EXTENSION> extension of files to process: JPG, jpeg, ... Renaming options: -n, --name-template <TPL> filename template (see manual for details) @@ -1609,29 +1589,28 @@ Misc options: --use-ipc (*) rotate thumbnail via pipe, rather than via file -v increment debugging level by 1 -h, --help display this help and exit --version output version and exit (*) The options marked with this sign do not take arguments and can be negated, i.e. prefixed by 'no'. E.g. '--mtime' sets file mtime value, while '--nomtime' or '--no-mtime' disables setting it. Consult the documentation for a full list of options. "); + } elsif ($verbose == 2) { + pod2usage(-verbose => 2); } - unless ($^O eq 'os2') { - close STDERR; - open STDERR, '>&SAVEERR'; - } + exit $exitcode; } ######################################################################################## # Usage : $name = template2name(...); # Purpose : builds file name according to the template # Returns : name as string # Parameters : $exifToolObj [ref] - # : $infoObj [ref] - # : $template [str] - the template to be used # : $fileNo [num] - counter for %c # : $fileName [str] - file name for %n and %e # : $counterSize [num] - the size of the counter for format (like "01", "0012") |