Mailing List Archive

svn commit: rev 20515 - in incubator/spamassassin/trunk: . spamd
Author: mss
Date: Thu May 27 12:12:53 2004
New Revision: 20515

Modified:
incubator/spamassassin/trunk/spamassassin.raw
incubator/spamassassin/trunk/spamd/spamd.raw
Log:
Some more help/usage/versioning cleanup.


Modified: incubator/spamassassin/trunk/spamassassin.raw
==============================================================================
--- incubator/spamassassin/trunk/spamassassin.raw (original)
+++ incubator/spamassassin/trunk/spamassassin.raw Thu May 27 12:12:53 2004
@@ -77,6 +77,49 @@
use Mail::SpamAssassin;
use Mail::SpamAssassin::ArchiveIterator;

+
+my %resphash = (
+ EX_OK => 0, # no problems
+ EX_USAGE => 64, # command line usage error
+ EX_DATAERR => 65, # data format error
+ EX_NOINPUT => 66, # cannot open input
+ EX_NOUSER => 67, # addressee unknown
+ EX_NOHOST => 68, # host name unknown
+ EX_UNAVAILABLE => 69, # service unavailable
+ EX_SOFTWARE => 70, # internal software error
+ EX_OSERR => 71, # system error (e.g., can't fork)
+ EX_OSFILE => 72, # critical OS file missing
+ EX_CANTCREAT => 73, # can't create (user) output file
+ EX_IOERR => 74, # input/output error
+ EX_TEMPFAIL => 75, # temp failure; user is invited to retry
+ EX_PROTOCOL => 76, # remote error in protocol
+ EX_NOPERM => 77, # permission denied
+ EX_CONFIG => 78, # configuration error
+);
+
+
+sub print_version {
+ print "SpamAssassin version " . Mail::SpamAssassin::Version() . "\n"
+ . " running on Perl version " . join(".", map { $_ * 1 } ($] =~ /(\d)\.(\d{3})(\d{3})/ )) . "\n";
+}
+
+sub print_usage_and_exit {
+ my ( $message, $respnam ) = @_;
+ $respnam ||= 'EX_USAGE';
+
+ if ($respnam eq 'EX_OK' ) {
+ print_version();
+ print("\n");
+ }
+ pod2usage(
+ -verbose => 0,
+ -message => $message,
+ -exitval => $resphash{$respnam},
+ );
+}
+
+
+
sub usage {
my ( $verbose, $message ) = @_;
my $ver = Mail::SpamAssassin::Version();
@@ -126,23 +169,17 @@
'help|h|?' => \$opt{'help'},
'mbox' => sub { $opt{'format'} = 'mbox'; },
'mbx' => sub { $opt{'format'} = 'mbx'; },
+) or print_usage_and_exit();

- # NOTE: ignored for backwards compatibility. will be stripped
- # in a future release.
- 'whitelist-factory|M=s' => sub { warn "The -M option has been removed.\n" },
- 'auto-whitelist|a' => sub { warn "The -a option has been removed.\n" },
- 'warning-from|w=s' => sub { warn "The -w option has been removed.\n" },
- 'log-to-mbox|l=s' => sub { warn "The -l option has been removed.\n" },
- )
- or usage( 0, "Unknown option!" );
if ( defined $opt{'help'} ) {
- usage( 0, "For more information read the spamassassin man page" );
+ print_usage_and_exit("For more information read the spamassassin man page.\n", 'EX_OK');
}
if ( defined $opt{'version'} ) {
- print "SpamAssassin version " . Mail::SpamAssassin::Version() . "\n";
- exit 0;
+ print_version();
+ exit($resphash{'EX_OK'});
}

+
# create the tester factory
my $spamtest = new Mail::SpamAssassin(
{
@@ -166,7 +203,7 @@
$Mail::SpamAssassin::DEBUG->{$1} = $2 + 0;
}
if ( $levels !~ /^\s*$/ ) {
- usage( 0, "bad areas in --debug option ($levels)!" );
+ print_usage_and_exit("bad areas in --debug option ($levels)!");
}
}


Modified: incubator/spamassassin/trunk/spamd/spamd.raw
==============================================================================
--- incubator/spamassassin/trunk/spamd/spamd.raw (original)
+++ incubator/spamassassin/trunk/spamd/spamd.raw Thu May 27 12:12:53 2004
@@ -81,6 +81,28 @@
EX_CONFIG => 78, # configuration error
);

+
+sub print_version {
+ print "SpamAssassin Server version " . Mail::SpamAssassin::Version() . "\n"
+ . " running on Perl version " . join(".", map { $_ * 1 } ($] =~ /(\d)\.(\d{3})(\d{3})/ )) . "\n";
+}
+
+sub print_usage_and_exit {
+ my ( $message, $respnam ) = (@_);
+ $respnam ||= 'EX_USAGE';
+
+ if ($respnam eq 'EX_OK' ) {
+ print_version();
+ print("\n");
+ }
+ pod2usage(
+ -verbose => 0,
+ -message => $message,
+ -exitval => $resphash{$respnam},
+ );
+}
+
+
# defaults
my %opt = (
'user-config' => 1,
@@ -122,7 +144,6 @@
'c' => \$opt{'create-prefs'},
'daemonize!' => \$opt{'daemonize'},
'd' => \$opt{'daemonize'},
- 'help|h' => \$opt{'help'},
'listen-ip|ip-address|i=s' => \$opt{'listen-ip'},
'max-children|m=i' => \$opt{'max-children'},
'max-conn-per-child=i' => \$opt{'max-conn-per-child'},
@@ -145,8 +166,6 @@
'user-config' => \$opt{'user-config'},
'nouser-config|x' => sub { $opt{'user-config'} = 0 },
'allowed-ips|A=s' => \@{ $opt{'allowed-ip'} },
- 'debug!' => \$opt{'debug'},
- 'D' => \$opt{'debug'},
'local!' => \$opt{'local'},
'L' => \$opt{'local'},
'paranoid!' => \$opt{'paranoid'},
@@ -157,23 +176,19 @@
'ssl' => \$opt{'ssl'},
'server-key=s' => \$opt{'server-key'},
'server-cert=s' => \$opt{'server-cert'},
-
- # will be stripped in future release
- 'add-from!' => sub { warn "The --add-from option has been removed\n" },
- 'F=i' => sub { warn "The -F option has been removed\n" },
- 'S' => sub { warn "The -S option has been removed\n" },
- 'stop-at-threshold!' =>
- sub { warn "The --stop-at-threshold option has been removed\n" },
- 'auto-whitelist|whitelist|a' =>
- sub { warn "The -a option has been removed\n" },
- )
- or pod2usage( -exitval => $resphash{'EX_USAGE'}, -verbose => 0 );
-
-$opt{'help'} and pod2usage(
- -exitval => $resphash{'EX_USAGE'},
- -verbose => 0,
- -message => 'For more details, use "man spamd"'
-);
+ 'debug!' => \$opt{'debug'},
+ 'D' => \$opt{'debug'},
+ 'version|V' => \$opt{'version'},
+ 'help|h' => \$opt{'help'},
+) or print_usage_and_exit();
+
+if ($opt{'help'}) {
+ print_usage_and_exit(qq{For more details, use "man spamd".\n}, 'EX_OK');
+}
+if ($opt{'version'}) {
+ print_version();
+ exit($resphash{'EX_OK'});
+}

# bug 2228: make the values of (almost) all parameters which accept file paths
# absolute, so they are still valid after daemonize()
@@ -205,12 +220,7 @@
or defined $opt{'port'} )
)
{
- pod2usage(
- -exitval => $resphash{'EX_USAGE'},
- -verbose => 0,
- -message =>
-"ERROR: --socketpath mutually exclusive with --allowed-ip/--ssl/--port params"
- );
+ print_usage_and_exit("ERROR: --socketpath mutually exclusive with --allowed-ip/--ssl/--port params");
}

if (
@@ -220,12 +230,7 @@
or $opt{'socketmode'})
)
{
- pod2usage(
- -exitval => $resphash{'EX_USAGE'},
- -verbose => 0,
- -message =>
-"ERROR: --socketowner/group/mode requires --socketpath param"
- );
+ print_usage_and_exit("ERROR: --socketowner/group/mode requires --socketpath param");
}

# These can be changed on command line with -A flag