Add a CLI

- Super simple CLI with the ability to read from files and STDIN.
- Add [vendor binary to
`composer.json`](https://getcomposer.org/doc/articles/vendor-binaries.md).
- Add CLI usage to README.

Closes #76.
This commit is contained in:
Scott Baker 2015-01-21 00:05:24 +02:00 committed by Haralan Dobrev
parent 6ddb6b2b33
commit 1cf48bb582
3 changed files with 42 additions and 2 deletions

View File

@ -25,6 +25,19 @@ $Parsedown = new Parsedown();
echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello <em>Parsedown</em>!</p>
```
Or as a command line tool:
``` bash
# from a file
./parsedown README.md
# redirect HTML to a file:
./parsedown README.md > README.html
# or from standard input
curl https://raw.githubusercontent.com/erusev/parsedown/master/README.md | ./parsedown
```
More examples in [the wiki](https://github.com/erusev/parsedown/wiki/Usage) and in [this video tutorial](http://youtu.be/wYZBY8DEikI).
### Questions

View File

@ -14,5 +14,8 @@
],
"autoload": {
"psr-0": {"Parsedown": ""}
}
}
},
"bin": [
"parsedown"
]
}

24
parsedown Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env php
<?php
require(dirname(__FILE__).'/Parsedown.php');
// From a file
if (isset($argv[1])) {
if ( ! is_readable($argv[1])) {
throw new RuntimeException(sprintf(
'Could not read "%s"',
$argv[1]
));
}
$markdown = file_get_contents($argv[1]);
} else {
// From standard input
$markdown = file_get_contents('php://stdin');
}
$Parsedown = new Parsedown();
echo $Parsedown->text($markdown);