Open
Conversation
flavio-a
approved these changes
Oct 1, 2025
Collaborator
flavio-a
left a comment
There was a problem hiding this comment.
I think I had some kind of objection last time I reviewed thiw but I can't remember it right now, so I'll approve before it comes back to mind.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
@Cruifer is starting to expect and rely on help texts in custom bot scripts. That poses a number of problems at present:
We don't always have a
-helpflag to show the script__doc__, even though we do have a docstring most of the times.The actual parameter names and what's contained in the script can mismatch, as the whole argument parsing is implemented manually
Since we have to use with Pywikibot's terrible CLI option synthax (
-name:<value>), in the few places where we have used the Python standard library we have inconsistency, as we have a sane syntax (e.g.--name <value>).What
After looking around, I couldn't find any decent library that would allow CLI named parameters to be split on
:and start with a single-(henceforth referred to as Pywikibot's terrible CLI option syntax). I hence had to implement something myself.PcwCliArgsis yet anotherArgumentParser-looking CLI argument parsing utility. You add options, flags and positional arguments, and then you parse them into a dictionary. If the-helpflag is found, it prints an auto-generated help text and exits.I wanted to do something with dataclasses and reflection, but apparently Python's class attributes can't have their own docstrings, so here we are with a builder interface.
The only issue is that we'd need the current directory in the
PYTHONPATHenvironment variable. That's not hard to achieve though.