[ConfigArgumentMerger] Improve ConfigArgumentMerger compatibility with external callers (#17051)

This commit is contained in:
YAMY
2026-01-16 15:32:42 +08:00
committed by GitHub
parent 968c4f55b1
commit daa4841e86
+13 -1
View File
@@ -16,9 +16,14 @@ logger = logging.getLogger(__name__)
class ConfigArgumentMerger: class ConfigArgumentMerger:
"""Handles merging of configuration file arguments with command-line arguments.""" """Handles merging of configuration file arguments with command-line arguments."""
def __init__(self, parser: argparse.ArgumentParser): def __init__(
self,
parser: argparse.ArgumentParser = None,
boolean_actions: List[str] = None,
):
"""Initialize with list of store_true action names.""" """Initialize with list of store_true action names."""
# NOTE: The current code does not support actions other than "store_true" and "store". # NOTE: The current code does not support actions other than "store_true" and "store".
if parser is not None:
self.parser = parser self.parser = parser
self.store_true_actions = [ self.store_true_actions = [
action.dest action.dest
@@ -35,6 +40,13 @@ class ConfigArgumentMerger:
and "--help" not in a.option_strings and "--help" not in a.option_strings
and "-h" not in a.option_strings and "-h" not in a.option_strings
} }
elif boolean_actions is not None:
# Legacy interface for compatibility
self.store_true_actions = boolean_actions
self.unsupported_actions = {}
else:
self.store_true_actions = []
self.unsupported_actions = {}
def merge_config_with_args(self, cli_args: List[str]) -> List[str]: def merge_config_with_args(self, cli_args: List[str]) -> List[str]:
""" """