From 84950328cc4d754fbd5084127456902769fcdd2b Mon Sep 17 00:00:00 2001 From: Inhere Date: Sun, 24 Jul 2022 13:13:48 +0800 Subject: [PATCH] up: update some for jump commands --- Dockerfile | 2 +- Makefile | 3 +++ app/Console/Attach/Golang/GenerateStructCmd.php | 3 +++ app/Console/Controller/JumpController.php | 1 + app/Lib/Jump/JumpStorage.php | 6 +++--- app/Lib/Parser/Item/FieldItem.php | 2 +- composer.json | 1 + resource/templates/quick-jump/jump.bash | 2 +- resource/templates/quick-jump/jump.zsh | 6 ++++-- script/phptests/json_encode.php | 6 ++++++ 10 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 script/phptests/json_encode.php diff --git a/Dockerfile b/Dockerfile index 24e203d..9b07c06 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # docker build . -t inhere:kite # run: # docker run inhere:kite gh cl -h -FROM php:8.0-alpine +FROM php:8.1 ENV KITE_CMD="list" WORKDIR /appdir diff --git a/Makefile b/Makefile index 230d892..669885a 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,9 @@ up-dev-deps: ## Update kite composer.lock and all depends on vendor phar: ## build kite application to phar package php -d phar.readonly=0 bin/kite phar:pack -o kite.phar +micro-bin:phar ## build kite application to phar package + cat ~/Workspace/php/phpsrc/php-src/sapi/micro/micro.sfx kite.phar > kiteapp + cs-fix: ## Fix code style for all files gofmt -w ./ diff --git a/app/Console/Attach/Golang/GenerateStructCmd.php b/app/Console/Attach/Golang/GenerateStructCmd.php index 6119ebb..200dccc 100644 --- a/app/Console/Attach/Golang/GenerateStructCmd.php +++ b/app/Console/Attach/Golang/GenerateStructCmd.php @@ -24,6 +24,7 @@ use function array_filter; use function array_merge; use function get_class; +use function println; use function str_replace; /** @@ -104,6 +105,8 @@ protected function execute(Input $input, Output $output): void case 'yaml': $data = ConfigUtil::parseYamlString($source); $p->setText(Json::pretty($data)); + $output->colored('JSON from YAML:'); + println($p->getText()); $itemParser = new Json5ItemParser; $itemParser->setKeyField('name'); break; diff --git a/app/Console/Controller/JumpController.php b/app/Console/Controller/JumpController.php index 00c70ba..98d9cda 100644 --- a/app/Console/Controller/JumpController.php +++ b/app/Console/Controller/JumpController.php @@ -51,6 +51,7 @@ protected static function commandAliases(): array 'hint' => ['match', 'search'], 'chdir' => ['into'], 'get' => ['cd'], + 'list' => ['ls'], ]; } diff --git a/app/Lib/Jump/JumpStorage.php b/app/Lib/Jump/JumpStorage.php index 94f1dff..adfd8fb 100644 --- a/app/Lib/Jump/JumpStorage.php +++ b/app/Lib/Jump/JumpStorage.php @@ -268,12 +268,12 @@ public function dumpTo(string $datafile = '', bool $force = false): void */ public function matchOne(string $keywords): string { - if (!$keywords || '.' === $keywords) { + if ('.' === $keywords) { return OS::getWorkDir(); } - // latestPath - if ($keywords === '-') { + // jump to prev path + if (!$keywords || $keywords === '-') { return $this->prevPath; } diff --git a/app/Lib/Parser/Item/FieldItem.php b/app/Lib/Parser/Item/FieldItem.php index 762c52d..e2775cb 100644 --- a/app/Lib/Parser/Item/FieldItem.php +++ b/app/Lib/Parser/Item/FieldItem.php @@ -28,7 +28,7 @@ class FieldItem extends AbstractObj implements JsonSerializable /** * @var string */ - public string $type = ''; + public string $type = 'string'; /** * sub-elem type on type is array diff --git a/composer.json b/composer.json index 8f977b0..84b0fde 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "ext-mbstring": "*", "inhere/console": "dev-master", "inhere/sroute": "dev-master", + "inhere/php-validate": "dev-master", "cebe/markdown": "^1.2", "colinodell/json5": "^2.2", "gitonomy/gitlib": "^1.3", diff --git a/resource/templates/quick-jump/jump.bash b/resource/templates/quick-jump/jump.bash index 3df8de7..316e0d4 100644 --- a/resource/templates/quick-jump/jump.bash +++ b/resource/templates/quick-jump/jump.bash @@ -40,7 +40,7 @@ __jump_completion() { # - $term='hi' local term="${COMP_WORDS[COMP_CWORD]}" - local commands=$(kite jump hint "$term" --no-name) + local commands=$(kite jump hint --no-name "$term") # echo commands: # echo $commands --- ${commands[@]} # COMPREPLY=$commands diff --git a/resource/templates/quick-jump/jump.zsh b/resource/templates/quick-jump/jump.zsh index 755b97c..eced8e9 100644 --- a/resource/templates/quick-jump/jump.zsh +++ b/resource/templates/quick-jump/jump.zsh @@ -9,6 +9,8 @@ # set +x # stop # typeset -ft __jump_chpwd # start for given function # typeset +ft __jump_chpwd # stop +# typeset -ft _jump_completion # start for given function +# typeset +ft _jump_completion # stop # # The following lines are autogenerated: @@ -43,8 +45,8 @@ _jump_completion() { kite util log "words: $words (w1: $words[1] w2: $words[2]) state: $state" --type "jump-comp2" # commands+=($(kite jump hint "$@")) - commands+=($(kite jump hint $words[2] --flag 1)) - histories+=($(kite jump hint $words[2] --flag 2)) + commands+=($(kite jump hint --flag 1 $words[2])) + histories+=($(kite jump hint --flag 2 $words[2])) # _describe -t 'commands' commands _describe 'commands' commands -- histories _alternative \ diff --git a/script/phptests/json_encode.php b/script/phptests/json_encode.php new file mode 100644 index 0000000..eddd20e --- /dev/null +++ b/script/phptests/json_encode.php @@ -0,0 +1,6 @@ + 'bar', 'baz' => 'long', 'emptySub' => []]; + +echo "Associative array always output as object: ", json_encode($d), "\n"; +echo "Associative array always output as object: ", json_encode($d, JSON_FORCE_OBJECT), "\n\n";