From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 08A3B1FB06 for ; Tue, 19 Jan 2021 09:34:36 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 9/9] lei_overview: start implementing format detection Date: Tue, 19 Jan 2021 09:34:35 +0000 Message-Id: <20210119093435.17955-10-e@80x24.org> In-Reply-To: <20210119093435.17955-1-e@80x24.org> References: <20210119093435.17955-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We'll need it for IMAP support, at least. Proper mbox family detection will be expensive, so deal with it later. --- lib/PublicInbox/LeiOverview.pm | 17 ++++++++++++++++- t/lei.t | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/LeiOverview.pm b/lib/PublicInbox/LeiOverview.pm index a7021b03..dcc3088b 100644 --- a/lib/PublicInbox/LeiOverview.pm +++ b/lib/PublicInbox/LeiOverview.pm @@ -38,6 +38,21 @@ sub ovv_out_lk_cancel ($) { unlink(delete($self->{lock_path})); } +sub detect_fmt ($$) { + my ($lei, $dst) = @_; + if ($dst =~ m!\A([:/]+://)!) { + $lei->fail("$1 support not implemented, yet\n"); + } elsif (!-e $dst) { + 'maildir'; # the default + } elsif (-f _ || -p _) { + $lei->fail("unable to determine mbox family of $dst\n"); + } elsif (-d _) { # TODO: MH? + 'maildir'; + } else { + $lei->fail("unable to determine format of $dst\n"); + } +} + sub new { my ($class, $lei) = @_; my $opt = $lei->{opt}; @@ -54,7 +69,7 @@ sub new { } $fmt //= 'json' if $dst eq '/dev/stdout'; - $fmt //= 'maildir'; + $fmt //= detect_fmt($lei, $dst) or return; if (index($dst, '://') < 0) { # not a URL, so assume path $dst = File::Spec->canonpath($dst); diff --git a/t/lei.t b/t/lei.t index 8bb4e439..64cb5f0e 100644 --- a/t/lei.t +++ b/t/lei.t @@ -232,6 +232,8 @@ my $test_external = sub { my @res = $cat->(); is_deeply(\@res, [], "clobber w/o --augment $sfx"); } + ok(!$lei->('q', '-o', "$home/mbox", 's:nope'), + 'fails if mbox format unspecified'); }; my $test_lei_common = sub {