From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 05/11] lei import: move check_input_format to lei
Date: Wed, 17 Feb 2021 09:07:01 -0100 [thread overview]
Message-ID: <20210217100707.6796-6-e@80x24.org> (raw)
In-Reply-To: <20210217100707.6796-1-e@80x24.org>
We'll be supporting "lei convert" in a future change; so it
makes sense to share a common internal API for common error
messages.
---
lib/PublicInbox/LEI.pm | 14 ++++++++++++++
lib/PublicInbox/LeiImport.pm | 17 ++---------------
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 12deedd8..1fa9f751 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -391,6 +391,20 @@ sub fail ($$;$) {
undef;
}
+sub check_input_format ($;$) {
+ my ($self, $files) = @_;
+ my $fmt = $self->{opt}->{'format'};
+ if (!$fmt) {
+ my $err = $files ? "regular file(s):\n@$files" : '--stdin';
+ return fail($self, "--format unset for $err");
+ }
+ return 1 if $fmt eq 'eml';
+ # XXX: should this handle {gz,bz2,xz}? that's currently in LeiToMail
+ require PublicInbox::MboxReader;
+ PublicInbox::MboxReader->can($fmt) ||
+ fail($self, "--format=$fmt unrecognized");
+}
+
sub out ($;@) {
my $self = shift;
return if print { $self->{1} // return } @_; # likely
diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm
index b25d7e97..32f3a467 100644
--- a/lib/PublicInbox/LeiImport.pm
+++ b/lib/PublicInbox/LeiImport.pm
@@ -29,19 +29,6 @@ sub import_done { # EOF callback for main daemon
$imp->wq_wait_old(\&import_done_wait, $lei);
}
-sub check_fmt ($;$) {
- my ($lei, $f) = @_;
- my $fmt = $lei->{opt}->{'format'};
- if (!$fmt) {
- my $err = $f ? "regular file(s):\n@$f" : '--stdin';
- return $lei->fail("--format unset for $err");
- }
- return 1 if $fmt eq 'eml';
- require PublicInbox::MboxReader;
- PublicInbox::MboxReader->can($fmt) ||
- $lei->fail( "--format=$fmt unrecognized\n");
-}
-
sub do_import {
my ($lei) = @_;
my $ops = {
@@ -82,7 +69,7 @@ sub call { # the main "lei import" method
if ($lei->{opt}->{stdin}) {
@argv and return
$lei->fail("--stdin and locations (@argv) do not mix");
- check_fmt($lei) or return;
+ $lei->check_input_format or return;
$self->{0} = $lei->{0};
} else {
my @f;
@@ -95,7 +82,7 @@ sub call { # the main "lei import" method
$lei->{nrd}->add_url($x);
}
}
- if (@f) { check_fmt($lei, \@f) or return }
+ if (@f) { $lei->check_input_format(\@f) or return }
if ($lei->{nrd} && (my @err = $lei->{nrd}->errors)) {
return $lei->fail(@err);
}
next prev parent reply other threads:[~2021-02-17 10:07 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-17 10:06 [PATCH 00/11] lei IMAP read support Eric Wong
2021-02-17 10:06 ` [PATCH 01/11] lei: bless config Eric Wong
2021-02-17 10:06 ` [PATCH 02/11] watch: move imap_common_init to NetReader Eric Wong
2021-02-17 10:06 ` [PATCH 03/11] watch: connect to NNTP and IMAP in config order Eric Wong
2021-02-17 10:07 ` [PATCH 04/11] lei import: start rearranging code for IMAP support Eric Wong
2021-02-17 10:07 ` Eric Wong [this message]
2021-02-17 10:07 ` [PATCH 06/11] tests: setup_public_inboxes: use IMAP-friendly newsgroups Eric Wong
2021-02-17 10:07 ` [PATCH 07/11] t/lei_to_mail: remove unnecessary arg passing Eric Wong
2021-02-17 10:07 ` [PATCH 08/11] lei convert: mail format conversion sub-command Eric Wong
2021-02-17 10:53 ` Eric Wong
2021-02-18 11:06 ` [PATCHv2 0/4] lei IMAP support take #2 Eric Wong
2021-02-18 11:06 ` [PATCHv2 1/4] lei convert: mail format conversion sub-command Eric Wong
2021-02-18 20:22 ` [PATCHv3 0/4] lei convert IMAP support Eric Wong
2021-02-18 20:22 ` [PATCHv3 1/4] lei convert: mail format conversion sub-command Eric Wong
2021-02-18 20:22 ` [PATCHv3 2/4] lei import: add IMAP and (maildir|mbox*):$PATHNAME support Eric Wong
2021-02-18 20:22 ` [PATCHv3 3/4] lei: consolidate the bulk of the IPC code Eric Wong
2021-02-18 20:22 ` [PATCHv3 4/4] lei: check for IMAP auth errors Eric Wong
2021-02-18 11:06 ` [PATCHv2 2/4] lei import: add IMAP and (maildir|mbox*):$PATHNAME support Eric Wong
2021-02-18 11:06 ` [PATCH (resend) 3/4] lei: consolidate the bulk of the IPC code Eric Wong
2021-02-18 11:06 ` [PATCHv2 4/4] lei: check for IMAP auth errors Eric Wong
2021-02-17 10:07 ` [PATCH 09/11] lei import: add IMAP, (maildir|mbox*):$PATHNAME support Eric Wong
2021-02-17 10:07 ` [PATCH 10/11] lei: consolidate the bulk of the IPC code Eric Wong
2021-02-17 10:07 ` [PATCH 11/11] lei: check for IMAP auth errors 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=20210217100707.6796-6-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).