Skip to content

hasFlag - Wrong documentation or implementation? #29

Closed

Description

@obstschale

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?

Activity

  1. lotfio commented on May 7, 2021

    @lotfio
    Member

    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 here

    I 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.

  2. erikaheidi commented on May 8, 2021

    @erikaheidi
    Member

    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.

  3. erikaheidi commented on May 8, 2021

    @erikaheidi
    Member

    and thank you so much @lotfio for jumping in ❤️

  4. added 2 commits that reference this issue on May 8, 2021
  5. obstschale commented on May 8, 2021

    @obstschale
    Author

    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.

    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 method hasFlag does 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

  6. erikaheidi commented on May 8, 2021

    @erikaheidi
    Member

    Thank you again! The new release is out 🎉 please update :D going ahead and closing this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions