From 3ac606432e0af5c5e2d0164988568c9606f39c1b Mon Sep 17 00:00:00 2001 From: cswimr Date: Sat, 1 Feb 2025 01:24:25 +0000 Subject: [PATCH] Add `--cog-path` CLI argument This argument takes a list of strings (can be used multiple times for more than one value), validates that the path provided exists, and adds the path via `self._cog_mgr.add_path()`, so that cogs can be loaded from that path. Closes #6506 --- redbot/core/_cli.py | 9 +++++++++ redbot/core/bot.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/redbot/core/_cli.py b/redbot/core/_cli.py index e1fbd981989..350db0f533c 100644 --- a/redbot/core/_cli.py +++ b/redbot/core/_cli.py @@ -219,6 +219,15 @@ def parse_cli_flags(args): action="extend", help="Force unloading specified cogs.", ) + parser.add_argument( + "--cog-path", + type=str, + default=[], + nargs="+", + action="extend", + help="Add a specific path to the list of cog paths. " + "This can be used multiple times to add multiple paths.", + ) parser.add_argument( "--dry-run", action="store_true", diff --git a/redbot/core/bot.py b/redbot/core/bot.py index 359b65e3657..a551010c814 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -1240,6 +1240,15 @@ async def _pre_connect(self) -> None: ) ) + if self._cli_flags.cog_path: + for path in self._cli_flags.cog_path: + path = Path(path) + if not path.exists(): + log.warning("Cog path '%s' does not exist, skipping", path) + continue + await self._cog_mgr.add_path(path) + log.info("Added cog path: %s", path) + if packages: # Load permissions first, for security reasons try: