Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10360682
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/workflow/ArcanistTasksWorkflow.php b/src/workflow/ArcanistTasksWorkflow.php
index 0b9d777d..f88634fd 100644
--- a/src/workflow/ArcanistTasksWorkflow.php
+++ b/src/workflow/ArcanistTasksWorkflow.php
@@ -1,278 +1,212 @@
<?php
/**
* Displays User Tasks
*
* @group workflow
*/
final class ArcanistTasksWorkflow extends ArcanistBaseWorkflow {
private $tasks;
public function getWorkflowName() {
return 'tasks';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**tasks** [__options__]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
View all assigned tasks.
EOTEXT
);
}
public function requiresConduit() {
return true;
}
public function requiresRepositoryAPI() {
return false;
}
public function requiresAuthentication() {
return true;
}
-
public function getArguments() {
return array(
'status' => array(
'param' => 'task_status',
'help' => 'Show tasks that or open or closed, default is open.',
),
'owner' => array(
'param' => 'username',
'paramtype' => 'username',
'help' =>
'Only show tasks assigned to the given username, '.
'also accepts @all to show all, default is you.',
'conflict' => array(
'unassigned' => '--owner suppresses unassigned',
),
),
'order' => array(
'param' => 'task_order',
'help' =>
'Arrange tasks based on priority, created, or modified, '.
'default is priority.',
),
'limit' => array(
'param' => 'n',
'paramtype' => 'int',
'help' => 'Limit the amount of tasks outputted, default is all.',
),
'unassigned' => array(
'help' => 'Only show tasks that are not assigned (upforgrabs).',
- )
+ ),
);
}
public function run() {
$output = array();
$status = $this->getArgument('status');
$owner = $this->getArgument('owner');
$order = $this->getArgument('order');
$limit = $this->getArgument('limit');
$unassigned = $this->getArgument('unassigned');
if ($owner) {
$owner_phid = $this->findOwnerPhid($owner);
} else if ($unassigned) {
$owner_phid = null;
} else {
$owner_phid = $this->getUserPHID();
}
$this->tasks = $this->loadManiphestTasks(
($status == 'all' ? 'any' : $status),
$owner_phid,
$order,
$limit);
if (!$this->tasks) {
echo "No tasks found.\n";
return 0;
}
- $task_rows = array();
+ $table = id(new PhutilConsoleTable())
+ ->setShowHeader(false)
+ ->addColumn('id', array('title' => 'ID'))
+ ->addColumn('title', array('title' => 'Title'))
+ ->addColumn('priority', array('title' => 'Priority'))
+ ->addColumn('status', array('title' => 'Status'));
+
foreach ($this->tasks as $task) {
$output = array();
// Render the "T123" column.
$task_id = 'T'.$task['id'];
- $formatted_task_id = phutil_console_format(
- '**%s**',
- $task_id);
- $output['id'] = array(
- 'text' => $formatted_task_id,
- 'len' => phutil_utf8_console_strlen($task_id),
- );
+ $formatted_task_id = phutil_console_format('**%s**', $task_id);
+ $output['id'] = $formatted_task_id;
// Render the "Title" column.
$formatted_title = rtrim($task['title']);
- $output['title'] = array(
- 'text' => $formatted_title,
- 'len' => phutil_utf8_console_strlen($formatted_title),
- );
-
+ $output['title'] = $formatted_title;
// Render the "Priority" column.
$web_to_terminal_colors = array(
'violet' => 'magenta',
'indigo' => 'magenta',
'orange' => 'red',
'sky' => 'cyan',
'red' => 'red',
'yellow' => 'yellow',
'green' => 'green',
'blue' => 'blue',
'cyan' => 'cyan',
'magenta' => 'magenta',
'lightred' => 'red',
'lightorange' => 'red',
'lightyellow' => 'yellow',
'lightgreen' => 'green',
'lightblue' => 'blue',
'lightsky' => 'blue',
'lightindigo' => 'magenta',
- 'lightviolet' => 'magenta'
+ 'lightviolet' => 'magenta',
);
if (isset($task['priorityColor'])) {
$color = idx($web_to_terminal_colors, $task['priorityColor'], 'white');
} else {
$color = 'white';
}
$formatted_priority = phutil_console_format(
"<bg:{$color}> </bg> %s",
$task['priority']);
- $output['priority'] = array(
- 'text' => $formatted_priority,
- 'len' => phutil_utf8_console_strlen($task['priority']) + 2,
- );
+ $output['priority'] = $formatted_priority;
// Render the "Status" column.
if (isset($task['isClosed'])) {
if ($task['isClosed']) {
$status_text = $task['statusName'];
$status_color = 'red';
} else {
$status_text = $task['statusName'];
$status_color = 'green';
}
$formatted_status = phutil_console_format(
"<bg:{$status_color}> </bg> %s",
$status_text);
- $output['status'] = array(
- 'text' => $formatted_status,
- 'len' => phutil_utf8_console_strlen('status') + 2,
- );
+ $output['status'] = $formatted_status;
} else {
- $output['status'] = array(
- 'text' => '',
- 'len' => 0,
- );
- }
-
- $task_rows[] = $output;
- }
-
- // Find the longest string in each column.
- $col_size = array();
- foreach ($task_rows as $row) {
- foreach ($row as $key => $col) {
- if (empty($col_size[$key])) {
- $col_size[$key] = 0;
- }
- $col_size[$key] = max($col_size[$key], $col['len']);
+ $output['status'] = '';
}
- }
-
- // Determine the terminal width. If we can't figure it out, assume 80.
- $width = nonempty(phutil_console_get_terminal_width(), 80);
-
-
- // We're going to clip the titles so they'll all fit in one line on the
- // terminal. Figure out where to clip them.
- $padding_between_columns = 4;
- $clip_title_at = max(
- // Always show at least a little bit of text even if it will make the
- // UI wrap, since it's useless if we don't show anything.
- 16,
- $width -
- ($col_size['id'] + $col_size['priority'] + $col_size['status'] +
- ($padding_between_columns * 3)));
- $col_size['title'] = min($col_size['title'], $clip_title_at);
-
- foreach ($task_rows as $key => $cols) {
- $new_title = phutil_utf8_shorten($cols['title']['text'], $clip_title_at);
- $task_rows[$key]['title']['len'] = phutil_utf8_console_strlen($new_title);
- $task_rows[$key]['title']['text'] = $new_title;
+ $table->addRow($output);
}
- $table = array();
- foreach ($task_rows as $row) {
- $trow = array();
- foreach ($row as $col => $cell) {
- $text = $cell['text'];
- $pad_len = $col_size[$col] - $cell['len'];
- if ($pad_len) {
- $text .= str_repeat(' ', $pad_len);
- }
- $trow[] = $text;
- }
- $table[] = implode(str_repeat(' ', $padding_between_columns), $trow);
- }
- $table = implode("\n", $table)."\n";
-
- echo $table;
+ $table->draw();
}
private function findOwnerPHID($owner) {
$conduit = $this->getConduit();
$users = $conduit->callMethodSynchronous(
'user.query',
array(
'usernames' => array($owner),
));
if (!$users) {
return null;
}
$user = head($users);
return idx($user, 'phid');
}
private function loadManiphestTasks($status, $owner_phid, $order, $limit) {
$conduit = $this->getConduit();
$find_params = array();
if ($owner_phid !== null) {
$find_params['ownerPHIDs'] = array($owner_phid);
}
if ($limit !== false) {
$find_params['limit'] = $limit;
}
$find_params['order'] = ($order ? 'order-'.$order : 'order-priority');
$find_params['status'] = ($status ? 'status-'.$status : 'status-open');
- $tasks = $conduit->callMethodSynchronous(
- 'maniphest.query',
- $find_params);
-
- return $tasks;
+ return $conduit->callMethodSynchronous('maniphest.query', $find_params);
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Nov 8, 08:20 (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1034328
Default Alt Text
(8 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline
Log In to Comment