Skip to content

Commit

Permalink
up: update redirect to git commands logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Sep 23, 2021
1 parent 76f07be commit 45bb016
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 26 deletions.
48 changes: 48 additions & 0 deletions app/Console/Component/RedirectToGitGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php declare(strict_types=1);

namespace Inhere\Kite\Console\Component;

use Inhere\Console\Application;
use Inhere\Console\Console;
use Inhere\Kite\Console\Controller\GitController;
use Throwable;
use Toolkit\Cli\Cli;
use Toolkit\Stdlib\Obj\AbstractObj;
use function in_array;

/**
* class RedirectToGitGroup
*/
class RedirectToGitGroup extends AbstractObj
{
/**
* @var array
*/
public $cmdList = [];

/**
* @param Application $app
* @param string $action
* @param array $args
*
* @return bool
* @throws Throwable
*/
public function handle(Application $app, string $action, array $args):bool
{
// resolve alias
$gitCtrl = $app->getController(GitController::getName());
$command = $gitCtrl->resolveAlias($action);

$redirectList = $this->cmdList;
if (in_array($command, $redirectList, true)) {
Cli::info("NOTICE: will redirect to git group for run `git $command`");
// Console::app()->dispatch("git:$command");
// Console::app()->dispatch("git:$command", $this->flags->getRawArgs());
Console::app()->dispatch("git:$command", $args);
return true;
}

return false;
}
}
30 changes: 18 additions & 12 deletions app/Console/Controller/GitHubController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Inhere\Console\IO\Output;
use Inhere\Kite\Common\CmdRunner;
use Inhere\Kite\Common\GitLocal\GitHub;
use Inhere\Kite\Console\Component\RedirectToGitGroup;
use Inhere\Kite\Helper\AppHelper;
use PhpComp\Http\Client\Client;
use Throwable;
Expand Down Expand Up @@ -86,20 +87,25 @@ protected function onNotFound(string $action, array $args): bool
return false;
}

// resolve alias
$gitCtrl = $this->app->getController(GitController::getName());
$command = $gitCtrl->resolveAlias($action);
$h = RedirectToGitGroup::new([
'cmdList' => $this->settings['redirectGit'] ?? [],
]);

$redirectGitGroup = $this->settings['redirectGit'] ?? [];
return $h->handle($this->app, $action, $args);

if (in_array($command, $redirectGitGroup, true)) {
$this->output->notice("will redirect to git group for run `git $command`");
// Console::app()->dispatch("git:$command");
Console::app()->dispatch("git:$command", $args);
return true;
}

return false;
// resolve alias
// $gitCtrl = $this->app->getController(GitController::getName());
// $command = $gitCtrl->resolveAlias($action);
//
// $redirectGitGroup = $this->settings['redirectGit'] ?? [];
// if (in_array($command, $redirectGitGroup, true)) {
// $this->output->notice("will redirect to git group for run `git $command`");
// // Console::app()->dispatch("git:$command");
// Console::app()->dispatch("git:$command", $args);
// return true;
// }
//
// return false;
}

// protected function beforeAction(): bool
Expand Down
33 changes: 19 additions & 14 deletions app/Console/Controller/GitLabController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Inhere\Kite\Common\CmdRunner;
use Inhere\Kite\Common\GitLocal\GitLab;
use Inhere\Kite\Console\Attach\Gitlab\ProjectInit;
use Inhere\Kite\Console\Component\RedirectToGitGroup;
use Inhere\Kite\Helper\AppHelper;
use Inhere\Kite\Helper\GitUtil;
use Throwable;
Expand Down Expand Up @@ -146,21 +147,25 @@ protected function onNotFound(string $action, array $args): bool
return false;
}

// resolve alias
$gitCtrl = $this->app->getController(GitController::getName());
$command = $gitCtrl->resolveAlias($action);

$redirectGitGroup = $this->settings['redirectGit'] ?? [];

if (in_array($command, $redirectGitGroup, true)) {
$this->output->notice("will redirect to git group for run `git $command`");
// Console::app()->dispatch("git:$command");
// Console::app()->dispatch("git:$command", $this->flags->getRawArgs());
Console::app()->dispatch("git:$command", $args);
return true;
}
$h = RedirectToGitGroup::new([
'cmdList' => $this->settings['redirectGit'] ?? [],
]);

return false;
return $h->handle($this->app, $action, $args);
// resolve alias
// $gitCtrl = $this->app->getController(GitController::getName());
// $command = $gitCtrl->resolveAlias($action);
//
// $redirectGitGroup = $this->settings['redirectGit'] ?? [];
// if (in_array($command, $redirectGitGroup, true)) {
// $this->output->notice("will redirect to git group for run `git $command`");
// // Console::app()->dispatch("git:$command");
// // Console::app()->dispatch("git:$command", $this->flags->getRawArgs());
// Console::app()->dispatch("git:$command", $args);
// return true;
// }
//
// return false;
}

/**
Expand Down

0 comments on commit 45bb016

Please sign in to comment.