Problem/Motivation

This module is very useful for exporting po files from our custom themes/modules.
In order to make the export reproducible, we found it nice to agregate all the export commands for a project in a simple bash script that we can run at different point of the development process with.
The problem is that there is no way to input a default "write-mode" when generating a PO file and an existing file is detected (something akin to a quiet mode or -y)

Proposed resolution

Provide a way to choose the default when generating a PO file.

Comments

Radelson created an issue. See original summary.

radelson’s picture

Here is a first small patch

wengerk’s picture

Status: Active » Needs work

Many thanks for your contribution and the awesome idea of "silent/quite" mode !
Your integration of default-write-mode is pretty cool. Here is my review

+++ b/src/Commands/PotionCommands.php
@@ -279,6 +279,10 @@ class PotionCommands extends DrushCommands {
+   * @option default-write-mode
+   *   Allows choosing the default write mode if an existing PO file is found.
+   *   [default: "none"].

it would be great to add the available write-mode here.

   * @option default-write-mode
   *   Allows choosing the default write mode if an existing PO file is found.
   *   Available: "merge", "create" or "override". [default: "none"].<ol>

<li>
<code>
+++ b/src/Commands/PotionCommands.php
@@ -279,6 +279,10 @@ class PotionCommands extends DrushCommands {
+   *   [default: "none"].

Maybe we could set it to NULL instead of none ?

  • +++ b/src/Commands/PotionCommands.php
    @@ -327,11 +331,12 @@ class PotionCommands extends DrushCommands {
    +    'default-write-mode' => 'none',
    

    same as before, set as null ?

  • +++ b/src/Commands/PotionCommands.php
    @@ -370,14 +375,18 @@ class PotionCommands extends DrushCommands {
    +      if (in_array($options["default-write-mode"], ['merge', 'create', 'override'])) {
    +        $write_mode = $options["default-write-mode"];
    +      } else {
    +        $msg = $this->t('A file @destination already exists. Do you want to replace it with the new one?', ['@destination' => $fullpath]);
    +        $write_mode = $this->io()->choice($msg, [
    +          'merge' => $this->t('Merge.')->render(),
    +          'create' => $this->t('Keep both.')->render(),
    +          'override' => $this->t('Replace.')->render(),
    +        ], 'merge');
    +      }
    

    We could avoid an if-else here by

    $write_mode = $options["default-write-mode"];
    
    if (!write_mode) {
      $msg = $this->t('A file @destination already exists. Do you want to replace it with the new one?', ['@destination' => $fullpath]);
      // (...)
    }