aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 {
# 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;
@@ -323,13 +321,13 @@ sub getOptions {
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'},
@@ -381,28 +379,28 @@ sub getOptions {
"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);
@@ -444,36 +442,21 @@ sub getOptions {
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?
@@ -1572,21 +1555,18 @@ sub rotateThumbnail {
########################################################################################
#
# 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:
@@ -1615,17 +1595,16 @@ Misc options:
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

Return to:

Send suggestions and report system problems to the System administrator.