Repository: readthedocs/readthedocs.org
Issue: Fix logic to build internal/external versions on management command

We are building only external/internal versions if we pass the `magic` word `external`/`internal`

https://github.com/readthedocs/readthedocs.org/blob/2a1b641469bc549f0de06baffb1831cb7a3bdd6b/readthedocs/core/management/commands/update_repos.py#L80-L101

But we first check if version isn't `None` or different than `all`

https://github.com/readthedocs/readthedocs.org/blob/06a2e65423a6e26e3226cda724112219c0867fdd/readthedocs/core/management/commands/update_repos.py#L49-L49

Meaning we never hit the internal/external _elifs_

We should just check for all these special values first.

Also, maybe add the same logic for the else in the bottom https://github.com/readthedocs/readthedocs.org/blob/06a2e65423a6e26e3226cda724112219c0867fdd/readthedocs/core/management/commands/update_repos.py#L85-L91

Changed files:
readthedocs/core/management/commands/update_repos.py

diff --git a/readthedocs/core/management/commands/update_repos.py b/readthedocs/core/management/commands/update_repos.py
index 031abf54e..8a0aaec6f 100644
--- a/readthedocs/core/management/commands/update_repos.py
+++ b/readthedocs/core/management/commands/update_repos.py
@@ -23,7 +23,7 @@ class Command(BaseCommand):
     help = __doc__
 
     def add_arguments(self, parser):
-        parser.add_argument('slugs', nargs='+', type=str)
+        parser.add_argument('--slugs', nargs='+', type=str)
 
         parser.add_argument(
             '-f',
@@ -43,17 +43,11 @@ class Command(BaseCommand):
     def handle(self, *args, **options):
         force = options['force']
         version = options['version']
+        slugs = options.get('slugs', [])
 
-        if options.get('slugs', []):
-            for slug in options['slugs']:
-                if version and version != 'all':
-                    log.info('Updating version %s for %s', version, slug)
-                    for version in Version.objects.filter(
-                            project__slug=slug,
-                            slug=version,
-                    ):
-                        trigger_build(project=version.project, version=version)
-                elif version == 'all':
+        if slugs:
+            for slug in slugs:
+                if version == 'all':
                     log.info('Updating all versions for %s', slug)
                     for version in Version.objects.filter(
                             project__slug=slug,
@@ -77,6 +71,13 @@ class Command(BaseCommand):
                             uploaded=False,
                     ):
                         trigger_build(project=version.project, version=version)
+                elif version:
+                    log.info('Updating version %s for %s', version, slug)
+                    for version in Version.objects.filter(
+                            project__slug=slug,
+                            slug=version,
+                    ):
+                        trigger_build(project=version.project, version=version)
                 else:
                     p = Project.all_objects.get(slug=slug)
                     log.info('Building %s', p)
@@ -89,6 +90,26 @@ class Command(BaseCommand):
                         uploaded=False,
                 ):
                     trigger_build(project=version.project, version=version)
+            elif version == INTERNAL:
+                log.info('Updating all internal versions')
+                for version in Version.internal.filter(
+                        active=True,
+                        uploaded=False,
+                ):
+                    trigger_build(project=version.project, version=version)
+            elif version == EXTERNAL:
+                log.info('Updating all external versions')
+                for version in Version.external.filter(
+                        active=True,
+                        uploaded=False,
+                ):
+                    trigger_build(project=version.project, version=version)
+            elif version:
+                log.info('Updating version %s', version)
+                for version in Version.objects.filter(
+                        slug=version,
+                ):
+                    trigger_build(project=version.project, version=version)
 
             else:
                 log.info('Updating all docs')