Skip to content

Commit

Permalink
convert all flags collect to new parser
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Sep 21, 2021
1 parent f6f7fa5 commit 8377f72
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 237 deletions.
5 changes: 5 additions & 0 deletions app/Common/IdeaHttp/ClientEnvReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class ClientEnvReader
*/
private $envs = [];

/**
* @var string
*/
private $curEnv = '';

/**
* @param string $envFile
*
Expand Down
4 changes: 2 additions & 2 deletions app/Common/IdeaHttp/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function new(array $data = []): self
/**
* @param string $str
*
* @return static
* @return static|null
*/
public static function fromHTTPString(string $str): ?self
{
Expand Down Expand Up @@ -399,7 +399,7 @@ public function parseHeaderRaw(string $headerRaw): array
$nodes = Str::explode($line, ':', 2);
$name = strtolower($nodes[0]);
$value = $nodes[1] ?? '';
if ($value && strpos(';', $value) !== false) {
if ($value && strpos($value, ';') !== false) {
$headerMap[$name] = Str::explode($value, ';');
} else {
$headerMap[$name] = [$value];
Expand Down
7 changes: 1 addition & 6 deletions app/Console/Command/Json5Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,12 @@ public static function aliases(): array
return ['j5'];
}

protected function configure(): void
{
$this->input->bindArgument('json5file', 0);
}

/**
* @options
* -o, --output Output the decoded contents to the file
*
* @arguments
* json5file The script name for execute
* json5file string;The json5 file name for parse;required
*
* @param Input $input
* @param Output $output
Expand Down
1 change: 0 additions & 1 deletion app/Console/Controller/ConvertController.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,4 @@ public function ts2dateCommand(FlagsParser $fs, Output $output): void
// opts
$output->table($data, 'Time to date', []);
}

}
18 changes: 5 additions & 13 deletions app/Console/Controller/CronTabController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public function parseConfigure(Input $input): void
* @options
* -i bool;Run an interactive environment
*
* @param FlagsParser $fs
* @param Output $output
*
* @throws Exception
* @example
* {binWithCmd} 'every 6 mins' // '*\/6 * * * *'
* {binWithCmd} 'every day 10 am' // '0 10 * * *'
* {binWithCmd} 'every day 10:20 am' // '20 10 * * *'
*
* @param Input $input
* @param Output $output
*
* @throws Exception
*/
public function parseCommand(FlagsParser $fs, Output $output): void
{
Expand All @@ -74,14 +74,6 @@ public function parseCommand(FlagsParser $fs, Output $output): void
$output->aList($dateList, "Execution time for the next $nextNum times:");
}

/**
* @param Input $input
*/
public function execTimeConfigure(Input $input): void
{
$input->bindArgument('expression', 0);
}

/**
* show next execution datetime for an cron expression.
*
Expand All @@ -92,7 +84,7 @@ public function execTimeConfigure(Input $input): void
* -n, --next int;Show next number exec datetime. default number is 3.
* -p, --prev bool;Show previsions exec datetime
*
* @param Input $input
* @param FlagsParser $fs
* @param Output $output
*
* @throws Exception
Expand Down
6 changes: 2 additions & 4 deletions app/Console/Controller/DbController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ class DbController extends Controller
* -s, --source The source sql file
* -o, --output The output content file
*
* @param Input $input
* @param FlagsParser $fs
* @param Output $output
*
*/
public function sql2mdCommand(FlagsParser $fs, Output $output): void
{
Expand All @@ -51,9 +50,8 @@ public function sql2mdCommand(FlagsParser $fs, Output $output): void
* -s, --source The source markdown file
* -o, --output The output sql file
*
* @param Input $input
* @param FlagsParser $fs
* @param Output $output
*
*/
public function md2sqlCommand(FlagsParser $fs, Output $output): void
{
Expand Down
6 changes: 3 additions & 3 deletions app/Console/Controller/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected static function commandAliases(): array
* @arguments
* path The ls path
*
* @param Input $input
* @param FlagsParser $fs
*/
public function listCommand(FlagsParser $fs): void
{
Expand Down Expand Up @@ -104,7 +104,7 @@ public function lnCommand(Output $output): void
* @arguments
* file The file path
*
* @param Input $input
* @param FlagsParser $fs
* @param Output $output
*/
public function vimCommand(FlagsParser $fs, Output $output): void
Expand Down Expand Up @@ -157,7 +157,7 @@ public function renameCommand(FlagsParser $fs, Output $output): void
* --pt The progress bar type. allow: txt,bar
* -s, --save The save local file for downloaded.
*
* @param Input $input
* @param FlagsParser $fs
* @param Output $output
*/
public function downCommand(FlagsParser $fs, Output $output): void
Expand Down
64 changes: 27 additions & 37 deletions app/Console/Controller/GitController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
use Toolkit\Stdlib\Obj\ConfigObject;
use Toolkit\Stdlib\Str;
use function array_keys;
use function array_values;
use function count;
use function implode;
use function sprintf;
use function strlen;
Expand Down Expand Up @@ -110,7 +108,7 @@ protected function options(): array
protected function beforeRun(): void
{
if ($this->app && !$this->settings) {
$this->settings = ConfigObject::new($this->app->getParam('git', []));
$this->settings = ConfigObject::new($this->app->getArrayParam('git'));
}
}

Expand Down Expand Up @@ -227,7 +225,7 @@ public function statusCommand(Output $output): void
* display git information for the project
*
* @options
* --show-commands bool;Show exec git commands
* --show-commands bool;Show exec git commands
*
* @param FlagsParser $fs
* @param Output $output
Expand All @@ -242,46 +240,38 @@ public function infoCommand(FlagsParser $fs, Output $output): void
]);
}

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

/**
* list branch by git branch
*
* @options
* -a, --all Display all branches
* -r, --remote <string> Display given remote branches
* --only-name Only display branch name
* --inline Only display branch name and print inline
* -s, --search <string> The keyword name for search branches
* -a, --all bool;Display all branches
* -r, --remote Display branches for the given remote
* --only-name bool;Only display branch name
* --inline bool;Only display branch name and print inline
* -s, --search The keyword name for search branches
*
* @arguments
*
* @param Input $input
* @param FlagsParser $fs
* @param Output $output
*/
public function branchCommand(Input $input, Output $output): void
public function branchCommand(FlagsParser $fs, Output $output): void
{
$opts = [];
$repo = Repo::new();

$remote = '';
$inline = $input->getBoolOpt('inline');
if ($input->getSameBoolOpt('a, all')) {
$inline = $fs->getOpt('inline');
if ($fs->getOpt('all')) {
$opts['all'] = true;
} elseif ($remote = $input->getSameStringOpt('r,remote')) {
} elseif ($remote = $fs->getOpt('remote')) {
$opts['remotes'] = true;
}

$list = $repo->getGit()->branch->getList($opts);

$onlyName = $input->getBoolOpt('only-name');
$keyword = $input->getSameStringOpt('s,search');
$onlyName = $fs->getOpt('only-name');
$keyword = $fs->getOpt('search');

$msg = 'Branch List';
if (strlen($remote) > 1) {
Expand Down Expand Up @@ -388,7 +378,7 @@ public function openCommand(FlagsParser $fs, Output $output): void
* Clone an remote git repository to local
*
* @options
* --gh Define the remote repository is on github
* --gh bool;Define the remote repository is on github
*
* @arguments
* repo The remote git repo URL or repository name
Expand All @@ -411,9 +401,9 @@ public function cloneCommand(FlagsParser $fs, Output $output): void
* get the latest/next git tag from the project directory
*
* @options
* -d, --dir The project directory path. default is current directory.
* --next-tag bool;Display the project next tag version. eg: v2.0.2 => v2.0.3
* --only-tag bool;Only output tag information
* -d, --dir The project directory path. default is current directory.
* --next-tag bool;Display the project next tag version. eg: v2.0.2 => v2.0.3
* --only-tag bool;Only output tag information
*
* @param FlagsParser $fs
* @param Input $input
Expand Down Expand Up @@ -580,7 +570,7 @@ public function tagNewCommand(FlagsParser $fs, Input $input, Output $output): vo
* -v, --tag The tag version. eg: v2.0.3
* --no-remote bool;Only delete local tag
*
* @param Input $input
* @param FlagsParser $fs
* @param Output $output
*/
public function tagDeleteCommand(FlagsParser $fs, Output $output): void
Expand Down Expand Up @@ -761,11 +751,11 @@ public function logCommand(FlagsParser $fs, Output $output): void
* collect git change log information by `git log`
*
* @arguments
* oldVersion string;The old version. eg: v1.0.2
* - keywords `last/latest` will auto use latest tag.
* - keywords `prev/previous` will auto use previous tag.;required
* newVersion string;The new version. eg: v1.2.3
* - keywords `head` will use `Head` commit.;required
* oldVersion string;The old version. eg: v1.0.2
* - keywords `last/latest` will auto use latest tag.
* - keywords `prev/previous` will auto use previous tag.;required
* newVersion string;The new version. eg: v1.2.3
* - keywords `head` will use `Head` commit.;required
*
* @options
* --exclude Exclude contains given sub-string. multi by comma split.
Expand All @@ -791,9 +781,9 @@ public function logCommand(FlagsParser $fs, Output $output): void
* @param Output $output
*
* @example
* {binWithCmd} last head
* {binWithCmd} last head --style gh-release --no-merges
* {binWithCmd} v2.0.9 v2.0.10 --no-merges --style gh-release --exclude "cs-fixer,format codes"
* {binWithCmd} last head
* {binWithCmd} last head --style gh-release --no-merges
* {binWithCmd} v2.0.9 v2.0.10 --no-merges --style gh-release --exclude "cs-fixer,format codes"
*/
public function changelogCommand(FlagsParser $fs, Output $output): void
{
Expand Down
Loading

0 comments on commit 8377f72

Please sign in to comment.