unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 06/10] mda+learn: add --help / -h support
Date: Tue,  1 Sep 2020 01:15:03 +0000	[thread overview]
Message-ID: <20200901011507.1643-7-e@80x24.org> (raw)
In-Reply-To: <20200901011507.1643-1-e@80x24.org>

"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 |  2 +-
 Documentation/public-inbox-mda.pod   |  2 +-
 script/public-inbox-learn            | 23 ++++++++++++++++++-----
 script/public-inbox-mda              | 18 ++++++++++++++----
 4 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/Documentation/public-inbox-learn.pod b/Documentation/public-inbox-learn.pod
index cd9bf278..94c96fd5 100644
--- a/Documentation/public-inbox-learn.pod
+++ b/Documentation/public-inbox-learn.pod
@@ -4,7 +4,7 @@ public-inbox-learn - spam trainer and remover for public-inbox
 
 =head1 SYNOPSIS
 
-B<public-inbox-learn> <spam|ham|rm> E<lt>MESSAGE
+  public-inbox-learn <spam|ham|rm> </path/to/RFC2822_message
 
 =head1 DESCRIPTION
 
diff --git a/Documentation/public-inbox-mda.pod b/Documentation/public-inbox-mda.pod
index 99c9053d..a5e353e5 100644
--- a/Documentation/public-inbox-mda.pod
+++ b/Documentation/public-inbox-mda.pod
@@ -4,7 +4,7 @@ public-inbox-mda - mail delivery agent for public-inbox
 
 =head1 SYNOPSIS
 
-B<public-inbox-mda> E<lt>MESSAGE
+  public-inbox-mda </path/to/RFC2822_message
 
 =head1 DESCRIPTION
 
diff --git a/script/public-inbox-learn b/script/public-inbox-learn
index 5cd08d49..fb2d86ec 100755
--- a/script/public-inbox-learn
+++ b/script/public-inbox-learn
@@ -4,9 +4,22 @@
 #
 # 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 warnings;
 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);
-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/) {
-	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';
 
diff --git a/script/public-inbox-mda b/script/public-inbox-mda
index 02ca3431..3ed5abb6 100755
--- a/script/public-inbox-mda
+++ b/script/public-inbox-mda
@@ -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
+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 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;

  parent reply	other threads:[~2020-09-01  1:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-01  1:14 [PATCH 00/10] some usability tweaks Eric Wong
2020-09-01  1:14 ` [PATCH 01/10] script/*: set executable bit on -learn and -imapd Eric Wong
2020-09-01  1:14 ` [PATCH 02/10] admin: improve minimum version text Eric Wong
2020-09-01  1:15 ` [PATCH 03/10] edit+purge: support `--help' and `-h' like other commands Eric Wong
2020-09-01  1:15 ` [PATCH 04/10] script/*: fold $usage into $help, support `-h' instead of -? Eric Wong
2020-09-01  1:15 ` [PATCH 05/10] daemon: support --help/-h in -httpd/imapd/nntpd Eric Wong
2020-09-01  1:15 ` Eric Wong [this message]
2020-09-01  1:15 ` [PATCH 07/10] config: use defined-or (//) in a few places Eric Wong
2020-09-01  1:15 ` [PATCH 08/10] watch: add --help/-h support Eric Wong
2020-09-01  1:15 ` [PATCH 09/10] doc: remove B<> (bold) markup from the remaining POD Eric Wong
2020-09-01  1:15 ` [PATCH 10/10] init+convert: create non-existing directory hierarchies Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200901011507.1643-7-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).