From cf7c27cadd9ce7800beedc72513cf12fda77420f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 25 Feb 2021 10:11:04 +0000 Subject: lei import: use --in-format/-F for consistency Since we recommend $IN_FORMAT:$LOCATION, this is hopefully not intrusive (not that this is released software, yet). This is to be consistent with "lei convert" usage. We'll keep "-f" only for output formats, since that is used for "lei q" and "lei convert" for outputs --- lib/PublicInbox/LEI.pm | 8 ++++---- lib/PublicInbox/LeiConvert.pm | 4 ++-- lib/PublicInbox/LeiImport.pm | 7 +++---- 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'lib/PublicInbox') diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 50665b3e..8eb96e78 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -172,7 +172,7 @@ our %CMD = ( # sorted in order of importance/use: 'import' => [ 'LOCATION...|--stdin', 'one-time import/update from URL or filesystem', qw(stdin| offset=i recursive|r exclude=s include|I=s - format|f=s kw|keywords|flags! C=s@), + in-format|F=s kw|keywords|flags! C=s@), ], 'convert' => [ 'LOCATION...|--stdin', 'one-time conversion from URL or filesystem to another format', @@ -399,9 +399,9 @@ sub fail ($$;$) { undef; } -sub check_input_format ($;$$) { - my ($self, $files, $opt_key) = @_; - $opt_key //= 'format'; +sub check_input_format ($;$) { + my ($self, $files) = @_; + my $opt_key = 'in-format'; my $fmt = $self->{opt}->{$opt_key}; if (!$fmt) { my $err = $files ? "regular file(s):\n@$files" : '--stdin'; diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm index 32aa2edb..45d42c9c 100644 --- a/lib/PublicInbox/LeiConvert.pm +++ b/lib/PublicInbox/LeiConvert.pm @@ -91,7 +91,7 @@ sub call { # the main "lei convert" method $opt->{augment} = 1 unless $ovv->{dst} eq '/dev/stdout'; if ($opt->{stdin}) { @inputs and return $lei->fail("--stdin and @inputs do not mix"); - $lei->check_input_format(undef, 'in-format') or return; + $lei->check_input_format(undef) or return; $self->{0} = $lei->{0}; } # e.g. Maildir:/home/user/Mail/ or imaps://example.com/INBOX @@ -123,7 +123,7 @@ sub call { # the main "lei convert" method elsif (-d _) { push @d, $input } else { return $lei->fail("Unable to handle $input") } } - if (@f) { $lei->check_input_format(\@f, 'in-format') or return } + if (@f) { $lei->check_input_format(\@f) or return } if (@d) { # TODO: check for MH vs Maildir, here require PublicInbox::MdirReader; } diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm index 13e817d0..7f247b64 100644 --- a/lib/PublicInbox/LeiImport.pm +++ b/lib/PublicInbox/LeiImport.pm @@ -68,8 +68,7 @@ sub call { # the main "lei import" method $self->{0} = $lei->{0}; } - # TODO: do we need --format for non-stdin? - my $fmt = $lei->{opt}->{'format'}; + my $fmt = $lei->{opt}->{'in-format'}; # e.g. Maildir:/home/user/Mail/ or imaps://example.com/INBOX for my $input (@inputs) { my $input_path = $input; @@ -159,7 +158,7 @@ sub _import_net { # imap_each, nntp_each cb sub import_path_url { my ($self, $input) = @_; my $lei = $self->{lei}; - my $ifmt = lc($lei->{opt}->{'format'} // ''); + my $ifmt = lc($lei->{opt}->{'in-format'} // ''); # TODO auto-detect? if ($input =~ m!\Aimaps?://!i) { $lei->{net}->imap_each($input, \&_import_net, $lei->{sto}, @@ -191,7 +190,7 @@ EOM sub import_stdin { my ($self) = @_; my $lei = $self->{lei}; - _import_fh($lei, delete $self->{0}, '', $lei->{opt}->{'format'}); + _import_fh($lei, delete $self->{0}, '', $lei->{opt}->{'in-format'}); } no warnings 'once'; # the following works even when LeiAuth is lazy-loaded -- cgit v1.2.3-24-ge0c7