Skip to content

Introduce class CommandArgumentParser [RHELDST-34542]#278

Closed
dichn wants to merge 1 commit into
release-engineering:masterfrom
dichn:new-parser
Closed

Introduce class CommandArgumentParser [RHELDST-34542]#278
dichn wants to merge 1 commit into
release-engineering:masterfrom
dichn:new-parser

Conversation

@dichn
Copy link
Copy Markdown
Contributor

@dichn dichn commented Jan 23, 2026

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.

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.
@dichn
Copy link
Copy Markdown
Contributor Author

dichn commented Jan 26, 2026

I think the CI failure has nothing to do with the new parser and this patch should be fine to review.
@rbikar @kdudka

[51/58] Installing systemd-udev-0:257.1 100% |  26.2 MiB/s |  12.3 MiB |  00m00s
>>> Running %post scriptlet: systemd-udev-0:257.10-1.fc42.x86_64                
>>> Finished %post scriptlet: systemd-udev-0:257.10-1.fc42.x86_64               
>>> Scriptlet output:                                                           
>>> Failed to preset unit: Unit system-systemdx2dcryptsetup.slice does not exist
>>>  

@dichn dichn self-assigned this Jan 26, 2026
@kdudka
Copy link
Copy Markdown
Contributor

kdudka commented Jan 26, 2026

Forwarding to @siteshwar @sfowl - any idea if this would work for osh-cli?

Copy link
Copy Markdown
Member

@rbikar rbikar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you intend to continue, create new classes for each command or immediately re-implement with argparse?

One example:

class Add_User(ClientCommand):

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.

Comment thread kobo/argcli.py
from kobo.plugins import Plugin


class ArgparseCommand(Plugin):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be equivalent of

class Command(Plugin):

but there some attributes that you didn't add here. How do you intend to support them?

Comment thread kobo/argcli.py
raise NotImplementedError


class CommandArgumentParser(object):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be equivalent

class Command(Plugin):

but it doesn't seem to provide everything, do you intend to implement the rest?

@dichn
Copy link
Copy Markdown
Contributor Author

dichn commented Feb 2, 2026

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.

@dichn dichn closed this Feb 2, 2026
@dichn dichn reopened this Feb 5, 2026
@dichn dichn closed this Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants