Add --cog-path CLI argument#6510
Conversation
|
This PR does not behave as outlined in the issue. |
|
Oops, good catch! I'll take another look at this. |
|
So, I propose the following: |
|
Why not just store it in memory during the run the flag is used? Why does the disk need to be used at all? |
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. This also adds the `persist` argument to `add_path()`, to allow for this functionality. Closes Cog-Creators#6506
Latest commit stores it in memory. Assuming I didn't miss anything, should be ready for review now. |
Flame442
left a comment
There was a problem hiding this comment.
[p]removepath (and by extension, bot._cog_mgr.remove_path abd .add_path) has incorrect behavior with the way you have temporarily added the path. These methods pull from bot._cog_mgr.user_defined_paths to get the list of user-defined paths to modify. By including the temporary paths in this method's output, they will attempt to append to and remove from the list containing the temporary paths, then set the list of user paths including any temporary paths that remain after that change. This will cause those remaining paths to become permanent paths.
All of the frontend (CogManagerUI cog) and backend (CogManager class) logic needs to properly handle not only processing both permanent and temporary user-defined paths, but also listing and modifying them.
Good catch, fixed this in the latest commit.
Updated in latest commit to make Out of curiosity, why should temporary paths be modifiable through Discord? I struggle to see a reason to use this feature in that way, as you would need to re-run the command to add a temporary path after each time the bot restarts. This would also result in any cogs loaded from a previously set temporary path failing to load on restart. With a CLI argument, you can just have your service runner (systemd, docker, etc.) use the argument every time it starts the bot. The temporary paths list is also populated before cogs begin loading at startup when using the CLI argument. |
In an attempt to speak succinctly, I said something I did not mean. What I should have said is that all frontend and backend logic needs to be updated such that it does not cause unexpected behavior when temporary paths are present. This includes logic that is currently used to modify paths, as it had the incorrect behavior I described. I agree that there is no reason to allow modifying temporary paths within discord. |
Flame442
left a comment
There was a problem hiding this comment.
Thank you for your contribution!
Description of the changes
This PR adds an argument,
--cog-path, to theredbotCLI that accepts a path, validates that the provided path exists, and adds the path viaself._cog_mgr.add_path(), so that cogs can be loaded from that path. The argument can be passed multiple times to add more than one path at a time. These paths are stored in memory and never to disk, so restarting the bot without the argument will "remove" the paths.Additionally, this PR adds a
persistargument toCogManager.add_path(), which defaults toTrue. The original behavior of appending the added path to a list and then calling.set_path()on that list is retained through this argument being set toTrue. Setting this argument toFalsewill append the path to a module-level list of paths, stored in memory. These are, as I mentioned earlier, never written to the bot's config, and are effectively discarded on shutdown.Closes #6506.
Have the changes in this PR been tested?
Yeah, but not super thoroughly