Skip to content

Commit

Permalink
Add README
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Sep 8, 2018
1 parent 43ac0fc commit b5f89bc
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Command line interface builder.
===============================

Create multi-command terminal application with parameter requirements that are self-documenting and easy to unit test.

***

<a href="https://circleci.com/gh/PhpGt/Cli" target="_blank">
<img src="https://badge.status.php.gt/cli-build.svg" alt="Build status" />
</a>
<a href="https://scrutinizer-ci.com/g/PhpGt/Cli" target="_blank">
<img src="https://badge.status.php.gt/cli-quality.svg" alt="Code quality" />
</a>
<a href="https://scrutinizer-ci.com/g/PhpGt/Cli" target="_blank">
<img src="https://badge.status.php.gt/cli-coverage.svg" alt="Code coverage" />
</a>
<a href="https://packagist.org/packages/PhpGt/Cli" target="_blank">
<img src="https://badge.status.php.gt/cli-version.svg" alt="Current version" />
</a>
<a href="https://www.php.gt/cli" target="_blank">
<img src="https://badge.status.php.gt/cli-docs.svg" alt="PHP.G/Cli documentation" />
</a>

## Example usage: Twitter client

CLI interaction:

```bash
$ 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!"
$ 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:`

```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`

```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
);
}
}
}
```

0 comments on commit b5f89bc

Please sign in to comment.