Skip to content

Commit

Permalink
up: update some logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jun 22, 2020
1 parent cab39b1 commit 394a42b
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 18 deletions.
1 change: 1 addition & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
25 changes: 20 additions & 5 deletions app/Common/GitLocal/AbstractGitLocal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 2 additions & 7 deletions app/Common/GitLocal/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions app/Common/GitLocal/GitLab.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
5 changes: 5 additions & 0 deletions app/Console/Command/DocCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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());
Expand Down
51 changes: 51 additions & 0 deletions app/Console/Controller/GitHubController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,6 +38,7 @@ protected static function commandAliases(): array
return [
'wf' => 'workflow',
'rls' => 'release',
'pr' => 'pullRequest',
];
}

Expand Down Expand Up @@ -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');
}
}
8 changes: 4 additions & 4 deletions app/Console/Controller/GitLabController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Controller/PhpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
11 changes: 11 additions & 0 deletions resource/mandocs/en/mysql/update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# update

update table row.

```sql
UPDATE table_name SET field1=new-value1, field2=new-value2
[WHERE Clause]
```



0 comments on commit 394a42b

Please sign in to comment.