-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new(tool): add new command group 'tool'
- Loading branch information
Showing
4 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters