Skip to content

Commit

Permalink
new(tool): add new command group 'tool'
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 14, 2022
1 parent e84faed commit 092cffc
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
40 changes: 40 additions & 0 deletions app/Console/Command/ToolCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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\Command;

use Inhere\Console\Command;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\Kite\Console\SubCmd\OpenCmd;

/**
* Class ToolCommand
*/
class ToolCommand extends Command
{
protected static string $name = 'tool';
protected static string $desc = 'some little tool commands';

protected function subCommands(): array
{
return [
OpenCmd::class,
];
}

/**
* @param Input $input
* @param Output $output
*/
protected function execute(Input $input, Output $output)
{
$this->showHelp();
}
}
41 changes: 41 additions & 0 deletions app/Console/SubCmd/OpenCmd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php declare(strict_types=1);

namespace Inhere\Kite\Console\SubCmd;

use Inhere\Console\Command;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;

/**
* Class OpenCmd
*/
class OpenCmd extends Command
{
protected static string $name = 'open';
protected static string $desc = 'open commands';

protected function subCommands(): array
{
return [
OpenUrlCmd::class,
];
}

protected function configure(): void
{
// $this->flags->addOptByRule($name, $rule);
}

/**
* Do execute command
*
* @param Input $input
* @param Output $output
*
* @return int|mixed
*/
protected function execute(Input $input, Output $output): mixed
{
return $this->showHelp();
}
}
43 changes: 43 additions & 0 deletions app/Console/SubCmd/OpenUrlCmd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php declare(strict_types=1);

namespace Inhere\Kite\Console\SubCmd;

use Inhere\Console\Command;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\Kite\Helper\AppHelper;
use function str_starts_with;

/**
* Class ProjectInit
*/
class OpenUrlCmd extends Command
{
protected static string $name = 'url';
protected static string $desc = 'open input url on browser';

protected function configure(): void
{
// $this->flags->addOptByRule($name, $rule);
$this->flags->addArg('url', 'want opened URL address', 'string', true);
}

/**
* @param Input $input
* @param Output $output
*
* @return int|mixed
*/
protected function execute(Input $input, Output $output): mixed
{
$pageUrl = $this->flags->getArg('url');
if (!str_starts_with($pageUrl, 'http')) {
$pageUrl = 'https://' . $pageUrl;
}

$output->info("will open URL: $pageUrl");
AppHelper::openBrowser($pageUrl);

return 0;
}
}
3 changes: 2 additions & 1 deletion config/aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
// element is: alias command => real command
return [
'ac' => 'git:ac',
'acp' => 'git:acp',
'acp' => 'git acp',
'glpr' => 'gitlab:pr',
'config' => 'self config',
'webui' => 'self webui',
'add-log' => 'util log',
'open-url' => 'tool open url',
];

0 comments on commit 092cffc

Please sign in to comment.