summaryrefslogtreecommitdiff
path: root/src/IRC/Application.php
blob: 4bb6d71e9df55519f0eeba4119652282bbc996b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

namespace FBeans\Blatask\IRC;

use FBeans\BlaIRC\Command;
use FBeans\BlaIRC\Application As BlaApplication;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;

class Application extends BlaApplication
{
    public function command(): Command
    {
        $command = new Command;
        $command->setName('task:list');

        // argument 0 is the command name
        $command->addArgument(1);

        $command->setExecuteCallback(
            function (InputInterface $input, OutputInterface $output) {
                $filter = $input->getArgument(1);

                $process_argument = ["task", "list"];

                if ($filter) {
                    $process_argument[] = $filter;
                }

                $process = new Process($process_argument);
                
                $process->run();

                if (!$process->isSuccessful()) {
                    $output->write($process->getErrorOutput());
                    return Command::SUCCESS;
                }

                $output->write($process->getOutput());
                return Command::FAILURE;
            }
        );

        return $command;
    }
}