Bug #51255

CommandController: Fix parsing of boolean values

Added by Timo Dödtmann about 8 years ago. Updated over 7 years ago.

Status:
Resolved
Priority:
Should have
Category:
Command
Target version:
-
Start date:
2013-08-22
Due date:
% Done:

0%

Estimated time:
PHP Version:
5.4
Has patch:
No
Complexity:

Description

I have the following (awesome) command:

<?php
namespace Acme\Demo\Command;

use TYPO3\Flow\Annotations as Flow;

/**
 * TestCommand
 *
 * @Flow\Scope("singleton")
 */
class MyCommandController extends \TYPO3\Flow\Cli\CommandController {

    /**
     * @param boolean $myParam A boolean value
     * @return void
     */
    public function commandCommand($myParam) {
        echo sprintf("Result: %s\n\n", var_export($myParam, 1));
    }

}

Now, it will be called in the terminal as followed:

$ ./flow my:command --myParam FALSE
Result: bool (false)

$ ./flow my:command --myParam=FALSE
Result: bool (true)

The last command returns `TRUE` but `FALSE` is passed, because the passed value is interpreted as a string (probably because of the prefix `=`).

I'm not quite sure if it is really a bug, but it would be nice if it is interpreted as "bool (false)".


Related issues

Related to TYPO3.Flow - Bug #59023: BooleanConverter should not convert empty values to booleanNew2014-05-22

Actions
Is duplicate of TYPO3.Flow - Bug #51385: BooleanConverter considers "false" TRUEResolvedBastian Waidelich2013-08-27

Actions
#1

Updated by Bastian Waidelich about 8 years ago

  • Status changed from New to Needs Feedback

just set the default to FALSE like:

    /**
     * @param boolean $myParam A boolean value
     * @return void
     */
    public function commandCommand($myParam = FALSE) {
        $this->outputLine("Result: %s\n\n", array($myParam));
    }

...and omit the flag "--my-param" if you don't want to set it

#2

Updated by Timo Dödtmann about 8 years ago

Thanks for your feedback.

I know how to correctly sends a FALSE to the CommandController.
But I think it would be nice if `--myParam=FALSE` and `--myParam FALSE` would lead to the same result.

By the way, declaration of a default value doesn't fix the different treatment of the parameter.

#3

Updated by Bastian Waidelich about 8 years ago

Timo Dödtmann wrote:

But I think it would be nice if `--myParam=FALSE` and `--myParam FALSE` would lead to the same result.

Reading the issue again, the current behavior is exactly how it's documented at http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartIII/CommandLine.html#passing-arguments

--foo=bar is not supported currently. So this would be a feature request and is not related to boolean arguments if I got it right!?

By the way, declaration of a default value doesn't fix the different treatment of the parameter.

That was just an example of how to turn the argument into an option that is false by default, meaning: If you omit the flag, it's FALSE if you add --flag it is TRUE

#4

Updated by Timo Dödtmann about 8 years ago

Exactly!
--myParam FALSE works fine
--myParam=FALSE is a feature request (because FALSE is interpreted as a string)

#5

Updated by Bastian Waidelich about 8 years ago

  • Subject changed from CommandController: Parsing of boolean values to CommandController: Fix parsing of boolean values
  • Status changed from Needs Feedback to Accepted
  • Assignee set to Bastian Waidelich

Ok, I'm with you now. this is indeed a bug with the BooleanConverter. See #51385

#6

Updated by Gerrit Code Review about 8 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/23355

#7

Updated by Gerrit Code Review about 8 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/23355

#8

Updated by Bastian Waidelich about 8 years ago

  • Status changed from Under Review to Closed

Closing as duplicate of #51385

#9

Updated by Gerrit Code Review over 7 years ago

  • Status changed from Closed to Under Review

Patch set 1 for branch 2.0 of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at https://review.typo3.org/27205

#10

Updated by Bastian Waidelich over 7 years ago

  • Status changed from Under Review to Resolved

Also available in: Atom PDF