style: remove unused code and updated plugin

This commit is contained in:
2018-11-26 00:58:20 -06:00
parent a2b2073bad
commit 68470e3dee
8 changed files with 108 additions and 840 deletions

View File

@@ -1,60 +1,78 @@
<?php
namespace Aerex\TaskwarriorPlugin\Taskwarrior\Commands;
use Aerex\TaskwarriorPlugin\Taskwarrior\Task;
use Aerex\TaskwarriorPlugin\Config;
use Symfony\Component\Process\Process;
class TodoStrategy implements IStrategy {
public function __construct(TaskwarriorConfig $config){
$this->config = $config;
$this->cmd[] = $this->config->taskBin();
}
public function add(Task $task){
$this->cmd[] = 'add';
$cmd[] = $this->config->getTaskBin();
$cmd[] = 'add';
if($task->getDescription() != null){
$this->cmd[] = sprintf('"%s"', $task->getDescription());
$cmd[] = sprintf('"%s"', (string)$task->getDescription());
}
if($task->getCategories() != null){
$categories = implode(' +', $task->getCategories());
$this->cmd[] = $categories;
$categories = implode(' +', (string)$task->getCategories());
$cmd[] = $categories;
}
if($task->getDue() != null){
$this->cmd[] = $task->getDue('Y-m-dTH:i:s');
$cmd[] = sprintf("due:%s",$task->getDue('Y-m-dTH:i:s'));
}
if($task->getRecurrence() != null){
$rrule = $task->getRecurrence()->getParts();
$this->cmd[] = sprintf('recur:%s', $rrule['FREQ']);
$cmd[] = sprintf('recur:%s', $rrule['FREQ']);
if(isset($rrule['UNTIL'])){
$this->cmd[] = sprintf('until:%s', $rrule['UNTIL']);
$cmd[] = sprintf('until:%s', $rrule['UNTIL']);
}
}
if($task->getStatus() != null){
$this->cmd[] = sprintf('status:%s', $task->getStatus());
$cmd[] = sprintf('status:%s', (string)$task->getStatus());
}
return $this->executeCommand($cmd);
}
public function count($uuid){
$cmd[] = $this->config->getTaskBin();
$cmd[] = sprintf('%s count', $uuid);
return $this->executeCommand($cmd);
}
private function executeCommand($command){
$rcOptions = $this->config->getOptions();
foreach ($rcOptions as $rcOption) {
$command[] = $rcOption;
}
$cmdString = implode(' ', $command);
echo $cmdString;
$process = new Process($cmdString);
$process->run();
if(!$process->isSuccessful()){
echo $process;
throw new TaskwarriorCommandLineException($process);
}
// clear cmd queue
$this->cmd = [];
return $process->getOutput();
}