Skip to content

Let command-line flags override a config file, even when set to their default - #125

Merged
zfleeman merged 1 commit into
mainfrom
zf/config-override-114
Oct 22, 2026
Merged

zfleeman merged 1 commit into
mainfrom
zf/config-override-114

Conversation

@zfleeman

Copy link
Copy Markdown
Owner

Closes #114.

A config file used to win whenever a command-line value matched argparse's built-in default, so --config my.json -c x264 --no-approx still encoded with x265 and kept --approx on.

Now _merge_config_args() loads the config file(s), passes their values to parser.set_defaults(), and parses the command line again. The order is command line > config file > built-in defaults, and anything you type wins.

Notes:

  • update_args_from_config() and its == parser.get_default(k) check are removed.
  • This reuses the first full parse to find the config file, instead of a separate parse_known_args() step. _search_for_default_config() doesn't change.
  • Config keys that aren't flags still end up in the args, and from/to still go through _extract_times().
  • A "config" key inside a config file is still followed. The outer file wins over the one it points to.

Tests in test_arguments.py cover -c x264, --no-approx, -s 20, and -a 64 beating a config file, plus config values applying when the flag isn't passed and unrelated flags keeping their built-in defaults.

@zfleeman
zfleeman merged commit dde88ca into main Oct 22, 2026
6 checks passed
@zfleeman
zfleeman deleted the zf/config-override-114 branch October 22, 2026 18:01
@zfleeman zfleeman mentioned this pull request Oct 22, 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.

Command-line flags set to their default can't override a config file

1 participant