Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set a default value when using InputOption::VALUE_NONE mode #51

Closed
glensc opened this issue Jan 23, 2019 · 5 comments
Closed

Cannot set a default value when using InputOption::VALUE_NONE mode #51

glensc opened this issue Jan 23, 2019 · 5 comments

Comments

@glensc
Copy link
Contributor

glensc commented Jan 23, 2019

$ php71 test.php
Fatal error: Uncaught Symfony\Component\Console\Exception\LogicException: Cannot set a default value when using InputOption::VALUE_NONE mode. in vendor/symfony/console/Input/InputOption.php:159
Stack trace:
#0 silly/vendor/mnapoli/silly/src/Command/Command.php(63): Symfony\Component\Console\Input\InputOption->setDefault(false)
#1 silly/vendor/mnapoli/silly/src/Application.php(108): Silly\Command\Command->defaults(Array)
#2 silly/test.php(20): Silly\Application->command('mail:download [...', Array)
#3 {main}
  thrown in vendor/symfony/console/Input/InputOption.php on line 159

seems to be issue with symfony 4.2:

$ composer show
mnapoli/silly             1.7.1   Silly CLI micro-framework based on Symfony Console
php-di/invoker            2.0.0   Generic and extensible callable invoker
psr/container             1.0.0   Common Container Interface (PHP FIG PSR-11)
symfony/console           v4.2.2  Symfony Console Component
symfony/contracts         v1.0.2  A set of abstractions extracted out of the Symfony components
symfony/polyfill-mbstring v1.10.0 Symfony polyfill for the Mbstring extension

Reproducer: https://gist.github.com/glensc/b28386f361db58f3c436e7b79460983b

tag v1 shows the problem:

git clone -b v1 https://gist.github.com/glensc/b28386f361db58f3c436e7b79460983b silly-51
@glensc
Copy link
Contributor Author

glensc commented Jan 23, 2019

@mnapoli am i using something wrong, or just not compatible with symfony 4.2?

@glensc
Copy link
Contributor Author

glensc commented Jan 23, 2019

downgraded symfony/console:

  • v4.1.10 same
  • v4.0.15 same
  • v3.4.21 same
  • v3.3.18 same
  • v3.2.14 same
  • v3.1.10 same
  • v3.0.9 same

i'm not able to downgrade further with mnapoli/silly=1.7.1

@glensc
Copy link
Contributor Author

glensc commented Jan 23, 2019

had to downgrade to 1.5 for error to go away:

➔ composer require symfony/console:^2 mnapoli/silly:~1.5.1 php-di/invoker:~1.2
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 3 installs, 3 updates, 0 removals
  - Installing container-interop/container-interop (1.2.0): Loading from cache
  - Downgrading php-di/invoker (2.0.0 => 1.3.3): Loading from cache
  - Installing psr/log (1.1.0): Loading from cache
  - Downgrading symfony/console (v4.2.2 => v2.8.11): Loading from cache
  - Downgrading mnapoli/silly (1.7.1 => 1.5.1): Loading from cache
  - Installing symfony/debug (v3.4.21): Loading from cache
Generating autoload files
➔ ./test.php
➔

@glensc
Copy link
Contributor Author

glensc commented Jan 23, 2019

i'm able to avoid the error by renaming the option:

➔ git diff
diff --git a/MailDownloadCommand.php b/MailDownloadCommand.php
index c4de6d7..1a4412e 100644
--- a/MailDownloadCommand.php
+++ b/MailDownloadCommand.php
@@ -16,7 +16,7 @@ namespace Eventum\Console\Command;
 class MailDownloadCommand
 {
     const DEFAULT_COMMAND = 'mail:download';
-    const USAGE = self::DEFAULT_COMMAND . ' [username] [hostname] [mailbox] [--limit=] [--no-lock]';
+    const USAGE = self::DEFAULT_COMMAND . ' [username] [hostname] [mailbox] [--limit=] [--nolock]';

     /**
      * @param string $username

but this would be backwards incompatible change for the application.

➔ ./test.php
array:5 [
  "username" => null
  "hostname" => null
  "mailbox" => null
  "limit" => 0
  "no-lock" => false
]
➔ ./test.php --nolock
array:5 [
  "username" => null
  "hostname" => null
  "mailbox" => null
  "limit" => 0
  "no-lock" => true
]
➔

@glensc
Copy link
Contributor Author

glensc commented Jan 23, 2019

removing default value for $noLock = false also helper:

➔ ./test.php
array:5 [
  "username" => null
  "hostname" => null
  "mailbox" => null
  "limit" => 0
  "no-lock" => false
]
➔ ./test.php --no-lock
array:5 [
  "username" => null
  "hostname" => null
  "mailbox" => null
  "limit" => 0
  "no-lock" => true
]
➔ git diff
diff --git a/MailDownloadCommand.php b/MailDownloadCommand.php
index c4de6d7..65246a2 100644
--- a/MailDownloadCommand.php
+++ b/MailDownloadCommand.php
@@ -22,10 +22,10 @@ class MailDownloadCommand
      * @param string $username
      * @param string $hostname
      * @param string $mailbox
-     * @param int $limit
      * @param bool $noLock
+     * @param int $limit
      */
-    public function execute($username, $hostname, $mailbox, $limit = 0, $noLock = false)
+    public function execute($username, $hostname, $mailbox, $noLock, $limit = 0)
     {
         dump([
             'username' => $username,
➔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant