App-karr
view release on metacpan or search on metacpan
lib/App/karr/Cmd/Show.pm view on Meta::CPAN
# ABSTRACT: Show full details of a task
package App::karr::Cmd::Show;
our $VERSION = '0.500';
use Moo;
use MooX::Cmd;
use MooX::Options (
usage_string => 'USAGE: karr show [ID] [--me] [--agent NAME] [--last N] [--json]',
);
use App::karr::Role::BoardAccess;
use App::karr::Role::Output;
use App::karr::Task;
with 'App::karr::Role::BoardAccess', 'App::karr::Role::Output';
option last => (
is => 'ro',
format => 'i',
default => sub { 1 },
doc => 'Number of recent tasks to show (default: 1)',
);
option me => (
is => 'ro',
doc => 'Show the task(s) my identity most recently acted on',
);
option agent => (
is => 'ro',
format => 's',
doc => 'Show the task(s) most recently claimed by this agent name',
);
sub _show_task {
my ($self, $task) = @_;
if ($self->json) {
$self->print_json($task->to_json_hash);
return;
}
printf "Task #%d: %s\n", $task->id, $task->title;
printf "Status: %s\n", $task->status;
printf "Priority: %s\n", $task->priority;
printf "Class: %s\n", $task->class;
printf "Assignee: %s\n", $task->assignee if $task->has_assignee;
printf "Tags: %s\n", join(', ', @{$task->tags}) if @{$task->tags};
printf "Due: %s\n", $task->due if $task->has_due;
printf "Estimate: %s\n", $task->estimate if $task->has_estimate;
printf "Depends: %s\n",
join( ', ', map { $self->_dependency_label($_) } @{$task->depends_on} )
if @{$task->depends_on};
printf "Claimed: %s\n", $task->claimed_by if $task->has_claimed_by;
printf "Blocked: %s\n", $task->has_block_reason ? $task->block_reason : 'yes'
if $task->has_blocked;
printf "Created: %s\n", $task->created;
printf "Updated: %s\n", $task->updated;
if (defined $task->body && length $task->body) {
print "\n" . $task->body . "\n";
}
}
# A bare id list answers the wrong question: `depends_on: [5]` tells the reader
# nothing about whether 5 is finished, which is the only thing they wanted to
# know. Half of what made ticket #123 a trap was that `show` did not print the
# field at all, so a dependency recorded on a card was invisible to the one
# reader who could have acted on it. An id the board does not have is called
# unknown rather than left to look like a status.
sub _dependency_label {
my ($self, $dep_id) = @_;
my $dep = $self->find_task($dep_id);
return sprintf '%s (unknown)', $dep_id unless $dep;
return sprintf '%s (%s)', $dep_id, $dep->status;
}
# Tasks sorted most-recently-updated first.
sub _by_updated {
my ($self, @tasks) = @_;
return sort { ($b->updated // '') cmp ($a->updated // '') } @tasks;
}
# Task ids the current identity most recently acted on, newest first, deduped.
sub _my_recent_ids {
my ($self, $limit) = @_;
my @ids;
my %seen;
for my $entry (reverse $self->activity_log->entries) {
my $tid = $entry->{task_id};
next unless defined $tid;
next if $seen{$tid}++;
push @ids, $tid;
last if @ids >= $limit;
}
return @ids;
}
sub _select_tasks {
my ($self, $id) = @_;
# Explicit id always wins.
if (defined $id) {
my $task = $self->find_task($id);
die "Task $id not found\n" unless $task;
return ($task);
}
my $limit = $self->last;
if ($self->me) {
my @tasks = grep { defined } map { $self->find_task($_) } $self->_my_recent_ids($limit);
return @tasks;
}
if (defined $self->agent) {
my @claimed = grep { $_->has_claimed_by && $_->claimed_by eq $self->agent } $self->load_tasks;
( run in 1.039 second using v1.01-cache-2.11-cpan-788537b7465 )