diff --git a/axltempl/composer.py b/axltempl/composer.py index 3f44873..29707ef 100644 --- a/axltempl/composer.py +++ b/axltempl/composer.py @@ -71,6 +71,34 @@ def run_install(): sys.exit(4) +def require_packages(packages, dev=False): + """ + Run composer require or require --dev + """ + if not is_present(): + util.write_error("Cannot find composer. Aborting...") + sys.exit(4) + + if len(packages) == 0: + return + + cmd = "composer require " + if dev: + cmd += "--dev " + cmd += " ".join([str(p) for p in packages]) + + composer_run = subprocess.run(cmd, shell=True, check=False) + if composer_run.returncode != 0: + util.write_error("Error when running 'composer require'. Aborting...") + util.write_error("Make sure you have set an adequate PHP memory limit.") + util.write_warning( + "Read {} for more details".format( + "https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors" + ) + ) + sys.exit(4) + + def get_drupal_template(name, description, core, core_version, docroot, cache_service): """ Get the composer template from package and modify it as per given options @@ -180,7 +208,7 @@ def __str__(self) -> str: """ package_str = self.name if self.version: - package_str += ":" + self.version + package_str += f':"{self.version}"' return package_str def __repr__(self) -> str: diff --git a/axltempl/drupal.py b/axltempl/drupal.py index cf72396..9fea370 100644 --- a/axltempl/drupal.py +++ b/axltempl/drupal.py @@ -58,6 +58,16 @@ default=DEFAULT_CORE_VERSION, show_default=True, ) +@click.option( + "--module", + "--package", + "-m", + "-p", + "packages", + type=click_types.COMPOSER_PACKAGE, + help="Specify Drupal module names or PHP packages", + multiple=True, +) @click.option( "--docroot", help="The document root", type=click.Path(exists=False), default="web" ) @@ -80,6 +90,7 @@ def main( description, core_package, core_version, + packages, docroot, cache, add_lando, @@ -112,6 +123,7 @@ def main( ) composer.run_install() + composer.require_packages(packages) settings_file = ensure_settings_file(docroot) modify_settings_file(