Skip to content

Commit

Permalink
Adding error message when include is part of CLI (#18)
Browse files Browse the repository at this point in the history
* Including file include from the commandline

* Adding tests

* Fixing help string tests

* Adding content to README.md

* Adding error conditions
  • Loading branch information
abhinavg4 authored Sep 12, 2024
1 parent cd39e7a commit ec47af9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion draccus/argparsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ def _postprocessing(self, parsed_args: Namespace) -> T:
for key in parsed_arg_values:
parsed_value = cfgparsing.parse_string(parsed_arg_values[key])
if isinstance(parsed_value, str) and parsed_value.startswith("include"):
parsed_arg_values[key] = cfgparsing.load_config(open(parsed_value[8:], "r"))
try:
parsed_arg_values[key] = cfgparsing.load_config(open(parsed_value[8:], "r"))
except FileNotFoundError as e:
raise FileNotFoundError(f"{e}. Include is a reserved cli keyword. "
f"If your argument uses include, "
f"Please refer to https://github.com/dlwh/draccus/issues/17")
else:
parsed_arg_values[key] = parsed_value

Expand Down

0 comments on commit ec47af9

Please sign in to comment.