Skip to content

Commit

Permalink
Merge pull request #1718 from tarlepp/feat/as-command-attribute
Browse files Browse the repository at this point in the history
Feat - Use `AsCommand` attribute
  • Loading branch information
tarlepp committed Mar 12, 2022
2 parents 2126b10 + 9bb9571 commit fc3df7e
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 67 deletions.
19 changes: 11 additions & 8 deletions src/Command/ApiKey/ApiKeyManagementCommand.php
Expand Up @@ -9,6 +9,7 @@
namespace App\Command\ApiKey;

use App\Command\Traits\ExecuteMultipleCommandTrait;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;

/**
Expand All @@ -17,22 +18,24 @@
* @package App\Command\ApiKey
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
#[AsCommand(
name: 'api-key:management',
description: 'Console command to manage API keys',
)]
class ApiKeyManagementCommand extends Command
{
use ExecuteMultipleCommandTrait;

public function __construct()
{
parent::__construct('api-key:management');

$this->setDescription('Console command to manage API keys');
parent::__construct();

$this->setChoices([
'api-key:list' => 'List API keys',
'api-key:create' => 'Create API key',
'api-key:edit' => 'Edit API key',
'api-key:change-token' => 'Change API key token',
'api-key:remove' => 'Remove API key',
ListApiKeysCommand::NAME => 'List API keys',
CreateApiKeyCommand::NAME => 'Create API key',
EditApiKeyCommand::NAME => 'Edit API key',
ChangeTokenCommand::NAME => 'Change API key token',
RemoveApiKeyCommand::NAME => 'Remove API key',
'0' => 'Exit',
]);
}
Expand Down
11 changes: 8 additions & 3 deletions src/Command/ApiKey/ChangeTokenCommand.php
Expand Up @@ -11,6 +11,7 @@
use App\Command\Traits\SymfonyStyleTrait;
use App\Entity\ApiKey;
use App\Resource\ApiKeyResource;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -22,17 +23,21 @@
* @package App\Command\ApiKey
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
#[AsCommand(
name: self::NAME,
description: 'Command to change token for existing API key',
)]
class ChangeTokenCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'api-key:change-token';

public function __construct(
private ApiKeyResource $apiKeyResource,
private ApiKeyHelper $apiKeyHelper,
) {
parent::__construct('api-key:change-token');

$this->setDescription('Command to change token for existing API key');
parent::__construct();
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/Command/ApiKey/CreateApiKeyCommand.php
Expand Up @@ -18,6 +18,7 @@
use App\Resource\UserGroupResource;
use App\Security\RolesService;
use Matthias\SymfonyConsoleForm\Console\Helper\FormHelper;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -30,11 +31,17 @@
* @package App\Command\ApiKey
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
#[AsCommand(
name: self::NAME,
description: 'Command to create new API key',
)]
class CreateApiKeyCommand extends Command
{
use ApiKeyUserManagementHelperTrait;
use SymfonyStyleTrait;

public const NAME = 'api-key:create';

/**
* @var array<int, array<string, string>>
*/
Expand All @@ -52,9 +59,7 @@ public function __construct(
private RolesService $rolesService,
private RoleRepository $roleRepository,
) {
parent::__construct('api-key:create');

$this->setDescription('Command to create new API key');
parent::__construct();
}

public function getRolesService(): RolesService
Expand Down
11 changes: 8 additions & 3 deletions src/Command/ApiKey/EditApiKeyCommand.php
Expand Up @@ -14,6 +14,7 @@
use App\Form\Type\Console\ApiKeyType;
use App\Resource\ApiKeyResource;
use Matthias\SymfonyConsoleForm\Console\Helper\FormHelper;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -25,17 +26,21 @@
* @package App\Command\ApiKey
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
#[AsCommand(
name: self::NAME,
description: 'Command to edit existing API key',
)]
class EditApiKeyCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'api-key:edit';

public function __construct(
private ApiKeyResource $apiKeyResource,
private ApiKeyHelper $apiKeyHelper,
) {
parent::__construct('api-key:edit');

$this->setDescription('Command to edit existing API key');
parent::__construct();
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/Command/ApiKey/ListApiKeysCommand.php
Expand Up @@ -13,6 +13,7 @@
use App\Resource\ApiKeyResource;
use App\Security\RolesService;
use Closure;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -28,15 +29,19 @@
* @package App\Command\ApiKey
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
#[AsCommand(
name: self::NAME,
description: 'Console command to list API keys',
)]
class ListApiKeysCommand extends Command
{
public const NAME = 'api-key:list';

public function __construct(
private ApiKeyResource $apiKeyResource,
private RolesService $rolesService,
) {
parent::__construct('api-key:list');

$this->setDescription('Console command to list API keys');
parent::__construct();
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/Command/ApiKey/RemoveApiKeyCommand.php
Expand Up @@ -11,6 +11,7 @@
use App\Command\Traits\SymfonyStyleTrait;
use App\Entity\ApiKey;
use App\Resource\ApiKeyResource;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -22,17 +23,21 @@
* @package App\Command\ApiKey
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
#[AsCommand(
name: self::NAME,
description: 'Console command to remove existing API key',
)]
class RemoveApiKeyCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'api-key:remove';

public function __construct(
private ApiKeyResource $apiKeyResource,
private ApiKeyHelper $apiKeyHelper,
) {
parent::__construct('api-key:remove');

$this->setDescription('Console command to remove existing API key');
parent::__construct();
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/Command/User/CreateRolesCommand.php
Expand Up @@ -13,6 +13,7 @@
use App\Repository\RoleRepository;
use App\Security\RolesService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -27,18 +28,22 @@
* @package App\Command\User
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
#[AsCommand(
name: self::NAME,
description: 'Console command to create roles to database',
)]
class CreateRolesCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'user:create-roles';

public function __construct(
private EntityManagerInterface $entityManager,
private RoleRepository $roleRepository,
private RolesService $rolesService,
) {
parent::__construct('user:create-roles');

$this->setDescription('Console command to create roles to database');
parent::__construct();
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/Command/User/CreateUserCommand.php
Expand Up @@ -18,6 +18,7 @@
use App\Resource\UserResource;
use App\Security\RolesService;
use Matthias\SymfonyConsoleForm\Console\Helper\FormHelper;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -30,11 +31,17 @@
* @package App\Command\User
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
#[AsCommand(
name: self::NAME,
description: 'Console command to create user to database',
)]
class CreateUserCommand extends Command
{
use ApiKeyUserManagementHelperTrait;
use SymfonyStyleTrait;

public const NAME = 'user:create';

private const PARAMETER_NAME = 'name';
private const PARAMETER_DESCRIPTION = 'description';

Expand Down Expand Up @@ -74,9 +81,7 @@ public function __construct(
private RolesService $rolesService,
private RoleRepository $roleRepository,
) {
parent::__construct('user:create');

$this->setDescription('Console command to create user to database');
parent::__construct();
}

public function getRolesService(): RolesService
Expand Down
11 changes: 8 additions & 3 deletions src/Command/User/CreateUserGroupCommand.php
Expand Up @@ -16,6 +16,7 @@
use App\Repository\RoleRepository;
use App\Resource\UserGroupResource;
use Matthias\SymfonyConsoleForm\Console\Helper\FormHelper;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -29,11 +30,17 @@
* @package App\Command\User
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
#[AsCommand(
name: self::NAME,
description: 'Console command to create user groups',
)]
class CreateUserGroupCommand extends Command
{
use GetApplicationTrait;
use SymfonyStyleTrait;

public const NAME = 'user:create-group';

/**
* @var array<int, array<string, string>>
*/
Expand All @@ -52,9 +59,7 @@ public function __construct(
private UserGroupResource $userGroupResource,
private RoleRepository $roleRepository,
) {
parent::__construct('user:create-group');

$this->setDescription('Console command to create user groups');
parent::__construct();
}

protected function configure(): void
Expand Down
11 changes: 8 additions & 3 deletions src/Command/User/EditUserCommand.php
Expand Up @@ -14,6 +14,7 @@
use App\Form\Type\Console\UserType;
use App\Resource\UserResource;
use Matthias\SymfonyConsoleForm\Console\Helper\FormHelper;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -25,17 +26,21 @@
* @package App\Command\User
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
#[AsCommand(
name: self::NAME,
description: 'Command to edit existing user',
)]
class EditUserCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'user:edit';

public function __construct(
private UserResource $userResource,
private UserHelper $userHelper,
) {
parent::__construct('user:edit');

$this->setDescription('Command to edit existing user');
parent::__construct();
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/Command/User/EditUserGroupCommand.php
Expand Up @@ -14,6 +14,7 @@
use App\Form\Type\Console\UserGroupType;
use App\Resource\UserGroupResource;
use Matthias\SymfonyConsoleForm\Console\Helper\FormHelper;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -25,17 +26,21 @@
* @package App\Command\User
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
#[AsCommand(
name: self::NAME,
description: 'Command to edit existing user group',
)]
class EditUserGroupCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'user:edit-group';

public function __construct(
private UserGroupResource $userGroupResource,
private UserHelper $userHelper,
) {
parent::__construct('user:edit-group');

$this->setDescription('Command to edit existing user group');
parent::__construct();
}

/**
Expand Down

0 comments on commit fc3df7e

Please sign in to comment.