phpgt / cli
Command line interface builder.
Fund package maintenance!
PhpGt
Installs: 7 923
Dependents: 7
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 1
Open Issues: 17
Requires
- php: >=8.2
- ext-json: *
- ext-readline: *
- phpgt/daemon: ^1.1.3
Requires (Dev)
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.7
- dev-master
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.2
- v1.0.1
- v1.0.0
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.0
- v0.1.1
- v0.1.0
- v0.0.3
- v0.0.2
- v0.0.1
- dev-242-repeating
- dev-dependabot/composer/phpstan/phpstan-1.10.6
- dev-dependabot/composer/phpunit/phpunit-9.6.5
- dev-2-version
- dev-circleci
- dev-special-command-flags
- dev-17-argument-value
This package is auto-updated.
Last update: 2024-11-15 11:31:29 UTC
README
Create multi-command terminal application with parameter requirements that are self-documenting and easy to unit test.
Example usage: Twitter client
CLI interaction:
$ twitter tweet --message "Sending a test Tweet from the terminal." Sent! View online: https://twitter.com/g105b/status/1038509073346510849 $ twitter dm --to @g105b --message "Hello, Greg!" Sent! $ twitter help Twitter example application Available commands: • tweet Send a Tweet to your timeline. • view View your timeline • follow Follow an account • dm Send a direct message. • login Authenticate your username. • help Show this help screen.
twitter.php:
$app = new Application( "Twitter example application", new CliArgumentList(...$argv), new TweetCommand(), new ViewCommand(), new FollowCommand(), new DmCommand(), new LoginCommand() ); $app->run();
Command/tweet.php
class TweetCommand extends Command { public function __construct() { $this->setName("tweet"); $this->setDescription("Send a Tweet to your timeline."); $this->setRequiredParameter(true, "message", "m"); $this->setOptionalParameter(true, "location", "l"); } public function run(ArgumentValueList $arguments):void { if(!TwitterApi::isLoggedIn()) { $this->writeLine("You must login first.", Stream::ERROR); } try { $uri = TwitterApi::sendTweet($arguments->get("message")); $this->writeLine("Sent! View online: $uri"); } catch(TwitterApiException $exception) { $this->writeLine( "Error sending Tweet: " . $exception->getMessage(), Stream::ERROR ); } } }