From 9048e2200e590ff4e6d2775abbb3792036963bc1 Mon Sep 17 00:00:00 2001 From: Gerhard Gonter <ggonter@gmail.com> Date: Sat, 27 Jul 2024 19:36:41 +0200 Subject: [PATCH] allow selective download of several attachments, attached to one issue --- lib/Redmine/CLI.pm | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/Redmine/CLI.pm b/lib/Redmine/CLI.pm index 1db927a..a684b04 100644 --- a/lib/Redmine/CLI.pm +++ b/lib/Redmine/CLI.pm @@ -281,6 +281,8 @@ sub interpret return undef; } + my @res; + if ($op_mode eq 'help') { usage('help', (@$pars) ? shift (@$pars) : 'overview'); } elsif ($op_mode eq 'exit') { return 0; } elsif ($op_mode eq 'interact' || $op_mode eq 'i') @@ -338,6 +340,7 @@ sub interpret my $out_tsv= $self->{out_tsv}; my ($proj_list, $csv)= Redmine::CLI::show_projects ($rm, $out_tsv); $self->{project_list}= $proj_list; + push (@res, $proj_list); } elsif ($op_mode eq 'wiki') { @@ -375,8 +378,9 @@ sub interpret push (@$pars, $self->{ticket_number}) if (!@$pars && exists ($self->{ticket_number})); foreach my $ticket_number (@$pars) { - Redmine::CLI::show_issue ($rm, $ticket_number); + my $issue= Redmine::CLI::show_issue ($rm, $ticket_number); $self->{ticket_number}= $ticket_number; + push (@res, $issue); } } elsif ($op_mode eq 'att') @@ -453,7 +457,7 @@ not needed? =end comment =cut - return 1; + return (1, \@res); } sub interact @@ -474,7 +478,7 @@ sub interact my ($op, @pars)= split (' ', $l); print "op=[$op]\n"; - my $continue= interpret ($self, $op, \@pars); + my ($continue)= interpret ($self, $op, \@pars); last unless ($continue); } } @@ -745,7 +749,7 @@ sub download_attachment { my $rm= shift; my $ticket_number= shift; - my $number= shift || 0; + my $number= shift; my $ua= $rm->{ua}; return undef unless (defined ($ua)); @@ -755,13 +759,25 @@ sub download_attachment # print "attachments: ", Dumper ($attachments); return undef unless (defined ($attachments)); - my $attachment= $attachments->[$number]; - return undef unless (defined ($attachment)); - print "attachment: ", Dumper ($attachment); + my @attachment_numbers; + if (!defined ($number) || $number eq '*') { push (@attachment_numbers, 0 .. $#$attachments); } + elsif ($number =~ /^\d+$/) { @attachment_numbers= $number; } + elsif ($number =~ /^\d[\d,-]*\d$/) { print "number ranges not yet implemented\n"; return undef; } + + print __LINE__, " attachment_numbers: ", join(' ', @attachment_numbers), "\n"; - $ua->get($attachment->{content_url}, ':content_file' => $attachment->{filename}); + my @dl_attachments; + foreach my $num (@attachment_numbers) + { + my $attachment= $attachments->[$num]; + next unless (defined ($attachment)); + # print __LINE__, " attachment: ", Dumper ($attachment); + print __LINE__, " attachment num=[$num] ", $attachment->{filename}, "\n"; + $ua->get($attachment->{content_url}, ':content_file' => $attachment->{filename}); + push (@dl_attachments, $attachment); + } - $attachment; + return (wantarray) ? @dl_attachments : \@dl_attachments; } sub usage -- GitLab