Skip to content

Commit d3f1857

Browse files
Fix: Support hyphens in command-line argument names (#576)
Allow CLI arguments to be specified with hyphens instead of only underscores. For example, `--proxy-auth-headers` now works in addition to `--proxy_auth_headers`. This matches the standard convention for command-line arguments where hyphens are typically preferred over underscores. The parser now checks both the original config attribute name and a hyphenated variant when matching arguments, making the CLI more intuitive and consistent with typical Unix/Linux command-line tools.
1 parent 092d563 commit d3f1857

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

timetagger/_config.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,22 @@ def _reset_config_to_defaults():
7777
def _update_config_from_argv(argv):
7878
for i in range(len(argv)):
7979
arg = argv[i]
80-
for name, conv, _ in Config._ITEMS:
81-
if arg.startswith(f"--{name}="):
82-
_, _, raw_value = arg.partition("=")
83-
elif arg == f"--{name}":
84-
if i + 1 < len(argv):
85-
raw_value = argv[i + 1]
80+
for config_attr, conv, _ in Config._ITEMS:
81+
for name in (config_attr, config_attr.replace("_", "-")):
82+
if arg.startswith(f"--{name}="):
83+
_, _, raw_value = arg.partition("=")
84+
elif arg == f"--{name}":
85+
if i + 1 < len(argv):
86+
raw_value = argv[i + 1]
87+
else:
88+
raise RuntimeError(f"Value for {arg} not given")
8689
else:
87-
raise RuntimeError(f"Value for {arg} not given")
88-
else:
89-
continue
90-
try:
91-
setattr(config, name, conv(raw_value))
92-
except Exception as err:
93-
raise RuntimeError(f"Could not set config.{name}: {err}")
94-
break
90+
continue
91+
try:
92+
setattr(config, config_attr, conv(raw_value))
93+
except Exception as err:
94+
raise RuntimeError(f"Could not set config.{config_attr}: {err}")
95+
break
9596

9697

9798
def _update_config_from_env(env):

0 commit comments

Comments
 (0)