adhocore / php-cli

PHP Console Application made easy- build great console apps with ease. Comes with Zero Dependency and Autocompletion support. Think of it as a PHP cli application framework.
https://github.com/adhocore/php-cli
MIT License
338 stars 35 forks source link

Support for options defined as "--name=value" #54

Closed oscarotero closed 4 years ago

oscarotero commented 4 years ago

Hi, thanks for this great library! I've noted that the parser does not support the ability to define arguments in this format:

command --option1 --option2="value"

But this works

command --option1 --option2 "value"

I think this whould be a good adition because it's a common way to set option values. Thanks!

adhocore commented 4 years ago

thank you for using library and opening a ticket. i will check it out sometime this weekend. (i thought it was already possible though)

adhocore commented 4 years ago

i checked and it is working.

file: test.php

<?php

$app = new Ahc\Cli\Application('app', '0.0.1');
$app
    ->command('cmd', 'Some cmd')
    ->option('-o --option1', 'Some option')
    ->option('-O --option2', 'Some other option')
    ->action(function ($option1, $option2) {
        var_dump($option1, $option2);
    });

$app->handle($_SERVER['argv']);

run in cli

$ php test.php cmd --option1 value1 --option2="value 2"

/mnt/d/projects/my/php-cli/test.php:9:
string(6) "value1"
/mnt/d/projects/my/php-cli/test.php:9:
string(7) "value 2"

Could you try updating adhocore/cli?

composer require adhocore/cli

adhocore commented 4 years ago

latest release: https://github.com/adhocore/php-cli/releases/tag/0.8.0

oscarotero commented 4 years ago

Hi. Sorry but still not working to me. In my use case I have the following command:

php commands.php list --limit 5 --order-by "id desc"

Using = I have the following error:

php commands.php list --limit 5 --order-by="id desc"

Ahc\Cli\Exception\RuntimeException Option "--order-by=id desc" not registered
(thrown in .../vendor/adhocore/cli/src/Input/Command.php:321)
adhocore commented 4 years ago

thanks for example. could reproduce issue.

$ php commands.php list --limit 5 --order-by="id desc" # didnt work
$ php commands.php list --limit 5 --order="id desc"    # worked

fixed in #55 (now both format above works)

adhocore commented 4 years ago

pls update to 0.8.2

oscarotero commented 4 years ago

Now works great. Thank you!

adhocore commented 4 years ago

it would be interesting to know what you built using adhocore/cli 😎

oscarotero commented 4 years ago

It's just a cli tool to handle the database of a website (list, update, remove items, etc). I was looking for a simple tool to do something quick and easily. Symfony is a bit verbose in my opinion and your project is exactly what I need. (I used commander.js in other projects but in this case I needed something in PHP).

Again, thanks for create and maintain it.