Skip to content

Commit

Permalink
update omse
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jul 31, 2020
1 parent 9afec1e commit 692ca43
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use Toolkit\Sys\Sys;

/**
* Class GitLocal
* Class GitUse
*
* @package Inhere\Kite\Common\GitLocal
*/
class GitLocal extends AbstractGitLocal
class GitUse extends AbstractGitLocal
{
/**
* Error code
Expand Down
28 changes: 21 additions & 7 deletions app/Console/Controller/GenerateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Inhere\Kite\Console\Controller;

use Inhere\Console\Controller;
use Inhere\Console\Exception\PromptException;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Toolkit\Stdlib\Str;
Expand All @@ -12,7 +13,7 @@
use function file_get_contents;
use function implode;
use function parse_ini_string;
use function str_replace;
use function strtr;
use function trim;

/**
Expand Down Expand Up @@ -106,13 +107,26 @@ public function repeatCommand(Input $input, Output $output): void
$template = trim($template);

$vars = (array)parse_ini_string(trim($varDefine), true);
foreach ($vars as $var => $valString) {
$values = Str::explode($valString, ',');
if (!isset($vars['copy'])) {
throw new PromptException('Must contains "copy" var on header define');
}

$pairs = [];
$values = Str::explode($vars['copy'], ',');
unset($vars['copy']);

// collect other vars
foreach ($vars as $var => $val) {
$tplKey = '{$' . $var . '}';

$pairs[$tplKey] = $val;
}

// repeat by values
foreach ($values as $val) {
$pairs['{$copy}'] = $val;

// repeat by values
foreach ($values as $val) {
$snippets[] = str_replace('{$' . $var . '}', $val, $template);
}
$snippets[] = strtr($template, $pairs);
}

$output->success('Complete');
Expand Down
21 changes: 21 additions & 0 deletions app/Console/Controller/GitLabController.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,26 @@ public function projectCommand(Input $input, Output $output): void
}


/**
* open gitlab project page on browser
*
* @options
* -l, --list List all project information
*
* @param Input $input
* @param Output $output
*/
public function openCommand(Input $input, Output $output): void
{
if ($input->getSameBoolOpt(['l', 'list'])) {
$output->json($this->projects);
return;
}

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


/**
* Resolve git conflicts
*
Expand Down Expand Up @@ -208,6 +228,7 @@ protected function pullRequestConfigure(Input $input): void
* -t, --target The target branch
* -o, --open Open the generated PR link on browser
* --direct The PR is from fork to main repository
* --new Open new pr page on browser http://my.gitlab.com/group/repo/merge_requests/new
*
* @argument
* project The project key in 'gitlab' config. eg: group-name, name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
use function sprintf;

/**
* Class GitLocGroup
* Class GitUseController
* - git:tag:push add tag and push to remote
* - git:tag:delete delete the tag on remote
*
*/
class GitLocController extends Controller
class GitUseController extends Controller
{
protected static $name = 'git';

Expand Down Expand Up @@ -184,7 +184,7 @@ public function tagPushCommand(Input $input, Output $output): void

$tag = GitUtil::buildNextTag($lTag);
} else {
$tag = $input->getSameOpt(['v', 'version'], '');
$tag = $input->getSameStringOpt(['v', 'version']);
if (!$tag) {
$output->error('please input new tag version, like: -v v2.0.4');
return;
Expand Down
121 changes: 121 additions & 0 deletions app/Console/Controller/GoController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php declare(strict_types=1);
/**
* This file is part of Kite.
*
* @link https://github.com/inhere
* @author https://github.com/inhere
* @license MIT
*/

namespace Inhere\Kite\Console\Controller;

use Inhere\Console\Controller;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\Kite\Common\CmdRunner;

/**
* Class GoController
* - go:fmt format go codes by go fmt
* - go:lint run go lint check
*
*/
class GoController extends Controller
{
protected static $name = 'go';

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

protected static function commandAliases(): array
{
return [
'fmt' => 'format',
'search' => 'pkgSearch',
'pkgUp' => [
'up', 'pkgup'
],
];
}

/**
* run go fmt for current directory
*
* @options
* --not-commit Dont run `git add` and `git commit` commands
*
* @arguments
* directory The directory for run go fmt
*
* @param Input $input
* @param Output $output
*
* @example
* {binWithCmd} src/rpc-client
*/
public function formatCommand(Input $input, Output $output): void
{
CmdRunner::new('go fmt ./...')->do(true);

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

/**
* Search php package from packagist.org
*
* @param Input $input
* @param Output $output
*/
public function pkgSearch(Input $input, Output $output): void
{
$output->success('TODO');
}

/**
* List all packages from of the project. from go.mod
*
* @param Input $input
* @param Output $output
*/
public function pkgListCommand(Input $input, Output $output): void
{
$filepath = $input->getWorkDir() . '/go.mod';
$content = \file_get_contents($filepath);

echo $content, "\n";

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

/**
* @param Input $input
*/
protected function pkgUpConfigure(Input $input): void
{
$input->bindArguments(['pkgName' => 0]);
}

/**
* update the package to latest by `go get -u`
*
* @arguments
* pkgName The package name. eg: gookit/rux
*
* @param Input $input
* @param Output $output
*
* @example
* {binWithCmd} gookit/rux
*/
public function pkgUpCommand(Input $input, Output $output): void
{
$pkgName = $input->getRequiredArg('pkgName');
$pkgPath = "github.com/$pkgName";

$output->aList([
'pkgName' => $pkgName,
'pkgPath' => $pkgPath,
], 'information', ['ucFirst' => false]);

CmdRunner::new('go get -u ' . $pkgPath)->do(true);
}
}
10 changes: 10 additions & 0 deletions resource/mandocs/en/go/build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# build

usage: `go build [-o output] [-i] [build flags] [packages]`

go build usage examples:

```bash
go build some/path/app.go
go build some/path/app.go -o myapp
```

0 comments on commit 692ca43

Please sign in to comment.