https://github.com/bpolaszek/simple-cli
A lightweight CLI helper, with almost no dependency.
https://github.com/bpolaszek/simple-cli
Last synced: 11 months ago
JSON representation
A lightweight CLI helper, with almost no dependency.
- Host: GitHub
- URL: https://github.com/bpolaszek/simple-cli
- Owner: bpolaszek
- Created: 2020-01-27T16:12:09.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-09T15:38:06.000Z (almost 6 years ago)
- Last Synced: 2025-01-10T09:59:28.940Z (about 1 year ago)
- Language: PHP
- Size: 4.88 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple CLI
Command-line helper functions, with almost no dependencies, to help you build console scripts quickly.
It is not intended to be a full-featured CLI framework, but rather to help you grab arguments / options that were passed to your script, display some text, and prompt for user input.
## Installation
```bash
composer require bentools/simple-cli:0.2.*
```
## Usage
```php
# php thatscript.php --file=some-file foobar
require_once __DIR__ . '/vendor/autoload.php';
use function BenTools\SimpleCli\cli;
use function BenTools\SimpleCli\getOption;
use function BenTools\SimpleCli\getArgument;
use function BenTools\SimpleCli\writeLn;
use function BenTools\SimpleCli\text;
use function BenTools\SimpleCli\ask;
use function BenTools\SimpleCli\askHidden;
use function BenTools\SimpleCli\confirm;
use function BenTools\SimpleCli\error;
use function BenTools\SimpleCli\success;
getOption('file'); // some-file
getArgument(0); // foobar
writeLn(text('Hey there!')->yellow());
$user = ask('What is your username?', $default = 'anonymous');
$password = askHidden('Enter your password');
if ('123456' === $password && confirm('Really?')) {
error('Nope nope nope!', $exit = true);
}
success('Done!');
```
## License
MIT.