Repository: nf-core/tools

Issue:
`--repo-type` needs implementing in all `nf-core modules` subcommands
### Description of the bug

Recently we added new behaviour for autodetecting repository type (pipeline or modules). When this can't be done, an error is given saying that it needs to be manually specified with `--repo-type`. However, it seems that this flag only exists for `nf-core modules create` and not any of the other `nf-core modules` commands.

So, functions such as `nf-core modules install` currently don't function if the pipeline has no config file specifying that it's a pipeline.


Discussion:

Resolving patch:
diff --git a/nf_core/__main__.py b/nf_core/__main__.py
--- a/nf_core/__main__.py
+++ b/nf_core/__main__.py
@@ -526,8 +526,7 @@ def remove(ctx, dir, tool):
 @click.option("-f", "--force", is_flag=True, default=False, help="Overwrite any files if they already exist")
 @click.option("-c", "--conda-name", type=str, default=None, help="Name of the conda package to use")
 @click.option("-p", "--conda-package-version", type=str, default=None, help="Version of conda package to use")
-@click.option("-r", "--repo-type", type=click.Choice(["pipeline", "modules"]), default=None, help="Type of repository")
-def create_module(ctx, tool, dir, author, label, meta, no_meta, force, conda_name, conda_package_version, repo_type):
+def create_module(ctx, tool, dir, author, label, meta, no_meta, force, conda_name, conda_package_version):
     """
     Create a new DSL2 module from the nf-core template.
 
@@ -549,7 +548,7 @@ def create_module(ctx, tool, dir, author, label, meta, no_meta, force, conda_nam
     # Run function
     try:
         module_create = nf_core.modules.ModuleCreate(
-            dir, tool, author, label, has_meta, force, conda_name, conda_package_version, repo_type
+            dir, tool, author, label, has_meta, force, conda_name, conda_package_version
         )
         module_create.create()
     except UserWarning as e:
diff --git a/nf_core/modules/module_utils.py b/nf_core/modules/module_utils.py
--- a/nf_core/modules/module_utils.py
+++ b/nf_core/modules/module_utils.py
@@ -367,14 +367,9 @@ def get_repo_type(dir, repo_type=None):
 
     # Figure out the repository type from the .nf-core.yml config file if we can
     tools_config = nf_core.utils.load_tools_config(dir)
-    if tools_config.get("repository_type") in ["pipeline", "modules"]:
-        if repo_type is not None and repo_type != tools_config["repository_type"]:
-            raise UserWarning(
-                f"'--repo-type {repo_type}' conflicts with [i][red]repository_type[/]: [blue]pipeline[/][/] in '{os.path.relpath(config_path_yml)}'"
-            )
-        return [dir, tools_config["repository_type"]]
+    repo_type = tools_config.get("repository_type", None)
 
-    # Could be set on the command line - throw an error if not
+    # If not set, prompt the user
     if not repo_type:
         log.warning(f"Can't find a '.nf-core.yml' file that defines 'repository_type'")
         repo_type = questionary.select(
@@ -385,12 +380,18 @@ def get_repo_type(dir, repo_type=None):
             ],
             style=nf_core.utils.nfcore_question_style,
         ).unsafe_ask()
+
+        # Save the choice in the config file
         log.info("To avoid this prompt in the future, add the 'repository_type' key to a root '.nf-core.yml' file.")
         if questionary.confirm(f"Would you like me to add this config now?").unsafe_ask():
             with open(os.path.join(dir, ".nf-core.yml"), "a+") as fh:
                 fh.write(f"repository_type: {repo_type}\n")
                 log.info("Config added to '.nf-core.yml'")
 
+    # Check if it's a valid answer
+    if not repo_type in ["pipeline", "modules"]:
+        raise UserWarning(f"Invalid repository type: '{repo_type}'")
+
     # It was set on the command line, return what we were given
     return [dir, repo_type]
 


Test patch: