drush-ops / drush

Drush is a command-line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those who spend their working hours hacking away at the command prompt.
https://www.drush.org
2.34k stars 1.08k forks source link

boolean options not loading from config file #6134

Open damienmckenna opened 1 week ago

damienmckenna commented 1 week ago

Describe the bug Boolean options defined in drush/drush.yml aren't used when running sql-dump.

To Reproduce drush.yml:

command:
  sql:
    dump:
      options:
        gzip: true
        structure-tables-key: common
sql:
  structure-tables:
    common:
      - cache
      - 'cache_*'
      - 'sessions'

Run drush sql-dump --result-file=auto.

Expected behavior A gzip file is saved.

Actual behavior A text sql file is caved.

Workaround Pass --gzip at runtime.

System Configuration

Q A
Drush version? 13.3.0.0
Drupal version? 11.0.5
PHP version 8.3.11
OS? Linux (via ddev)
damienmckenna commented 1 week ago

I added print_r($options) to SqlBase::dump() and this is what it shows:

Array
(
    [result-file] => auto
    [create-db] => 
    [data-only] => 
    [ordered-dump] => 
    [gzip] => 
    [extra] => 
    [extra-dump] => 
    [format] => null
    [database] => default
    [db-url] => 
    [target] => default
    [show-passwords] => 
    [skip-tables-key] => 
    [structure-tables-key] => common
    [tables-key] => 
    [skip-tables-list] => 
    [structure-tables-list] => 
    [tables-list] => 
    [fields] => 
    [field] => 
    [druplicon] => 
    [notify] => 
    [xh-link] => 
    [help] => 
    [quiet] => 
    [verbose] => 
    [version] => 
    [ansi] => 
    [no-interaction] => 
    [yes] => 
    [no] => 
    [root] => /var/www/html/web
    [uri] => https://mysite.ddev.site
    [simulate] => 
    [define] => Array
        (
        )

    [xdebug] => 
)

As you can see, the "structure-tables-key" value is defined correctly but "gzip" is not.

damienmckenna commented 1 week ago

If I add verbose: true to the drush.yml that value doesn't change in the $options output.

If I comment out the structure-tables-key line the value does change.

These just confirm that boolean values are not loaded properly.

greg-1-anderson commented 1 week ago

This has been broken for years. In ancient versions of Symfony, it worked. Then, Symfony became more strict, and it stopped working. I forget the details of what changed, but the basic problem is that boolean CLI options do not take a default value, so the config code can't follow its usual pattern of setting the default value of the Symfony Console input item. Years and years ago, I submitted a feature enhancement to Symfony console, adding negatable binary cli options that had the ability to set their default value; however, I didn't have time to do the work to get it merged. Then, years ago, someone else picked it up and got it merged, but they decided that the ability to set the default value of a binary cli option was unnecessary, so consolidation/config remains broken.

I don't know if there's another way to fix this that doesn't involve changing Symfony.