Skip to content

Commit

Permalink
Code: use AsCommand attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Dec 13, 2023
1 parent f2ed935 commit 1752b8a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
9 changes: 5 additions & 4 deletions src/Command/ForceRunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
namespace Contributte\Scheduler\Command;

use Contributte\Scheduler\IScheduler;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'scheduler:force-run',
description: 'Force run selected scheduler job'
)]
class ForceRunCommand extends Command
{

protected static string $defaultName = 'scheduler:force-run';

private IScheduler $scheduler;

public function __construct(IScheduler $scheduler)
Expand All @@ -24,8 +27,6 @@ public function __construct(IScheduler $scheduler)

protected function configure(): void
{
$this->setName(self::$defaultName)
->setDescription('Force run selected scheduler job');
$this->addArgument('key', InputArgument::REQUIRED, 'Job key');
}

Expand Down
13 changes: 5 additions & 8 deletions src/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

namespace Contributte\Scheduler\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'scheduler:help',
description: 'Print cron syntax'
)]
class HelpCommand extends Command
{

protected static string $defaultName = 'scheduler:help';

protected function configure(): void
{
$this->setName(self::$defaultName)
->setDescription('Print cron syntax');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('Cron syntax: ');
Expand Down
13 changes: 5 additions & 8 deletions src/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
use Contributte\Scheduler\IScheduler;
use Cron\CronExpression;
use Nette\Utils\DateTime;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'scheduler:list',
description: 'List all scheduler jobs'
)]
class ListCommand extends Command
{

protected static string $defaultName = 'scheduler:list';

private IScheduler $scheduler;

public function __construct(IScheduler $scheduler)
Expand All @@ -28,12 +31,6 @@ public function __construct(IScheduler $scheduler)
$this->scheduler = $scheduler;
}

protected function configure(): void
{
$this->setName(self::$defaultName)
->setDescription('List all scheduler jobs');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$jobs = $this->scheduler->getAll();
Expand Down
13 changes: 5 additions & 8 deletions src/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
namespace Contributte\Scheduler\Command;

use Contributte\Scheduler\IScheduler;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'scheduler:run',
description: 'Run scheduler jobs'
)]
class RunCommand extends Command
{

protected static string $defaultName = 'scheduler:run';

private IScheduler $scheduler;

public function __construct(IScheduler $scheduler)
Expand All @@ -21,12 +24,6 @@ public function __construct(IScheduler $scheduler)
$this->scheduler = $scheduler;
}

protected function configure(): void
{
$this->setName(self::$defaultName)
->setDescription('Run scheduler jobs');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->scheduler->run();
Expand Down

0 comments on commit 1752b8a

Please sign in to comment.