1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-12 12:23:50 +03:00

python: getopt: subclass OptionParser to populate option_class

The option_class needs to be set correctly for OptionGroups that use self.add_option

Override OptionParser `__init__` to change the default Option class to the samba one.

Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Rob van der Linde
2023-10-19 15:05:56 +13:00
committed by Andrew Bartlett
parent 6943a58bff
commit 837e1d9fda
3 changed files with 26 additions and 5 deletions

View File

@@ -115,6 +115,28 @@ class Option(optparse.Option):
return value
class OptionParser(optparse.OptionParser):
"""Samba OptionParser, adding support for required=True on Options."""
def __init__(self,
usage=None,
option_list=None,
option_class=Option,
version=None,
conflict_handler="error",
description=None,
formatter=None,
add_help_option=True,
prog=None,
epilog=None):
"""
Ensure that option_class defaults to the Samba one.
"""
super().__init__(usage, option_list, option_class, version,
conflict_handler, description, formatter,
add_help_option, prog, epilog)
class SambaOptions(optparse.OptionGroup):
"""General Samba-related command line options."""