(args, parser)
| 120 | |
| 121 | |
| 122 | def update_args_with_config(args, parser): |
| 123 | try: |
| 124 | resolved_config = resolve_config_file(args.config_name, args.filename) |
| 125 | |
| 126 | if resolved_config is None: |
| 127 | console.info(f"No config file '{args.config_name}' found. Proceeding without one.") |
| 128 | return args |
| 129 | |
| 130 | args.config_name = resolved_config |
| 131 | config_args = get_args_from_config(resolved_config, parser) |
| 132 | |
| 133 | # Get all action types from the parser |
| 134 | action_types = {action.dest: action for action in parser._actions} |
| 135 | |
| 136 | # Update args with config values, but command line args take precedence |
| 137 | for key, value in vars(config_args).items(): |
| 138 | # Skip if the argument was provided on command line |
| 139 | if key in vars(args): |
| 140 | arg_action = action_types.get(key) |
| 141 | if arg_action and isinstance(arg_action, argparse._StoreAction): |
| 142 | # For regular arguments, only skip if explicitly provided |
| 143 | if getattr(args, key) is not None and (arg_action.default is None or value == arg_action.default): |
| 144 | continue |
| 145 | elif arg_action and isinstance(arg_action, argparse._StoreTrueAction): |
| 146 | # For boolean flags, skip if True (explicitly set) |
| 147 | if getattr(args, key): |
| 148 | continue |
| 149 | |
| 150 | # Set the value from config |
| 151 | if key in action_types: |
| 152 | setattr(args, key, value) |
| 153 | else: |
| 154 | parser.error(f"Invalid argument: {key}") |
| 155 | |
| 156 | except AmbiguousConfigFileError as e: |
| 157 | parser.error(str(e)) |
| 158 | except Exception as e: |
| 159 | parser.error(f"Error reading config file: {str(e)}") |
| 160 | |
| 161 | return args |
| 162 | |
| 163 | |
| 164 | def create_parser(): |
no test coverage detected