MCPcopy Index your code
hub / github.com/Codeplain-ai/codeplain / get_args_from_config

Function get_args_from_config

plain2code_read_config.py:32–68  ·  view source on GitHub ↗

Read configuration from YAML file and return args compatible with plain2code_arguments.py. Args: config_file: Path to the YAML config file Returns: Namespace object with arguments as defined in plain2code_arguments.py Raises: FileNotFoundError: If config fi

(config_file: str, parser: ArgumentParser)

Source from the content-addressed store, hash-verified

30
31
32def get_args_from_config(config_file: str, parser: ArgumentParser) -> Namespace:
33 """
34 Read configuration from YAML file and return args compatible with plain2code_arguments.py.
35
36 Args:
37 config_file: Path to the YAML config file
38 Returns:
39 Namespace object with arguments as defined in plain2code_arguments.py
40
41 Raises:
42 FileNotFoundError: If config file doesn't exist
43 KeyError: If argument not found in parser arguments
44 """
45
46 args = Namespace()
47
48 # Load config
49 config = load_config(config_file)
50 config = validate_config(config, parser)
51
52 for action in parser._actions:
53 # Create a list of possible config keys for this argument
54 possible_keys = [action.dest]
55 if hasattr(action, "option_strings"):
56 # Add all option strings without leading dashes
57 possible_keys.extend(opt.lstrip("-") for opt in action.option_strings)
58
59 # Handling multi-named arguments like --verbose and -v
60 config_value = None
61 for key in possible_keys:
62 if key in config:
63 config_value = config[key]
64 break
65
66 if config_value is not None:
67 setattr(args, action.dest, config_value)
68 return args

Callers 1

update_args_with_configFunction · 0.90

Calls 2

load_configFunction · 0.85
validate_configFunction · 0.85

Tested by

no test coverage detected