]> Sergey Matveev's repositories - public-inbox.git/commitdiff
mda+learn: add --help / -h support
authorEric Wong <e@80x24.org>
Tue, 1 Sep 2020 01:15:03 +0000 (01:15 +0000)
committerEric Wong <e@80x24.org>
Wed, 2 Sep 2020 08:53:57 +0000 (08:53 +0000)
"use Getopt::Long" doesn't seem too slow on a hot page cache,
and it's probably used frequently enough to be in cache.

We'll also start reducing the amount of markup in the .pod and
favoring verbatim text in documentation for readability in
source form, since the bold text seems excessive.

Documentation/public-inbox-learn.pod
Documentation/public-inbox-mda.pod
script/public-inbox-learn
script/public-inbox-mda

index cd9bf2782ad74bae8cbb90544aef7618d7408b22..94c96fd5a469f26ec9b4d22f3dff670244b42158 100644 (file)
@@ -4,7 +4,7 @@ public-inbox-learn - spam trainer and remover for public-inbox
 
 =head1 SYNOPSIS
 
 
 =head1 SYNOPSIS
 
-B<public-inbox-learn> <spam|ham|rm> E<lt>MESSAGE
+  public-inbox-learn <spam|ham|rm> </path/to/RFC2822_message
 
 =head1 DESCRIPTION
 
 
 =head1 DESCRIPTION
 
index 99c9053d35949496491c36274dad1d9d3f164c33..a5e353e5aaab53cd6ccdca55f6f4578fab0b0436 100644 (file)
@@ -4,7 +4,7 @@ public-inbox-mda - mail delivery agent for public-inbox
 
 =head1 SYNOPSIS
 
 
 =head1 SYNOPSIS
 
-B<public-inbox-mda> E<lt>MESSAGE
+  public-inbox-mda </path/to/RFC2822_message
 
 =head1 DESCRIPTION
 
 
 =head1 DESCRIPTION
 
index 5cd08d490bf0273bce85ce4d148bdb09035ad288..fb2d86ec141ff11741d6681975d9a0feb7579c44 100755 (executable)
@@ -4,9 +4,22 @@
 #
 # Used for training spam (via SpamAssassin) and removing messages from a
 # public-inbox
 #
 # Used for training spam (via SpamAssassin) and removing messages from a
 # public-inbox
-my $usage = "$0 <spam|ham|rm> </path/to/message";
+my $help = <<EOF;
+usage: public-inbox-learn [OPTIONS] [spam|ham|rm] </path/to/RFC2822_message
+
+required action argument:
+
+   spam  unindex the message and train as spam
+     rm  remove the message without training as spam
+    ham  index the message (based on To:/Cc: headers) and train as ham
+
+options:
+
+  --all  scan all inboxes on `rm'
+
+See public-inbox-learn(1) man page for full documentation.
+EOF
 use strict;
 use strict;
-use warnings;
 use PublicInbox::Config;
 use PublicInbox::InboxWritable;
 use PublicInbox::Eml;
 use PublicInbox::Config;
 use PublicInbox::InboxWritable;
 use PublicInbox::Eml;
@@ -14,11 +27,11 @@ use PublicInbox::Address;
 use PublicInbox::Spamcheck::Spamc;
 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
 my %opt = (all => 0);
 use PublicInbox::Spamcheck::Spamc;
 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
 my %opt = (all => 0);
-GetOptions(\%opt, 'all') or die "bad command-line args\n";
+GetOptions(\%opt, qw(all help|h)) or die $help;
 
 
-my $train = shift or die "usage: $usage\n";
+my $train = shift or die $help;
 if ($train !~ /\A(?:ham|spam|rm)\z/) {
 if ($train !~ /\A(?:ham|spam|rm)\z/) {
-       die "`$train' not recognized.\nusage: $usage\n";
+       die "`$train' not recognized.\n$help";
 }
 die "--all only works with `rm'\n" if $opt{all} && $train ne 'rm';
 
 }
 die "--all only works with `rm'\n" if $opt{all} && $train ne 'rm';
 
index 02ca343163eaf00658b8081f025695f94b6c2e58..3ed5abb6d910dfb76b586a5fbd4dfb4ca9dfa024 100755 (executable)
@@ -3,11 +3,21 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Mail delivery agent for public-inbox, run from your MTA upon mail delivery
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Mail delivery agent for public-inbox, run from your MTA upon mail delivery
+my $help = <<EOF;
+usage: public-inbox-mda [OPTIONS] </path/to/RFC2822_message
+
+options:
+
+  --no-precheck  skip internal checks for spam messages
+
+See public-inbox-mda(1) man page for full documentation.
+EOF
 use strict;
 use strict;
-use warnings;
-my $usage = 'public-inbox-mda [OPTIONS] < rfc2822_message';
-my $precheck = grep(/\A--no-precheck\z/, @ARGV) ? 0 : 1;
-my ($ems, $emm);
+use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
+my ($ems, $emm, $show_help);
+my $precheck = 1;
+GetOptions('precheck!' => \$precheck, 'help|h' => \$show_help) or
+       do { print STDERR $help; exit 1 };
 
 my $do_exit = sub {
        my ($code) = shift;
 
 my $do_exit = sub {
        my ($code) = shift;