Skip to content

Commit

Permalink
update some for command
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 30, 2020
1 parent d87d6c9 commit 6627028
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
14 changes: 8 additions & 6 deletions app/Console/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,27 @@ protected function execute($input, $output)
if (is_string($commands)) {
// Color::println("run > $commands", 'comment');
// Sys::execute($commands, false);
$ret = SysCmd::exec($this->replaceScriptVars($commands, $runArgs));
$ret = SysCmd::exec($this->replaceScriptVars($name, $commands, $runArgs));
echo $ret['output'];
return;
}

if (is_array($commands)) {
foreach ($commands as $index => $command) {
$pos = $name . '.' . $index;
if (!$command) {
$output->liteError("The script {$name}.{$index} command is empty, skip run it");
$output->liteError("The script {$pos} command is empty, skip run it");
continue;
}

if (!is_string($command)) {
$output->liteError("The script {$name}.{$index} command is not string, skip run it");
$output->liteError("The script {$pos} command is not string, skip run it");
continue;
}

// Color::println("run > $command", 'comment');
// Sys::execute($command, false);
$ret = SysCmd::exec($this->replaceScriptVars($command, $runArgs));
$ret = SysCmd::exec($this->replaceScriptVars($pos, $command, $runArgs));
echo $ret['output'];
}
return;
Expand All @@ -122,19 +123,20 @@ protected function execute($input, $output)
}

/**
* @param string $name
* @param string $cmdString
* @param array $scriptArgs
*
* @return string
*/
private function replaceScriptVars(string $cmdString, array $scriptArgs): string
private function replaceScriptVars(string $name, string $cmdString, array $scriptArgs): string
{
if (strpos($cmdString, '$') === false) {
return $cmdString;
}

if (!$scriptArgs) {
throw new PromptException('missing arguments for run script');
throw new PromptException("missing arguments for run script '{$name}'");
}

$pairs = [];
Expand Down
21 changes: 14 additions & 7 deletions app/Console/Group/GitFlowGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,27 @@ protected function beforeExecute(): bool
*/
public function syncCommand(Input $input, Output $output): void
{
$forkRemote = $this->config['fork']['remote'] ?? '';
$mainRemote = $this->config['main']['remote'] ?? '';
if (!$forkRemote || !$mainRemote) {
$output->liteError('missing config for "fork.remote" and "main.remote" on "gitflow"');
return;
}

$pwd = $input->getPwd();
$info = [
'Work Dir' => $pwd,
'Cur Branch' => $this->curBranchName,
'Work Dir' => $pwd,
'Cur Branch' => $this->curBranchName,
'Fork Remote' => $forkRemote,
'Main Remote' => $mainRemote,
];
$output->aList($info, 'Work Information');

$output->aList($info, 'Work Information', ['ucFirst' => false]);

if (!$curBranch = $this->curBranchName) {
$curBranch = GitUtil::getCurrentBranchName();
}

$forkRemote = $this->config['fork']['remote'];
$mainRemote = $this->config['main']['remote'];

$remotes = GitUtil::getRemotes($pwd);
if (!isset($remotes[$mainRemote])) {
$names = array_keys($remotes);
Expand All @@ -102,7 +109,7 @@ public function syncCommand(Input $input, Output $output): void

// git pull main BRANCH
$cmd = "git pull {$mainRemote} $curBranch";
CmdRunner::new($cmd)->do();
CmdRunner::new($cmd, $pwd)->do(true)->okDoRun('git status');

$output->success('Complete');
}
Expand Down

0 comments on commit 6627028

Please sign in to comment.