groupstats.pl: Add handling of incompatible command line options.
authorThomas Hochstein <thh@inter.net>
Sat, 18 Sep 2010 00:12:58 +0000 (02:12 +0200)
committerThomas Hochstein <thh@inter.net>
Sat, 18 Sep 2010 18:45:33 +0000 (20:45 +0200)
-t/-l/-b are incompatible. Print warning, let -l take precedence
over -t and -b over both.

-q/-d are incompatible with -l and -b. Print warning, ignore
them.

For -l, only -o 'pretty' makes sense. Force that.

Signed-off-by: Thomas Hochstein <thh@inter.net>
groupstats.pl

index bf5bb3d..b1e31e9 100755 (executable)
@@ -40,7 +40,27 @@ my %ConfOverride;
 $ConfOverride{'DBTableGrps'}  = $Options{'g'} if $Options{'g'};\r
 &OverrideConfig(\%Conf,\%ConfOverride);\r
 \r
 $ConfOverride{'DBTableGrps'}  = $Options{'g'} if $Options{'g'};\r
 &OverrideConfig(\%Conf,\%ConfOverride);\r
 \r
-### default output type to 'dump'\r
+### check for incompatible command line options\r
+# you can't mix '-t', '-b' and '-l'\r
+# -b/-l take preference over -t, and -b takes preference over -l\r
+if ($Options{'b'} or $Options{'l'}) {\r
+  if ($Options{'t'}) {\r
+    # drop -t\r
+    warn ("$MySelf: W: You cannot combine thresholds (-t) and top lists (-b) or levels (-l). Threshold '-t $Options{'t'}' was ignored.\n");\r
+    undef($Options{'t'});\r
+  };\r
+  if ($Options{'b'} and $Options{'l'}) {\r
+    # drop -l\r
+    warn ("$MySelf: W: You cannot combine top lists (-b) and levels (-l). Level '-l $Options{'l'}' was ignored.\n");\r
+    undef($Options{'l'});\r
+  };\r
+  # -q/-d don't work with -b or -l\r
+  warn ("$MySelf: W: Sorting by number of postings (-q) ignored due to top list mode (-b) / levels (-l).\n") if $Options{'q'};\r
+  warn ("$MySelf: W: Reverse sorting (-d) ignored due to top list mode (-b) / levels (-l).\n") if $Options{'d'};\r
+};\r
+\r
+### check output type\r
+# default output type to 'dump'\r
 $Options{'o'} = 'dump' if !$Options{'o'};\r
 # fail if more than one newsgroup is combined with 'dumpgroup' type\r
 die ("$MySelf: E: You cannot combine newsgroup lists (-n) with more than one group with '-o dumpgroup'!\n") if ($Options{'o'} eq 'dumpgroup' and defined($Options{'n'}) and $Options{'n'} =~ /:|\*/);\r
 $Options{'o'} = 'dump' if !$Options{'o'};\r
 # fail if more than one newsgroup is combined with 'dumpgroup' type\r
 die ("$MySelf: E: You cannot combine newsgroup lists (-n) with more than one group with '-o dumpgroup'!\n") if ($Options{'o'} eq 'dumpgroup' and defined($Options{'n'}) and $Options{'n'} =~ /:|\*/);\r
@@ -49,14 +69,10 @@ if ($Options{'o'} eq 'dumpgroup' and !defined($Options{'n'})) {
   $Options{'o'} = 'dump';\r
   warn ("$MySelf: W: You must submit exactly one newsgroup ('-n news.group') for '-o dumpgroup'. Output type was set to 'dump'.\n");\r
 };\r
   $Options{'o'} = 'dump';\r
   warn ("$MySelf: W: You must submit exactly one newsgroup ('-n news.group') for '-o dumpgroup'. Output type was set to 'dump'.\n");\r
 };\r
-# you can't mix '-t' and '-b'\r
-if ($Options{'b'}) {\r
-  if ($Options{'t'}) {\r
-    warn ("$MySelf: W: You cannot combine thresholds (-t) and top lists (-b). Threshold '-t $Options{'t'}' was ignored.\n");\r
-    undef($Options{'t'});\r
-  };\r
-  warn ("$MySelf: W: Sorting by number of postings (-q) ignored due to top list mode (-b).\n") if $Options{'q'};\r
-  warn ("$MySelf: W: Reverse sorting (-d) ignored due to top list mode (-b).\n") if $Options{'d'};\r
+# set output type to 'pretty' for -l\r
+if ($Options{'l'}) {\r
+  $Options{'o'} = 'pretty';\r
+  warn ("$MySelf: W: Output type forced to '-o pretty' due to usage of '-l'.\n");\r
 };\r
 \r
 ### get query type, default to 'postings'\r
 };\r
 \r
 ### get query type, default to 'postings'\r
This page took 0.012353 seconds and 4 git commands to generate.