|
1 |
| -# minicli |
| 1 | +# Minicli Application Template |
2 | 2 |
|
3 |
| -[Minicli](https://github.com/minicli/minicli) is an experimental dependency-free toolkit for building CLI-only applications in PHP created by @erikaheidi. |
4 |
| -This repository is a template you can use to create a new application that has a single dependency: `minicli/minicli`. |
| 3 | +This repository is an application template for building command-line applications in PHP with [Minicli](https://github.com/minicli/minicli). |
5 | 4 |
|
6 |
| -### Why minicli |
7 |
| - |
8 |
| -The current trend in software development is basing your project on a big pile of unknowns. There is nothing wrong in using third party software, but if more than 80% of your application is out of your control, things can get messy. |
9 |
| -What usually happens is that you don't even know what packages you're depending on, when using the most popular frameworks. |
10 |
| - |
11 |
| -Minicli was created as [an educational experiment](https://dev.to/erikaheidi/bootstrapping-a-cli-php-application-in-vanilla-php-4ee) and a way to go dependency-free when building simple command-line applications in PHP. It can be used for microservices, personal dev tools, bots and little fun things. |
12 |
| - |
13 |
| - |
14 |
| -## Getting Started |
15 |
| - |
16 |
| -You'll need `php-cli` and [Composer](https://getcomposer.org/) to get started. |
17 |
| - |
18 |
| -Create a new project with: |
19 |
| - |
20 |
| -```bash |
21 |
| -composer create-project --prefer-dist minicli/application myapp |
22 |
| -``` |
23 |
| - |
24 |
| -Once the installation is finished, you can run `minicli` it with: |
25 |
| - |
26 |
| -```bash |
27 |
| -cd myapp |
28 |
| -./minicli |
29 |
| -``` |
30 |
| -If that doesn't work for you, you may have to use instead: |
31 |
| - |
32 |
| -```bash |
33 |
| -php minicli |
34 |
| -``` |
35 |
| -This will show you the default app signature: |
36 |
| - |
37 |
| -```bash |
38 |
| -usage: ./minicli help |
39 |
| -``` |
40 |
| - |
41 |
| -The default `help` command that comes with minicli (`app/Command/Help/DefaultController.php`) auto-generates a tree of available commands: |
42 |
| - |
43 |
| -```bash |
44 |
| -./minicli help |
45 |
| -``` |
46 |
| - |
47 |
| -```bash |
48 |
| -Available Commands |
49 |
| - |
50 |
| -help |
51 |
| -└──test |
52 |
| - |
53 |
| -``` |
54 |
| - |
55 |
| -The `help test` command, defined in `app/Command/Help/TestController.php`, shows an echo test of parameters: |
56 |
| - |
57 |
| -```bash |
58 |
| -./minicli help test user=erika name=value |
59 |
| -``` |
60 |
| - |
61 |
| -```bash |
62 |
| -Hello, erika! |
63 |
| - |
64 |
| -Array |
65 |
| -( |
66 |
| - [user] => erika |
67 |
| - [name] => value |
68 |
| -) |
69 |
| -``` |
70 |
| - |
71 |
| -### The simplest app |
72 |
| - |
73 |
| -The simplest minicli script doesn't require using Command Controllers at all. You can delete the `app` folder and use `registerCommand` with an anonymous function, like this: |
74 |
| - |
75 |
| -```php |
76 |
| -#!/usr/bin/php |
77 |
| -<?php |
78 |
| - |
79 |
| -if (php_sapi_name() !== 'cli') { |
80 |
| - exit; |
81 |
| -} |
82 |
| - |
83 |
| -require __DIR__ . '/vendor/autoload.php'; |
84 |
| - |
85 |
| -use Minicli\App; |
86 |
| -use Minicli\Command\CommandCall; |
87 |
| - |
88 |
| -$app = new App(); |
89 |
| -$app->setSignature('./minicli mycommand'); |
90 |
| - |
91 |
| -$app->registerCommand('mycommand', function(CommandCall $input) { |
92 |
| - echo "My Command!"; |
93 |
| - |
94 |
| - var_dump($input); |
95 |
| -}); |
96 |
| - |
97 |
| -$app->runCommand($argv); |
98 |
| -``` |
99 |
| - |
100 |
| -## Tests |
101 |
| -To keep dependencies to a minimum, the `minicli/application` template repository doesn't require any specific testing framework, but we highly recommend using [PestPHP](https://pestphp.com), which is the testing framework used by [minicli/minicli](https://github.com/minicli/minicli). |
102 |
| - |
103 |
| -### Bootstrapping Tests with PestPHP |
104 |
| - |
105 |
| -To get started with PestPHP to test your Minicli application, first include the required dependencies with: |
106 |
| - |
107 |
| -```bash |
108 |
| -composer require pestphp/pest --dev --with-all-dependencies |
109 |
| -``` |
110 |
| - |
111 |
| -Then, run the following command to create a tests folder and a couple example tests: |
112 |
| - |
113 |
| -```bash |
114 |
| -./vendor/bin/pest --init |
115 |
| -``` |
116 |
| - |
117 |
| -Then you can use the following command to run the test suite: |
118 |
| - |
119 |
| -```bash |
120 |
| -./vendor/bin/pest |
121 |
| -``` |
122 |
| - |
123 |
| -For more details on how to test your application with PestPHP, please refer to the [official documentation](https://pestphp.com/docs/writing-tests). |
| 5 | +Please check [the official documentation](https://docs.minicli.dev) for more information on how to use this application template. |
0 commit comments