ValidatorCommand.php 995 Bytes
Newer Older
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
<?php

/**
 * Created by PhpStorm.
 * User: wangy
 * Date: 2020/2/12
 * Time: 10:49
 */

namespace Meibuyu\Micro\Command;

use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Meibuyu\Micro\Generator\FileAlreadyExistsException;
use Meibuyu\Micro\Generator\ValidatorGenerator;
use Symfony\Component\Console\Input\InputArgument;

/**
 * @Command()
 */
class ValidatorCommand extends HyperfCommand
{

    protected $name = 'gen:validator';

    /**
     * Handle the current command.
     */
    public function handle()
    {
        try {
            $name = $this->input->getArgument('name');
            (new ValidatorGenerator(['name' => $name]))->run();
            $this->info("Validator created successfully.");
        } catch (FileAlreadyExistsException $e) {
            $this->error($e->getMessage() . ' already exists!');
        }
    }

    public function getArguments()
    {
        return [['name', InputArgument::REQUIRED, '名称']];
    }

}