Skip to content

Commit

Permalink
👔 up: update some generate commands logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 17, 2023
1 parent 4704e01 commit 3f0e2c4
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 14 deletions.
5 changes: 0 additions & 5 deletions app/Console/Controller/GoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ class GoController extends Controller

protected static string $desc = 'Some useful tool commands for go development';

public static function isEnabled(): bool
{
return false;
}

protected static function commandAliases(): array
{
return [
Expand Down
3 changes: 2 additions & 1 deletion app/Console/Controller/JsonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public function ml2lineCommand(): void
* -o, --output The output target. default is STDOUT.
* --tpl-dir The custom template file dir path.
* --tpl, --tpl-file The custom template file name or path.
* -t, --type string;the generate code language type, allow: java, php;;php
* -t, --type string;the generate code language type, allow: java, php, go;;php
* -c, --ctx array;provide context data, allow multi, format KEY:VALUE
*
* @param FlagsParser $fs
Expand Down Expand Up @@ -421,6 +421,7 @@ public function toClassCommand(FlagsParser $fs, Output $output): void
->setSource($json)
->configThis($config)
->loadVarsFromStrings($fs->getOpt('ctx'))
->addTplVar('genMark', $this->input->getFullScript(true))
->setPathResolver([Kite::class, 'resolve'])
->prepare();

Expand Down
2 changes: 1 addition & 1 deletion app/Console/SubCmd/GolangCmd/GenerateStructCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function execute(Input $input, Output $output): void

$tplFile = $fs->getOpt('tpl-file');
if (!$tplFile) {
$tplFile = "$tplDir/struct.tpl";
$tplFile = "$tplDir/dto.tpl";
}

$config = array_merge($config, array_filter([
Expand Down
8 changes: 8 additions & 0 deletions app/Lib/Generate/JsonToGoStruct.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@
class JsonToGoStruct extends AbstractJsonToCode
{
public const TYPE = 'go';

/**
* @return string
*/
public function getLang(): string
{
return self::TYPE;
}
}
2 changes: 2 additions & 0 deletions app/Lib/Generate/Type/GolangType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
class GolangType
{
public const INT64 = 'int64';

public const UINT64 = 'uint64';

}
11 changes: 6 additions & 5 deletions app/Lib/Parser/Item/FieldItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Inhere\Kite\Lib\Generate\Java\JavaType;
use Inhere\Kite\Lib\Generate\LangName;
use Inhere\Kite\Lib\Generate\Type\GolangType;
use JsonSerializable;
use Toolkit\Stdlib\Json;
use Toolkit\Stdlib\Obj\AbstractObj;
Expand Down Expand Up @@ -69,11 +70,11 @@ public function getType(string $lang = LangName::PHP): string
*/
public function golangType(): string
{
if ($this->type === 'long') {
return 'int64';
}

return $this->type;
return match ($this->type) {
JavaType::LONG => GolangType::INT64,
Type::INTEGER => Type::INT,
default => $this->type,
};
}

/**
Expand Down
1 change: 0 additions & 1 deletion app/Lib/Parser/Text/Json5ItemParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function __invoke(string $line): array
}
return [];
}

// url
if (str_contains($line, '://')) {
$line = preg_replace('/https?:\/\//', 'XX', $line);
Expand Down
2 changes: 1 addition & 1 deletion app/Lib/Parser/Text/JsonItemParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __invoke(string $line): array
public static function matchField(string $line): array
{
// is value of array.
if (!str_contains($line, '": ')) {
if (!str_contains($line, '":')) {
return [];
}

Expand Down

0 comments on commit 3f0e2c4

Please sign in to comment.