You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add config_argument: user-supplied config file as argument defaults
config_files= lets the developer preset defaults from files chosen at
construction time. The new Parser(config_argument="--config") adds a
CLI flag so the END USER can point at a config file whose values
become argument defaults, resolved at invocation time.
Implementation is two-pass parsing: a throwaway pre-scan parser (that
neither prints nor exits) extracts only the config path from argv;
the file is loaded through the shared config_parser_class machinery
and layered over the constructor config defaults; then the real
parser is built — so required-relaxation, type-aware conversion,
group sections, and --help defaults all come from the existing
defaults pipeline.
Priority chain extends naturally:
declared defaults < config_files < config_argument file < env < CLI
Properties of the feature:
- accepts one flag or several aliases: config_argument=("-c", "--config")
- an explicitly passed path that is missing or malformed raises
ConfigurationError (config_files stays a lenient search list)
- no cascade into subparsers (consistent with config_files)
- runtime defaults live only for the duration of one parse_args call
- new Parser.loaded_config_files property reports applied files in
priority order
Also fixes a related pre-existing bug in ConfigAction: an explicit
--config file was merged BEFORE search_paths, so preset files
silently overrode the user's explicit choice; the explicit file now
wins.
Copy file name to clipboardExpand all lines: CLAUDE.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,9 @@
2
2
3
3
## What is argclass
4
4
5
-
Declarative CLI parser for Python over `argparse`. Type hints → CLI args automatically. `str`→string, `bool`→flag, `Optional[T]`→optional, `list[T]`→multi-value, `Literal[...]`→choices. Priority: defaults < config files < env vars < CLI args. Zero deps, stdlib only, Python 3.10-3.14.
5
+
Declarative CLI parser for Python over `argparse`. Type hints → CLI args automatically. `str`→string, `bool`→flag, `Optional[T]`→optional, `list[T]`→multi-value, `Literal[...]`→choices. Priority: defaults < config files < `config_argument` file < env vars < CLI args. Zero deps, stdlib only, Python 3.10-3.14.
6
+
7
+
`Parser(config_argument="--config")` adds a CLI flag whose file becomes argument defaults at invocation time (two-pass parsing); `config_files=` is the developer-preset equivalent.
0 commit comments