Skip to content

Commit

Permalink
👔 up: update str, self some commands logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 29, 2022
1 parent b44cb65 commit d89ac79
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
14 changes: 10 additions & 4 deletions app/Console/Controller/SelfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\Console\Util\PhpDevServe;
use Inhere\Kite\Console\SubCmd\InitCommand;
use Inhere\Kite\Helper\AppHelper;
use Inhere\Kite\Helper\SysCmd;
use Inhere\Kite\Kite;
Expand Down Expand Up @@ -66,6 +67,13 @@ protected static function commandAliases(): array
];
}

protected function subCommands(): array
{
return [
InitCommand::class,
];
}

protected function beforeRun(): void
{
parent::beforeRun();
Expand Down Expand Up @@ -253,7 +261,7 @@ public function objectCommand(FlagsParser $fs, Output $output): void
* update {binName} to latest from github repository(by git pull)
*
* @options
* --no-deps bool;Not update deps by composer update
* --deps bool;whether update vendor deps by `composer update`
*
* @param FlagsParser $fs
* @param Output $output
Expand All @@ -272,11 +280,9 @@ public function updateCommand(FlagsParser $fs, Output $output): void
// [, $msg,] = Sys::run($cmd);
SysCmd::quickExec($cmd, $dir);

if (!$fs->getOpt('no-deps')) {
if ($fs->getOpt('deps')) {
Color::println('Run composer update:');
$cmd = 'composer update';
// [, $msg,] = Sys::run($cmd);
// $output->writeln($msg);
SysCmd::quickExec($cmd, $dir);
}

Expand Down
20 changes: 17 additions & 3 deletions app/Console/Controller/StringController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Throwable;
use Toolkit\FsUtil\File;
use Toolkit\PFlag\FlagsParser;
use Toolkit\Stdlib\Arr;
use Toolkit\Stdlib\Json;
use Toolkit\Stdlib\Str;
use function array_pad;
Expand Down Expand Up @@ -433,7 +434,7 @@ public function replaceCommand(FlagsParser $fs, Output $output): void
* --fields The field names, split by ','
* --get-cols Only get the provide index cols, start is 0. eg: 1,5
* -o, --output The output target. default is stdout.
* --of, --out-fmt The output format. allow: raw, md-table
* --of, --out-fmt The output format. allow: raw, md/md-table, table, json
* --is, --item-sep The item sep char. default is NL.
* --vn, --value-num int;The item value number. default get from first line.
* --vs, --value-sep The item value sep char for 'space' parser. default is SPACE
Expand All @@ -457,6 +458,12 @@ public function parseCommand(FlagsParser $fs, Output $output): void
$p->setItemParser(TextParser::charSplitParser($valueSep));
}

$indexes = [];
$idxString = $fs->getOpt('get-cols');
if ($idxString && !$indexes = Str::toInts($idxString)) {
throw new InvalidArgumentException('please provide valid column index string.');
}

switch ($fs->getOpt('item-parser')) {
case 'json':
case 'json5':
Expand All @@ -466,7 +473,8 @@ public function parseCommand(FlagsParser $fs, Output $output): void
default:
$valueSep = $fs->getOpt('value-sep', ' ');
$itemParser = TextParser::charSplitParser($valueSep);
break;
// $itemParser = TextItemParser::new($valueSep, $indexes);
break;
}

$p->setItemParser($itemParser);
Expand All @@ -475,6 +483,7 @@ public function parseCommand(FlagsParser $fs, Output $output): void
$result = '';
$doOutput = true;
switch ($fs->getOpt('out-fmt')) {
case 'md':
case 'mdtable':
case 'mdTable':
case 'md-table':
Expand All @@ -488,7 +497,12 @@ public function parseCommand(FlagsParser $fs, Output $output): void
$result = $head . "\n" . $line . "\n" . implode("\n", $rows);
break;
case 'raw':
$result = $text;
case 'text':
$rows = $p->stream()->eachToArray(function (array $item) use ($indexes) {
return implode(' ', Arr::gets($item, $indexes));
});

$result = implode("\n", $rows);
break;
case 'table':
Table::show($p->getData());
Expand Down
8 changes: 4 additions & 4 deletions app/Lib/Convert/JavaProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ private function setNodeValue(array &$array, string $path, mixed $value): void
}

/**
* @param Traversable|array $data
* @param iterable $data
*
* @return string
*/
public function encode(Traversable|array $data): string
public function encode(iterable $data): string
{
$flatMap = [];
$this->flattenData($data, $flatMap);
Expand All @@ -97,11 +97,11 @@ public function encode(Traversable|array $data): string
}

/**
* @param Traversable|array $data
* @param iterable $data
* @param string $parentPath
* @param array $flatMap
*/
private function flattenData(Traversable|array $data, array &$flatMap = [], string $parentPath = ''): void
private function flattenData(iterable $data, array &$flatMap = [], string $parentPath = ''): void
{
foreach ($data as $key => $val) {
if ($parentPath) {
Expand Down
1 change: 1 addition & 0 deletions app/Lib/Generate/AbstractGenCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function prepareContext(): void
'package' => 'YOUR.PKG.NAME',
'modulePkg' => 'MODULE_PKG',
'pkgName' => 'PKG_NAME',
'subPkg' => 'SUB_PKG',
]);
}

Expand Down

0 comments on commit d89ac79

Please sign in to comment.