Skip to content

Commit

Permalink
up: update the git log command to alone class
Browse files Browse the repository at this point in the history
- update readme
  • Loading branch information
inhere committed Nov 5, 2022
1 parent b5db10a commit ccdba0a
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 52 deletions.
4 changes: 2 additions & 2 deletions README.en.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Kite

[![License](https://img.shields.io/packagist/l/inhere/console.svg?style=flat-square)](LICENSE)
[![Php Version](https://img.shields.io/badge/php-%3E=8.0.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/inhere/console)
[![Php Version](https://img.shields.io/badge/php-%3E=8.1.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/inhere/console)
[![zh-CN readme](https://img.shields.io/badge/中文-Readme-brightgreen.svg?maxAge=2592000)](README.md)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/inhere/kite)](https://github.com/inhere/kite)
[![Actions Status](https://github.com/inhere/kite/workflows/Unit-Tests/badge.svg)](https://github.com/inhere/kite/actions)
Expand All @@ -18,7 +18,7 @@ Kite is a tool for help development.
**Required:**

- git
- php 8.0+
- php 8.1+
- composer

### Install by script
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Kite

[![License](https://img.shields.io/packagist/l/inhere/console.svg?style=flat-square)](LICENSE)
[![Php Version](https://img.shields.io/badge/php-%3E=8.0.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/inhere/console)
[![Php Version](https://img.shields.io/badge/php-%3E=8.1.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/inhere/console)
[![English](https://img.shields.io/badge/English-Readme-brightgreen.svg?maxAge=2592000)](README.en.md)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/inhere/kite)](https://github.com/inhere/kite)
[![Actions Status](https://github.com/inhere/kite/workflows/Unit-Tests/badge.svg)](https://github.com/inhere/kite/actions)
Expand All @@ -17,10 +17,10 @@ PHP编写的,方便本地开发和使用的个人CLI工具应用。
**系统环境依赖**

- git
- php 8.0+
- php 8.1+
- composer

> TIP: 支持windows 10
> TIP: 支持windows 10, linux, macOS
**脚本安装(推荐)**

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 @@ -28,6 +28,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\GitLogCmd;
use Inhere\Kite\Helper\AppHelper;
use Inhere\Kite\Kite;
use Throwable;
Expand Down Expand Up @@ -82,6 +83,7 @@ protected static function commandAliases(): array
'project' => ['pj', 'info'],
'checkout' => ['co'],
] + [
GitLogCmd::getName() => GitLogCmd::aliases(),
BranchCmd::getName() => BranchCmd::aliases(),
MergeRequestCmd::getName() => MergeRequestCmd::aliases(),
ResolveConflictCmd::getName() => ResolveConflictCmd::aliases(),
Expand All @@ -99,6 +101,7 @@ protected function subCommands(): array
{
return [
BranchCmd::class,
GitLogCmd::class,
ProjectCmd::class,
MergeRequestCmd::class,
ResolveConflictCmd::class,
Expand Down
50 changes: 4 additions & 46 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\GitLogCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\GitTagCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\GitTagCreateCmd;
use Inhere\Kite\Console\SubCmd\GitxCmd\GitTagDelCmd;
Expand All @@ -42,7 +43,6 @@
use Toolkit\Stdlib\Obj\DataObject;
use Toolkit\Stdlib\Str;
use Toolkit\Sys\Proc\ProcTasks;
use function abs;
use function realpath;
use function strtolower;

Expand All @@ -69,7 +69,6 @@ protected static function commandAliases(): array
{
return [
'changelog' => ['chlog', 'clog', 'cl'],
'log' => ['l', 'lg'],
'tagDelete' => [
'tag-del',
'tagdel',
Expand Down Expand Up @@ -97,6 +96,8 @@ protected static function commandAliases(): array
'tagInfo' => ['tag-info', 'ti', 'tag-show'],
] + [
BranchCmd::getName() => BranchCmd::aliases(),
GitTagCmd::getName() => GitTagCmd::aliases(),
GitLogCmd::getName() => GitLogCmd::aliases(),
AddCommitCmd::getName() => AddCommitCmd::aliases(),
AddCommitPushCmd::getName() => AddCommitPushCmd::aliases(),
];
Expand All @@ -110,6 +111,7 @@ protected function subCommands(): array
return [
BranchCmd::class,
GitTagCmd::class,
GitLogCmd::class,
AddCommitCmd::class,
AddCommitPushCmd::class,
];
Expand Down Expand Up @@ -490,50 +492,6 @@ public function tagDeleteCommand(FlagsParser $fs, Output $output): void
$cmd->run($fs->getFlags());
}

/**
* display recently git commits information by `git log`
*
* @arguments
* maxCommit int;Max display how many commits;;15
*
* @options
* --ac, --abbrev-commit bool;Only display the abbrev commit ID
* --exclude Exclude contains given sub-string. multi by comma split.
* --file Export changelog message to file
* --format The git log option `--pretty` value.
* can be one of oneline, short, medium, full, fuller, reference, email, raw, format:<string> and tformat:<string>.
* --mc, --max-commit int;Max display how many commits
* --nc, --no-color bool;Dont use color render git output
* --nm, --no-merges bool;No contains merge request logs
*
* @param FlagsParser $fs
* @param Output $output
*/
public function logCommand(FlagsParser $fs, Output $output): void
{
$b = Git::new()->newCmd('log');

$noColor = $fs->getOpt('no-color');
$exclude = $fs->getOpt('exclude');

$noMerges = $fs->getOpt('no-merges');
$abbrevID = $fs->getOpt('abbrev-commit');
$maxCommit = $fs->getOpt('max-commit', $fs->getArg('maxCommit'));

// git log --color --graph --pretty=format:'%Cred%h%Creset:%C(ul yellow)%d%Creset %s (%Cgreen%cr%Creset, %C(bold blue)%an%Creset)' --abbrev-commit -10
$b->add('--graph');
$b->addIf('--color', !$noColor);
$b->add('--pretty=format:"%Cred%h%Creset:%C(ul yellow)%d%Creset %s (%Cgreen%cr%Creset, %C(bold blue)%an%Creset)"');
$b->addIf("--exclude=$exclude", $exclude);
$b->addIf('--abbrev-commit', $abbrevID);
$b->addIf('--no-merges', $noMerges);
$b->add('-' . abs($maxCommit));

$b->runAndPrint();

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

/**
* collect git change log information by `git log`
*
Expand Down
83 changes: 83 additions & 0 deletions app/Console/SubCmd/GitxCmd/GitLogCmd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php declare(strict_types=1);

namespace Inhere\Kite\Console\SubCmd\GitxCmd;

use Inhere\Console\Command;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use PhpGit\Git;
use function abs;
use function date;

/**
* class GitLogCmd
*
* @author inhere
* @date 2022/7/12
*/
class GitLogCmd extends Command
{
protected static string $name = 'log';
protected static string $desc = 'display recently git commits information by `git log`';

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

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


/**
* display recently git commits information by `git log`
*
* @arguments
* maxCommit int;Max display how many commits;;15
*
* @options
* --ac, --abbrev-commit bool;Only display the abbrev commit ID
* --exclude Exclude contains given sub-string. multi by comma split.
* --file Export changelog message to file
* --format The git log option `--pretty` value.
* can be one of oneline, short, medium, full, fuller, reference, email, raw, format:<string> and tformat:<string>.
* --mc, --max-commit int;Max display how many commits
* --nc, --no-color bool;Dont use color render git output
* --nm, --no-merges bool;No contains merge request logs
*
* @param Input $input
* @param Output $output
*
* @return void
*/
protected function execute(Input $input, Output $output)
{
$fs = $this->flags;

$noColor = $fs->getOpt('no-color');
$exclude = $fs->getOpt('exclude');

$noMerges = $fs->getOpt('no-merges');
$abbrevID = $fs->getOpt('abbrev-commit');
$maxCommit = $fs->getOpt('max-commit', $fs->getArg('maxCommit'));

$b = Git::new()->log->builder();

// git log --color --graph --pretty=format:'%Cred%h%Creset:%C(ul yellow)%d%Creset %s (%Cgreen%cr%Creset, %C(bold blue)%an%Creset)' --abbrev-commit -10
$b->add('--graph');
$b->addIf('--color', !$noColor);
$b->add('--pretty=format:"%Cred%h%Creset:%C(ul yellow)%d%Creset %s (%Cgreen%cr%Creset, %C(bold blue)%an%Creset)"');
$b->addIf("--exclude=$exclude", $exclude);
$b->addIf('--abbrev-commit', $abbrevID);
$b->addIf('--no-merges', $noMerges);
$b->add('-' . abs($maxCommit));

$b->runAndPrint();

$output->success('Complete at ' . date('Y-m-d H:i:s'));
}
}
5 changes: 5 additions & 0 deletions app/Console/SubCmd/GitxCmd/GitTagCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class GitTagCmd extends Command
protected static string $name = 'tag';
protected static string $desc = 'git tag manage tool command. eg: list, add, del';

public static function aliases(): array
{
return ['tg'];
}

protected function subCommands(): array
{
return [
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": ">=8.0.1",
"php": ">=8.1.0",
"ext-json": "*",
"ext-mbstring": "*",
"inhere/console": "dev-master",
Expand Down

0 comments on commit ccdba0a

Please sign in to comment.