generated from inherelab/php-pkg-template
-
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.
feat: support add CmdHandler class to CliApp
- Loading branch information
Showing
10 changed files
with
128 additions
and
14 deletions.
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
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
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
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
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,34 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Toolkit\PFlag\Contract; | ||
|
||
use Toolkit\PFlag\CliApp; | ||
use Toolkit\PFlag\FlagsParser; | ||
|
||
/** | ||
* interface CmdHandlerInterface | ||
* | ||
* @author inhere | ||
*/ | ||
interface CmdHandlerInterface | ||
{ | ||
/** | ||
* @return array{name:string, desc: string, example:string, help: string} | ||
*/ | ||
public function metadata(): array; | ||
|
||
/** | ||
* @param FlagsParser $fs | ||
* | ||
* @return void | ||
*/ | ||
public function configure(FlagsParser $fs): void; | ||
|
||
/** | ||
* @param FlagsParser $fs | ||
* @param CliApp $app | ||
* | ||
* @return mixed | ||
*/ | ||
public function execute(FlagsParser $fs, CliApp $app): mixed; | ||
} |
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,51 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Toolkit\PFlagTest\Cases; | ||
|
||
use Toolkit\PFlag\CliApp; | ||
use Toolkit\PFlag\Contract\CmdHandlerInterface; | ||
use Toolkit\PFlag\FlagsParser; | ||
use function vdump; | ||
|
||
/** | ||
* class DemoCmdHandler | ||
* | ||
* @author inhere | ||
*/ | ||
class DemoCmdHandler implements CmdHandlerInterface | ||
{ | ||
/** | ||
* @return array{name:string, desc: string, example:string, help: string} | ||
*/ | ||
public function metadata(): array | ||
{ | ||
return [ | ||
'name' => 'demo', | ||
'desc' => 'desc for demo command handler', | ||
]; | ||
} | ||
|
||
/** | ||
* @param FlagsParser $fs | ||
* | ||
* @return void | ||
*/ | ||
public function configure(FlagsParser $fs): void | ||
{ | ||
$fs->addOptsByRules([ | ||
'opt1' => 'string;a string opt1 for command test2, and is required;true', | ||
'opt2' => 'int;a int opt2 for command test2', | ||
]); | ||
} | ||
|
||
/** | ||
* @param FlagsParser $fs | ||
* @param CliApp $app | ||
* | ||
* @return mixed | ||
*/ | ||
public function execute(FlagsParser $fs, CliApp $app): mixed | ||
{ | ||
vdump(__METHOD__); | ||
} | ||
} |
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
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
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
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