Skip to content

Commit

Permalink
Merge pull request #20 from WebFiori/dev
Browse files Browse the repository at this point in the history
Updated Docs + Sample App
  • Loading branch information
usernane authored Dec 3, 2023
2 parents 568c19d + 4957a39 commit 2a5adce
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 20 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/php83.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Build PHP 8.3

on:
push:
branches: [ main, dev ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ${{ matrix.os }}
services:
sql.data:
image: mcr.microsoft.com/mssql/server:2019-latest
env:
SA_PASSWORD: 1234567890@Eu
ACCEPT_EULA: Y
MSSQL_PID: Express
ports:
- "1433:1433"
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [8.3]

name: PHP${{matrix.php}} - ${{matrix.os}}

steps:
- name: Clone Repo
uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mysqli, mbstring, sqlsrv
tools: phpunit:9.5.20, composer

- name: Shutdown Ubuntu MySQL
run: sudo service mysql stop

- name: Set up MySQL
uses: mirromutth/[email protected]
with:
mysql version: '5.7'
mysql database: 'testing_db'
mysql root password: 123456
mysql user: 'root'
mysql password: 123456

- name: Wait for MySQL
run: |
while ! mysqladmin ping --host=127.0.0.1 --password=123456 --silent; do
sleep 1
done
- name: Setup MSSQL
run: sqlcmd -S localhost -U SA -P 1234567890@Eu -Q 'create database testing_db'

- name: Install Dependencies
run: composer install --prefer-dist --no-interaction --no-dev

- name: Execute Tests
run: phpunit

- name: CodeCov
uses: codecov/codecov-action@v1
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# WebFiori CLI
Class library that can help in writing command line based applications using PHP.
Class library that can help in writing command line based applications with minimum dependencies using PHP.


<p align="center">
<a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php82.yml">
<img src="https://github.com/WebFiori/cli/workflows/Build%20PHP%208.2/badge.svg?branch=main">
<a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php83.yml">
<img src="https://github.com/WebFiori/cli/actions/workflows/php83.yml/badge.svg?branch=main">
</a>
<a href="https://codecov.io/gh/WebFiori/cli">
<img src="https://codecov.io/gh/WebFiori/cli/branch/main/graph/badge.svg" />
Expand Down Expand Up @@ -42,15 +42,15 @@ Class library that can help in writing command line based applications using PHP
## Supported PHP Versions
| Build Status |
|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php70.yml"><img src="https://github.com/WebFiori/cli/workflows/Build%20PHP%207.0/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php71.yml"><img src="https://github.com/WebFiori/cli/workflows/Build%20PHP%207.1/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php72.yml"><img src="https://github.com/WebFiori/cli/workflows/Build%20PHP%207.2/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php73.yml"><img src="https://github.com/WebFiori/cli/workflows/Build%20PHP%207.3/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php74.yml"><img src="https://github.com/WebFiori/cli/workflows/Build%20PHP%207.4/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php80.yml"><img src="https://github.com/WebFiori/cli/workflows/Build%20PHP%208.0/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php81.yml"><img src="https://github.com/WebFiori/cli/workflows/Build%20PHP%208.1/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php82.yml"><img src="https://github.com/WebFiori/cli/workflows/Build%20PHP%208.2/badge.svg?branch=main"></a> |

| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php70.yml"><img src="https://github.com/WebFiori/cli/actions/workflows/php70.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php71.yml"><img src="https://github.com/WebFiori/cli/actions/workflows/php71.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php72.yml"><img src="https://github.com/WebFiori/cli/actions/workflows/php72.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php73.yml"><img src="https://github.com/WebFiori/cli/actions/workflows/php73.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php74.yml"><img src="https://github.com/WebFiori/cli/actions/workflows/php74.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php80.yml"><img src="https://github.com/WebFiori/cli/actions/workflows/php80.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php81.yml"><img src="https://github.com/WebFiori/cli/actions/workflows/php81.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php82.yml"><img src="https://github.com/WebFiori/cli/actions/workflows/php82.yml/badge.svg?branch=main"></a> |
| <a target="_blank" href="https://github.com/WebFiori/cli/actions/workflows/php83.yml"><img src="https://github.com/WebFiori/cli/actions/workflows/php83.yml/badge.svg?branch=main"></a> |


## Features
Expand All @@ -73,7 +73,7 @@ To install the library, simply include it in your `composer.json`'s `require` se
### Creating a Command


First step in creating new command is to create a new class that extends the class `CLICommand`. The class `CLICommand` is a utility class which has methods which can be used to read inputs, send outputs and use command line arguments.
First step in creating new command is to create a new class that extends the class `webfiori\cli\CLICommand`. The class `CLICommand` is a utility class which has methods that can be used to read inputs, send outputs and use command line arguments.

The class has one abstract method that must be implemented. The code that will exist in the body of the method will represent the logic of the command.

Expand All @@ -98,7 +98,7 @@ class SampleCommand extends CLICommand {

### Running a Command

The class `Runner` is the class which is used to manage the logic of executing the commands. In order to run a command, an instance of this class must be created and used to register the command and start running the application.
The class `webfiori\cli\Runner` is the class which is used to manage the logic of executing the commands. In order to run a command, an instance of this class must be created and used to register the command and start running the application.

To register a command, the method `Runner::register()` is used. To start the application, the method `Runner::start()` is used.

Expand All @@ -112,7 +112,7 @@ use SampleCommand;

$runner = new Runner();
$runner->register(new SampleCommand());
$runner->start();
exit($runner->start());
```

Now if terminal is opened and following command is executed:
Expand Down Expand Up @@ -154,7 +154,7 @@ class SampleCommand extends CLICommand {

```

Arguments provided as an associative array. Index is name of the argument and the value of the index is sub-associative array of options. Each argument can have the following options:
Arguments can be provided as an associative array or array of objects of type `webfiori\cli\CommandArgument`. In case of associative array, Index is name of the argument and the value of the index is sub-associative array of options. Each argument can have the following options:
* `optional`: A boolean. if set to true, it means that the argument is optional. Default is false.
* `default`: An optional default value for the argument to use if it is not provided.
* `description`: A description of the argument which will be shown if the command `help` is executed.
Expand Down Expand Up @@ -217,7 +217,7 @@ One of the commands which comes by default with the library is the `help` comman
### Setting Help Instructions

Help instructions are provided by the developer who created the command during its implementation. Instructions can be set on the constructor of the class that extends the class `CLICommand` as a description. The description can be set for the command and its arguments.
Help instructions are provided by the developer who created the command during its implementation. Instructions can be set on the constructor of the class that extends the class `webfiori\cli\CLICommand` as a description. The description can be set for the command and its arguments.

``` php
<?php
Expand Down Expand Up @@ -269,7 +269,7 @@ Output of this command will be as follows:
Usage:
command [arg1 arg2="val" arg3...]
Global Arguments:[0m[k
Global Arguments:
--ansi:[Optional] Force the use of ANSI output.
Available Commands:
help: Display CLI Help. To display help for specific command, use the argument "--command-name" with this command.
Expand Down Expand Up @@ -300,7 +300,7 @@ hello: A command to show greetings.
## Unit-Testing Commands

Testing commands using the library is very simple. In any test case, developer must follow following steps to prepare a test case:
* Create new instance of the class `Runner`.
* Create new instance of the class `webfiori\cli\Runner`.
* Register the command that will be tested using the method `Runner::register()`.
* Set arguments vector using the method `Runner::setArgsVector()`.
* Set user inputs using the method `Runner::setInputs()`.
Expand Down
4 changes: 4 additions & 0 deletions example/app/app
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env php
<?php
require "app.php";

5 changes: 4 additions & 1 deletion example/app/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
use webfiori\cli\Runner;

$runner = new Runner();

$runner->register(new HelpCommand());
$runner->register(new HelloWorldCommand());
$runner->register(new OpenFileCommand());
$runner->start();
$runner->setDefaultCommand('help');

exit($runner->start());

0 comments on commit 2a5adce

Please sign in to comment.