Introduce class CommandArgumentParser [RHELDST-34542]#278
Conversation
This change adds a new `CommandAtgumentParser` to support argparse-based commands while keeping the existing optparse CommandOptionParser. This change introduces `ArgparseCommand` as a base class for argparse-based commands, allowing optparse and argparse commands to coexist during migration. No existing optparse behavior is modified.
|
I think the CI failure has nothing to do with the new parser and this patch should be fine to review. |
|
Forwarding to @siteshwar @sfowl - any idea if this would work for |
There was a problem hiding this comment.
How do you intend to continue, create new classes for each command or immediately re-implement with argparse?
One example:
kobo/kobo/client/commands/cmd_add_user.py
Line 10 in eec6a3d
Imagine you want to migrate
class Add_User(ClientCommand):
in order to migrate this you can do:
class Add_User(ArgparseCommand):
and update the code as needed. Is this your intention?
But we can just hope that no one inherits from Add_User. But you can see in rcm-pub that we actually use some inheritance.
I guess it would good to migrate to argparse but I think that for rcm-pub now it's very 'nice to have' and is not really urgent. And give the fact we shouldn't do any new improvements for pub as it's going to be decommissioned eventually and optparse should probably work for a long time as there i s no date for removal set.
https://peps.python.org/pep-0389/#deprecation-of-optparse
I don't want to stop this undertaking but I guess at this point we can prepare some foundation in kobo but it's questionable if we ever get to this in rcm-pub because the optparse will likely work for years to come and until there is some hard date of removal we won't really need to do this.
| from kobo.plugins import Plugin | ||
|
|
||
|
|
||
| class ArgparseCommand(Plugin): |
There was a problem hiding this comment.
This should be equivalent of
Line 153 in eec6a3d
but there some attributes that you didn't add here. How do you intend to support them?
| raise NotImplementedError | ||
|
|
||
|
|
||
| class CommandArgumentParser(object): |
There was a problem hiding this comment.
This should be equivalent
Line 153 in eec6a3d
but it doesn't seem to provide everything, do you intend to implement the rest?
|
We plan to stop the parser migration effort, since pub is expected to be decommissioned eventually. Refactoring a large portion of legacy code doesn't seem worthwhile, and optparse will likely remain functional for a long time, as no removal date has been set. |
This change adds a new
CommandAtgumentParserto support argparse-based commands while keeping the existing optparse CommandOptionParser.This change introduces
ArgparseCommandas a base class for argparse-based commands, allowing optparse and argparse commands to coexist during migration. No existing optparse behavior is modified.