Skip to content

Commit

Permalink
up: update some git,php,json and extra commands
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 7, 2022
1 parent cf10ce9 commit a4b3354
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 17 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ kite gitlab {command} [arguments ...] [--options ...]
// remote
'mainRemote' => 'main',
'forkRemote' => 'origin',
// 分支别名
'branchAliases' => [
'h' => 'head',
]
],
```

Expand Down
5 changes: 4 additions & 1 deletion app/Console/Controller/Gitx/GitHubController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Inhere\Kite\Console\SubCmd\Gitflow\UpdatePushCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\AddCommitCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\AddCommitPushCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\GitEmojiCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\GitTagCmd;
use Inhere\Kite\Helper\AppHelper;
use Inhere\Kite\Kite;
Expand Down Expand Up @@ -60,9 +61,10 @@ protected static function commandAliases(): array
'pr' => 'pullRequest',
'redirectList' => ['rl'],
], [
GitEmojiCmd::getName() => GitEmojiCmd::aliases(),
UpdatePushCmd::getName() => UpdatePushCmd::aliases(),
UpdateNoPushCmd::getName() => UpdateNoPushCmd::aliases(),
AddCommitCmd::getName() => AddCommitCmd::aliases(),
AddCommitCmd::getName() => AddCommitCmd::aliases(),
AddCommitPushCmd::getName() => AddCommitPushCmd::aliases(),
]);
}
Expand All @@ -74,6 +76,7 @@ protected function subCommands(): array
{
return [
GitTagCmd::class,
GitEmojiCmd::class,
UpdatePushCmd::class,
UpdateNoPushCmd::class,
AddCommitCmd::class,
Expand Down
3 changes: 3 additions & 0 deletions app/Console/Controller/Gitx/GitLabController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Inhere\Kite\Console\SubCmd\GitlabCmd\ResolveConflictCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\AddCommitCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\AddCommitPushCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\GitEmojiCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\GitLogCmd;
use Inhere\Kite\Helper\AppHelper;
use Inhere\Kite\Kite;
Expand Down Expand Up @@ -80,6 +81,7 @@ protected static function commandAliases(): array
'checkout' => ['co'],
] + [
GitLogCmd::getName() => GitLogCmd::aliases(),
GitEmojiCmd::getName() => GitEmojiCmd::aliases(),
BranchCmd::getName() => BranchCmd::aliases(),
MergeRequestCmd::getName() => MergeRequestCmd::aliases(),
ResolveConflictCmd::getName() => ResolveConflictCmd::aliases(),
Expand All @@ -98,6 +100,7 @@ protected function subCommands(): array
return [
BranchCmd::class,
GitLogCmd::class,
GitEmojiCmd::class,
ProjectCmd::class,
MergeRequestCmd::class,
ResolveConflictCmd::class,
Expand Down
3 changes: 3 additions & 0 deletions app/Console/Controller/Gitx/GitxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Inhere\Kite\Console\SubCmd\BranchCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\AddCommitCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\AddCommitPushCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\GitEmojiCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\GitLogCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\GitTagCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\GitTagCreateCmd;
Expand Down Expand Up @@ -98,6 +99,7 @@ protected static function commandAliases(): array
BranchCmd::getName() => BranchCmd::aliases(),
GitTagCmd::getName() => GitTagCmd::aliases(),
GitLogCmd::getName() => GitLogCmd::aliases(),
GitEmojiCmd::getName() => GitEmojiCmd::aliases(),
AddCommitCmd::getName() => AddCommitCmd::aliases(),
AddCommitPushCmd::getName() => AddCommitPushCmd::aliases(),
];
Expand All @@ -112,6 +114,7 @@ protected function subCommands(): array
BranchCmd::class,
GitTagCmd::class,
GitLogCmd::class,
GitEmojiCmd::class,
AddCommitCmd::class,
AddCommitPushCmd::class,
];
Expand Down
30 changes: 18 additions & 12 deletions app/Console/Controller/JsonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ protected function init(): void
*/
private function getDumpfile(int $index = 0): string
{
return Kite::getTmpPath("json-load$index.json");
if ($index > 0) {
return Kite::getTmpPath("json-load$index.json");
}

return Kite::getTmpPath("json-load.json");
}

protected function jsonRender(): JSONPretty
Expand Down Expand Up @@ -172,18 +176,19 @@ public function loadCommand(FlagsParser $fs, Output $output): void
/**
* get data by path in the loaded JSON data.
*
* @options
* --type The search type. allow: keys, path
* --nc, --no-color bool;dont render color for output result.
* -s, --source The json data source, default read stdin, allow: @load, @clipboard, @stdin
* -o, --output The output, default is stdout, allow: @load, @clipboard, @stdout
* -k, --keys bool;only output all top key names for data.
* -f, --filter array;include filter by input keywords, like use grep.
* -e, --exclude array;exclude filter by input keywords.
* -m, --match, --search array;search and high line by input keywords.
*
* @arguments
* path string;The key path for search get, use `$` get all;required
*
* @options
* --type The search type. allow: keys, path
* --nc, --no-color bool;dont render color for output result.
* -s, --source The json data source, default read stdin, allow: @load, @clipboard, @stdin
* -o, --output The output, default is stdout, allow: @load, @clipboard, @stdout
* --tk, --top-keys bool;only output all top key names
* -f, --filter array;include filter by input keywords.
* -e, --exclude array;exclude filter by input keywords.
*
* @throws Throwable
* @example
* {binWithCmd} -s @l --nc -e ' 0,' -e '[]' $ # exclude contains ' 0,' '[]' lines.
Expand Down Expand Up @@ -216,14 +221,15 @@ public function getCommand(FlagsParser $fs, Output $output): void
} elseif (is_scalar($ret)) {
$str = (string)$ret;
} else {
if ($fs->getOpt('top-keys')) {
if ($fs->getOpt('keys')) {
$ret = array_keys($ret);
}

$render = $this->jsonRender()
->setNoColor($fs->getOpt('no-color'))
->setIncludes($fs->getOpt('filter'))
->setExcludes($fs->getOpt('exclude'));
->setExcludes($fs->getOpt('exclude'))
->setMatches($fs->getOpt('search'));

$str = $render->renderData($ret);
}
Expand Down
20 changes: 20 additions & 0 deletions app/Console/Controller/PhpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use function str_contains;
use function strlen;
use function trim;
use function var_export;

/**
* Class GitGroup
Expand Down Expand Up @@ -83,6 +84,25 @@ public function str2arrCommand(FlagsParser $fs, Output $output): void
$output->success('Complete');
}

/**
* convert input JSON string to PHP array.
*
* @arguments
* source The source. allow: @clipboard, @stdin
* output The output target. default is stdout.
*
* @param FlagsParser $fs
* @param Output $output
*/
public function json2arrCommand(FlagsParser $fs, Output $output): void
{
$json = ContentsAutoReader::readFrom($fs->getArg('source'), []);
$code = var_export(Json::decode($json, true), true);

$output->println($code);
$output->success('Complete');
}

/**
* convert create mysql table SQL to PHP class
*
Expand Down
51 changes: 51 additions & 0 deletions app/Console/SubCmd/GitxCmd/GitEmojiCmd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php declare(strict_types=1);

namespace Inhere\Kite\Console\SubCmd\GitxCmd;

use Inhere\Console\Command;
use Inhere\Console\Component\Symbol\GitEmoji;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\Kite\Common\CmdRunner;

/**
* class GitTagListCmd
*
* @author inhere
* @date 2022/7/12
*/
class GitEmojiCmd extends Command
{
protected static string $name = 'emoji';
protected static string $desc = 'git emoji list or search by keywords';

public static function aliases(): array
{
return ['moji', 'emj'];
}

protected function getArguments(): array
{
return [
'keywords' => 'match special emoji by keywords',
];
}

protected function execute(Input $input, Output $output)
{
$fs = $this->flags;
$ge = GitEmoji::new();

if ($kw = $fs->getArg('keywords')) {
$matched = $ge->search($kw);
if ($matched) {
$output->table($matched, "matched emojis by '$kw'");
} else {
$output->info('not found matched emojis');
}
return;
}

$output->table($ge->getEmojis());
}
}
5 changes: 4 additions & 1 deletion app/Console/SubCmd/ToolCmd/HashCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected function configure(): void
// $this->flags->addOptByRule($name, $rule);
$this->flags->addArg('str', 'want to signed string. allow: @c', 'string', true);
$this->flags->addOpt('algo', 'a', 'Name of selected hashing algorithm. eg: md5, sha256', 'string', false, 'md5');
$this->flags->addOpt('upper', 'u', 'Convert hashed value to upper case', 'bool');
// $this->flags->addOpt(
// 'key', 'k',
// 'Shared secret key used for generating the HMAC variant of the message digest.',
Expand Down Expand Up @@ -54,7 +55,9 @@ protected function execute(Input $input, Output $output)
$signStr = hash($algoName, $rawStr);
}

$signStr = strtoupper($signStr);
if ($fs->getOpt('upper')) {
$signStr = strtoupper($signStr);
}

$output->colored('SIGN:');
$output->println($signStr);
Expand Down
5 changes: 4 additions & 1 deletion app/Console/SubCmd/ToolCmd/HashHmacCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function configure(): void
// $this->flags->addOptByRule($name, $rule);
$this->flags->addArg('str', 'want to signed string. allow: @c', 'string', true);
$this->flags->addOpt('algo', 'a', 'Name of selected hashing algorithm. eg: md5, sha256', 'string', false, 'sha256');
$this->flags->addOpt('upper', 'u', 'Convert hashed value to upper case', 'bool');
$this->flags->addOpt(
'key', 'k',
'Shared secret key used for generating the HMAC variant of the message digest.',
Expand Down Expand Up @@ -53,7 +54,9 @@ protected function execute(Input $input, Output $output)
$signStr = hash_hmac($algoName, $rawStr, $secKey);
}

$signStr = strtoupper($signStr);
if ($fs->getOpt('upper')) {
$signStr = strtoupper($signStr);
}

$output->colored('SIGN:');
$output->println($signStr);
Expand Down
2 changes: 0 additions & 2 deletions config/config.cli.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use Custom\Console\Controller\JenkinsController;
use Toolkit\Stdlib\OS;

$osName = OS::name();
Expand All @@ -18,7 +17,6 @@
],
'cliControllers' => [
// some class
JenkinsController::class,
],

// --------- component object config -----------
Expand Down

0 comments on commit a4b3354

Please sign in to comment.