From 394a42bd2eb8e98090650eae55ae5603c3164af4 Mon Sep 17 00:00:00 2001 From: inhere Date: Mon, 22 Jun 2020 10:23:18 +0800 Subject: [PATCH] up: update some logic --- .php_cs | 1 + app/Common/GitLocal/AbstractGitLocal.php | 25 ++++++++-- app/Common/GitLocal/GitHub.php | 9 +--- app/Common/GitLocal/GitLab.php | 3 +- app/Console/Command/DocCommand.php | 5 ++ app/Console/Controller/GitHubController.php | 51 +++++++++++++++++++++ app/Console/Controller/GitLabController.php | 8 ++-- app/Console/Controller/PhpController.php | 2 + resource/mandocs/en/mysql/update.md | 11 +++++ 9 files changed, 97 insertions(+), 18 deletions(-) create mode 100644 resource/mandocs/en/mysql/update.md diff --git a/.php_cs b/.php_cs index 4bbff31..9383eae 100644 --- a/.php_cs +++ b/.php_cs @@ -32,6 +32,7 @@ return PhpCsFixer\Config::create() 'no_unused_imports' => true, 'single_quote' => true, 'standardize_not_equals' => true, + 'void_return' => true, // add :void for method ]) ->setFinder( PhpCsFixer\Finder::create() diff --git a/app/Common/GitLocal/AbstractGitLocal.php b/app/Common/GitLocal/AbstractGitLocal.php index a3df9b5..403cb09 100644 --- a/app/Common/GitLocal/AbstractGitLocal.php +++ b/app/Common/GitLocal/AbstractGitLocal.php @@ -2,6 +2,7 @@ namespace Inhere\Kite\Common\GitLocal; +use Inhere\Console\IO\Output; use Inhere\Kite\Helper\GitUtil; use function count; use function explode; @@ -33,21 +34,35 @@ abstract class AbstractGitLocal protected $config; /** - * @param array $config + * @var Output + */ + protected $output; + + /** + * @param Output $output + * @param array $config * * @return static */ - public static function new(array $config = []) + public static function new(Output $output, array $config = []) { - return new static($config); + return new static($output, $config); } /** * Class constructor. * - * @param array $config + * @param Output $output + * @param array $config */ - public function __construct(array $config = []) + public function __construct(Output $output,array $config = []) + { + $this->output = $output; + + $this->init($config); + } + + protected function init(array $config): void { $this->config = $config; } diff --git a/app/Common/GitLocal/GitHub.php b/app/Common/GitLocal/GitHub.php index 48eb87b..29343d6 100644 --- a/app/Common/GitLocal/GitHub.php +++ b/app/Common/GitLocal/GitHub.php @@ -46,14 +46,9 @@ class GitHub extends AbstractGitLocal */ private $dstBranch = ''; - /** - * Class constructor. - * - * @param array $config - */ - public function __construct(array $config = []) + protected function init(array $config): void { - parent::__construct($config); + parent::init($config); $this->host = self::GITHUB_HOST; } diff --git a/app/Common/GitLocal/GitLab.php b/app/Common/GitLocal/GitLab.php index a8c0d34..ba5f23b 100644 --- a/app/Common/GitLocal/GitLab.php +++ b/app/Common/GitLocal/GitLab.php @@ -39,9 +39,8 @@ class GitLab extends AbstractGitLocal * * @param array $config */ - public function __construct(array $config = []) + protected function init(array $config): void { - parent::__construct(); $this->projects = $config['projects'] ?? []; unset($config['projects']); diff --git a/app/Console/Command/DocCommand.php b/app/Console/Command/DocCommand.php index 3f34f61..fc46edd 100644 --- a/app/Console/Command/DocCommand.php +++ b/app/Console/Command/DocCommand.php @@ -62,6 +62,7 @@ protected function configure(): void $def->addOption('lang', '', Input::OPT_OPTIONAL, 'use the language for find topic document', Document::DEF_LANG); $def->addOption('create', '', Input::OPT_BOOLEAN, 'create an new topic document'); + $def->addOption('cat', '', Input::OPT_BOOLEAN, 'see the document file contents'); $def->addOption('edit', 'e', Input::OPT_BOOLEAN, 'edit an topic document'); $def->addOption('editor', '', Input::OPT_OPTIONAL, 'editor for edit the topic document', 'vim'); $def->addOption('list-topic', 'l', Input::OPT_BOOLEAN, 'list all top/sub topics'); @@ -156,6 +157,10 @@ protected function execute($input, $output) // read content $text = $file->getFileContent(); + if ($input->getBoolOpt('cat')) { + $output->writeRaw($text); + return; + } // parse content $md = new CliMarkdown($man->getLang()); diff --git a/app/Console/Controller/GitHubController.php b/app/Console/Controller/GitHubController.php index 6f0806c..943a10e 100644 --- a/app/Console/Controller/GitHubController.php +++ b/app/Console/Controller/GitHubController.php @@ -10,6 +10,7 @@ namespace Inhere\Kite\Console\Controller; use Inhere\Console\Controller; +use Inhere\Console\Exception\PromptException; use Inhere\Console\IO\Input; use Inhere\Console\IO\Output; use Inhere\Kite\Common\CmdRunner; @@ -37,6 +38,7 @@ protected static function commandAliases(): array return [ 'wf' => 'workflow', 'rls' => 'release', + 'pr' => 'pullRequest', ]; } @@ -114,4 +116,53 @@ public function cloneCommand(Input $input, Output $output): void $output->success('Complete'); } + + /** + * Configure for the `pullRequestCommand` + * + * @param Input $input + */ + protected function pullRequestConfigure(Input $input): void + { + $input->bindArgument('project', 0); + } + + /** + * generate an PR link for given project information + * + * @param Input $input + * @param Output $output + */ + public function pullRequestCommand(Input $input, Output $output): void + { + $gh = GitHub::new($output, $this->app->getParam('github', [])); + + $workDir = $input->getWorkDir(); + $gh->setWorkDir($workDir); + + // https://github.com/swoft-cloud/swoft-component/compare/master...ulue:dev2 + $pjName = ''; + $dirName = basename($workDir); + $dirPfx = $this->config['dirPrefix']; + + // try auto parse project name for dirname. + if ($dirPfx && strpos($dirName, $dirPfx) === 0) { + $tmpName = substr($dirName, strlen($dirPfx)); + + if (isset($this->projects[$tmpName])) { + $pjName = $tmpName; + $output->liteNote('auto parse project name for dirname.'); + } + } + + if (!$pjName) { + $pjName = $input->getRequiredArg('project'); + } + + if (!isset($this->projects[$pjName])) { + throw new PromptException("project '{$pjName}' is not found in the config"); + } + + $output->success('Complete'); + } } diff --git a/app/Console/Controller/GitLabController.php b/app/Console/Controller/GitLabController.php index 48a3635..aa22ea9 100644 --- a/app/Console/Controller/GitLabController.php +++ b/app/Console/Controller/GitLabController.php @@ -55,7 +55,7 @@ public static function aliases(): array protected static function commandAliases(): array { return [ - 'pr' => 'prLink', + 'pr' => 'pullRequest', 'li' => 'linkInfo', 'cf' => 'config', 'conf' => 'config', @@ -133,11 +133,11 @@ public function resolveCommand(Input $input, Output $output): void } /** - * Configure for the `linkInfoCommand` + * Configure for the `pullRequestCommand` * * @param Input $input */ - protected function prLinkConfigure(Input $input): void + protected function pullRequestConfigure(Input $input): void { $input->bindArgument('project', 0); } @@ -163,7 +163,7 @@ protected function prLinkConfigure(Input $input): void * {binWithCmd} -t qa Will generate PR link for main 'HEAD_BRANCH' to main 'qa' * {binWithCmd} -t qa --direct Will generate PR link for fork 'HEAD_BRANCH' to main 'qa' */ - public function prLinkCommand(Input $input, Output $output): void + public function pullRequestCommand(Input $input, Output $output): void { $pjName = ''; // http://gitlab.gongzl.com/wzl/order/merge_requests/new?utf8=%E2%9C%93&merge_request%5Bsource_project_id%5D=319&merge_request%5Bsource_branch%5D=fea_4_16&merge_request%5Btarget_project_id%5D=319&merge_request%5Btarget_branch%5D=qa diff --git a/app/Console/Controller/PhpController.php b/app/Console/Controller/PhpController.php index d034cd7..0b92a6f 100644 --- a/app/Console/Controller/PhpController.php +++ b/app/Console/Controller/PhpController.php @@ -51,6 +51,8 @@ protected static function commandAliases(): array * * @param Input $input * @param Output $output + * @example + * {binWithCmd} src/rpc-client */ public function csFixCommand(Input $input, Output $output): void { diff --git a/resource/mandocs/en/mysql/update.md b/resource/mandocs/en/mysql/update.md new file mode 100644 index 0000000..c9542dc --- /dev/null +++ b/resource/mandocs/en/mysql/update.md @@ -0,0 +1,11 @@ +# update + +update table row. + +```sql +UPDATE table_name SET field1=new-value1, field2=new-value2 +[WHERE Clause] +``` + + +