-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved STDIN support, added examples
- Loading branch information
Showing
5 changed files
with
109 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
use kamermans\Command\Command; | ||
|
||
require_once __DIR__.'/../vendor/autoload.php'; | ||
|
||
echo "Type some words, one per line, then press CTRL-D and they will be sorted:\n"; | ||
|
||
$cmd = Command::factory("sort") | ||
// This causes Command to use the real STDIN | ||
->run(STDIN); | ||
|
||
echo "\n"; | ||
echo $cmd->getStdOut(); |
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,18 @@ | ||
<?php | ||
|
||
use kamermans\Command\Command; | ||
|
||
require_once __DIR__.'/../vendor/autoload.php'; | ||
|
||
$filename = __DIR__.'/../README.md'; | ||
$stdin = fopen($filename, 'r'); | ||
|
||
// This will count the number of words in the README.md file | ||
$cmd = Command::factory("wc") | ||
->option("--words") | ||
->run($stdin); | ||
|
||
fclose($stdin); | ||
|
||
$words = trim($cmd->getStdOut()); | ||
echo "File $filename contains $words words\n"; |
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,12 @@ | ||
<?php | ||
|
||
use kamermans\Command\Command; | ||
|
||
require_once __DIR__.'/../vendor/autoload.php'; | ||
|
||
$stdin = "banana\norange\napple\npear\n"; | ||
|
||
$cmd = Command::factory("sort") | ||
->run($stdin); | ||
|
||
echo $cmd->getStdOut(); |
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