Skip to content

Commit 47b17b1

Browse files
committed
Improve documentation and examples
1 parent c3505ba commit 47b17b1

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

Diff for: README.md

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# clue/reactphp-shell
22

3-
[![CI status](https://github.com/clue/reactphp-shell/workflows/CI/badge.svg)](https://github.com/clue/reactphp-shell/actions)
3+
[![CI status](https://github.com/clue/reactphp-shell/actions/workflows/ci.yml/badge.svg)](https://github.com/clue/reactphp-shell/actions)
44
[![installs on Packagist](https://img.shields.io/packagist/dt/clue/shell-react?color=blue&label=installs%20on%20Packagist)](https://packagist.org/packages/clue/shell-react)
55

66
Run async commands within any interactive shell command, built on top of [ReactPHP](https://reactphp.org/).
@@ -13,57 +13,65 @@ Once [installed](#install), you can use the following code to run an interactive
1313
bash shell and issue some commands within:
1414

1515
```php
16+
<?php
17+
18+
require __DIR__ . '/vendor/autoload.php';
19+
1620
$launcher = new Clue\React\Shell\ProcessLauncher();
1721

1822
$shell = $launcher->createDeferredShell('bash');
1923

2024
$shell->execute('echo -n $USER')->then(function ($result) {
2125
var_dump('current user', $result);
26+
}, function (Exception $e) {
27+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
2228
});
2329

2430
$shell->execute('env | sort | head -n10')->then(function ($env) {
2531
var_dump('env', $env);
32+
}, function (Exception $e) {
33+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
2634
});
2735

2836
$shell->end();
2937
```
3038

31-
See also the [examples](examples):
39+
See also the [examples](examples/):
3240

3341
* [Run shell commands within a bash shell](examples/bash.php)
3442
* [Run PHP code within an interactive PHP shell](examples/php.php)
3543
* [Run shell commands within a docker container](examples/docker.php)
3644

3745
## Install
3846

39-
The recommended way to install this library is [through Composer](https://getcomposer.org).
47+
The recommended way to install this library is [through Composer](https://getcomposer.org/).
4048
[New to Composer?](https://getcomposer.org/doc/00-intro.md)
4149

4250
This will install the latest supported version:
4351

4452
```bash
45-
$ composer require clue/shell-react:^0.2
53+
composer require clue/shell-react:^0.2
4654
```
4755

4856
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
4957

5058
This project aims to run on any platform and thus does not require any PHP
5159
extensions and supports running on legacy PHP 5.3 through current PHP 8+.
52-
It's *highly recommended to use PHP 7+* for this project.
60+
It's *highly recommended to use the latest supported PHP version* for this project.
5361

5462
## Tests
5563

5664
To run the test suite, you first need to clone this repo and then install all
57-
dependencies [through Composer](https://getcomposer.org):
65+
dependencies [through Composer](https://getcomposer.org/):
5866

5967
```bash
60-
$ composer install
68+
composer install
6169
```
6270

6371
To run the test suite, go to the project root and run:
6472

6573
```bash
66-
$ php vendor/bin/phpunit
74+
vendor/bin/phpunit
6775
```
6876

6977
## License

Diff for: examples/bash.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
<?php
22

3-
use Clue\React\Shell\ProcessLauncher;
4-
53
require __DIR__ . '/../vendor/autoload.php';
64

7-
$launcher = new ProcessLauncher();
5+
$launcher = new Clue\React\Shell\ProcessLauncher();
86

97
$shell = $launcher->createDeferredShell('bash 2>&1');
108

119
$shell->execute('echo -n $USER')->then(function ($result) {
1210
var_dump('current user', $result);
11+
}, function (Exception $e) {
12+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
1313
});
1414

1515
$shell->execute('env | sort | head -n10')->then(function ($env) {
1616
var_dump('env', $env);
17+
}, function (Exception $e) {
18+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
1719
});
1820

1921
$shell->end();

Diff for: examples/docker.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
<?php
22

3-
use Clue\React\Shell\ProcessLauncher;
4-
53
require __DIR__ . '/../vendor/autoload.php';
64

7-
$launcher = new ProcessLauncher();
5+
$launcher = new Clue\React\Shell\ProcessLauncher();
86

97
$shell = $launcher->createDeferredShell('docker run -i --rm debian bash');
108

119
$shell->execute('id')->then(function ($result) {
1210
var_dump('current user', $result);
11+
}, function (Exception $e) {
12+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
1313
});
1414

1515
$shell->execute('env')->then(function ($env) {
1616
var_dump('env', $env);
17+
}, function (Exception $e) {
18+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
1719
});
1820

1921
$shell->end();

Diff for: examples/php.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?php
22

3-
use Clue\React\Shell\ProcessLauncher;
4-
53
require __DIR__ . '/../vendor/autoload.php';
64

7-
$launcher = new ProcessLauncher();
5+
$launcher = new Clue\React\Shell\ProcessLauncher();
86

97
$shell = $launcher->createDeferredShell('php -a');
108
$shell->setBounding("echo '{{ bounding }}';");

0 commit comments

Comments
 (0)