Closed
Description
The docs have the following snippet for flags:
<?php
public function handle()
{
$message = "Hello World";
if ($this->hasFlag('shout')) {
$message = strtoupper($message);
}
$this->getPrinter()->display($message);
}However then I try to use hasFlag I receive the following output.
public function handle()
{
var_dump($this->hasFlag('verbose')); // bool(false)
} public function handle()
{
var_dump($this->hasFlag('--verbose')); // bool(true)
}My question is: Are the docs wrong in this case or is the implementation wrong?
Metadata
Metadata
Assignees
Labels
No labels
Activity
lotfio commentedon May 7, 2021
Hello @obstschale The implementation is correct as it is a standard that flags start with
-,--if you have a look at the CommandCall class you can see the method that is parsing flags hereI am not sure also if it is a documentation issue as it can be written that way to evaluate to
false,So lets get @erikaheidi to confirm.
erikaheidi commentedon May 8, 2021
Hello @obstschale , thank you very much for opening this issue. My initial intention was to save the flags without the
--portion, and somewhere along the way I thought it could lead to confusion - but my thoughts clearly got mixed up when writing the docs.However, thinking again about this, I believe it makes more sense to go with this approach. I am working on a fix now to allow for both ways (otherwise it could definitely cause backwards compatibility issues), please keep an eye for the coming release.
erikaheidi commentedon May 8, 2021
and thank you so much @lotfio for jumping in ❤️
Fixing #29 - now obtaining flags also without --
Merge pull request #30 from minicli/fix-flags
obstschale commentedon May 8, 2021
Actually, I was thinking the same. In my eyes
--is just the indicator that the following is a flag. But it is not part of the flag. Hence, the methodhasFlagdoes not need the--because, hey the method name itself already says it.But I'm totally fine with the current implementation. But I would love the see that the documentation matches the implementation :D
erikaheidi commentedon May 8, 2021
Thank you again! The new release is out 🎉 please update :D going ahead and closing this now.