From 6ba4ab8fb8f9c82f235656c00457c9f6dbe64ea7 Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 27 Dec 2016 16:49:40 +0000 Subject: auto-complete mail-ids for moderation commands --- lib/Sietima/Role/SubscriberOnly/Moderate.pm | 45 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'lib') diff --git a/lib/Sietima/Role/SubscriberOnly/Moderate.pm b/lib/Sietima/Role/SubscriberOnly/Moderate.pm index 7e231ed..678b66c 100644 --- a/lib/Sietima/Role/SubscriberOnly/Moderate.pm +++ b/lib/Sietima/Role/SubscriberOnly/Moderate.pm @@ -57,42 +57,39 @@ sub show_mail_from_moderation_queue ($self,$runner,@) { around command_line_spec => sub ($orig,$self) { my $spec = $self->$orig(); + + my $list_mail_ids = sub ($self,$runner,$args) { + $self->mail_store->retrieve_ids_by_tags('moderation'); + }; + my $etc = sub($cmd) { + return ( + summary => "$cmd the given mail, currently held for moderation", + parameters => [ + { + name => 'mail-id', + required => 1, + summary => "id of the mail to $cmd", + completion => { op => $list_mail_ids }, + }, + ], + ); + }; + $spec->{subcommands}{'show-held'} = { op => 'show_mail_from_moderation_queue', - summary => 'shows the given mail, currently held for moderation', - parameters => [ - { - name => 'mail-id', - required => 1, - summary => 'id of the mail to show', - }, - ], + $etc->('show'), }; $spec->{subcommands}{'resume-held'} = { op => sub ($self,$runner,$args) { $self->resume($runner->parameters->{'mail-id'}); }, - summary => 'resume the given mail, currently held for moderation', - parameters => [ - { - name => 'mail-id', - required => 1, - summary => 'id of the mail to resume', - }, - ], + $etc->('resume'), }; $spec->{subcommands}{'drop-held'} = { op => sub ($self,$runner,$args) { $self->drop($runner->parameters->{'mail-id'}); }, - summary => 'drop the given mail, currently held for moderation', - parameters => [ - { - name => 'mail-id', - required => 1, - summary => 'id of the mail to drop', - }, - ], + $etc->('drop'), }; $spec->{subcommands}{'list-held'} = { op => 'list_mails_in_moderation_queue', -- cgit v1.2.3