Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 30, 2020
1 parent d7cd3ab commit d87d6c9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
16 changes: 11 additions & 5 deletions app/Console/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
namespace Inhere\Kite\Console\Command;

use Inhere\Console\Command;
use Inhere\Console\Exception\ConsoleException;
use Inhere\Console\Exception\PromptException;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\Kite\Helper\SysCmd;
Expand Down Expand Up @@ -78,7 +80,7 @@ protected function execute($input, $output)
}

if (!isset($scripts[$name])) {
$output->liteError('please input an exists script name for run');
$output->liteError("please input an exists script name for run. ('{$name}' not exists)");
return;
}

Expand Down Expand Up @@ -121,20 +123,24 @@ protected function execute($input, $output)

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

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

$pairs = [];

// like bash script, first var is '$1'
foreach ($args as $i => $arg) {
foreach ($scriptArgs as $i => $arg) {
$pairs['$' . $i] = $arg;
}

Expand Down
17 changes: 17 additions & 0 deletions app/Console/Group/UtilGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,21 @@ public function dateCommand(Input $input, Output $output): void
$output->println('Time: ' . date('Y-m-d H:i:s'));
// $output->success('Complete');
}

/**
* print system ENV information
*
* @options
* --format Format the env value
*
* @arguments
* keywords The keywords for search ENV
*
* @param Input $input
* @param Output $output
*/
public function envCommand(Input $input, Output $output): void
{
// env | grep XXX
}
}
3 changes: 2 additions & 1 deletion bin/kite
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ $app->on(Application::ON_NOT_FOUND, static function (string $cmd, Application $a
$app->getOutput()->note("command not found, redirect to run script: $cmd");

$args = $app->getInput()->getArgs();
$args = array_merge([$cmd], $args);

$app->getInput()->setArgs(array_merge([$cmd], $args));
$app->getInput()->setArgs($args, true);
$app->dispatch('run');

return true;
Expand Down

0 comments on commit d87d6c9

Please sign in to comment.