Use args.force, not args.f #16

Merged
mig5 merged 1 commits from mig/fix-args-force into main 2025-11-17 14:56:01 +00:00
mig5 commented 2025-11-17 03:13:06 +00:00 (Migrated from github.com)

I tried to remove a directory without -r and I got this error:

user@vpn-ssh:~/git$ rm foo
Traceback (most recent call last):
  File "/home/user/venv-resrm/bin/resrm", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/user/venv-resrm/lib/python3.13/site-packages/resrm/core.py", line 435, in main
    if args.f:
       ^^^^^^
AttributeError: 'Namespace' object has no attribute 'f'

It turns out that in argparse, if you have two flags for the same attribute (e.g -f and --force), argparse favours the 'longest' attribute name. So only args.force works, not args.f.

I tried to remove a directory without -r and I got this error: ``` user@vpn-ssh:~/git$ rm foo Traceback (most recent call last): File "/home/user/venv-resrm/bin/resrm", line 8, in <module> sys.exit(main()) ~~~~^^ File "/home/user/venv-resrm/lib/python3.13/site-packages/resrm/core.py", line 435, in main if args.f: ^^^^^^ AttributeError: 'Namespace' object has no attribute 'f' ``` It turns out that in argparse, if you have two flags for the same attribute (e.g `-f` and `--force`), argparse favours the 'longest' attribute name. So only `args.force` works, not `args.f`.
mdaleo404 (Migrated from github.com) approved these changes 2025-11-17 14:55:47 +00:00
mdaleo404 (Migrated from github.com) left a comment

Yes, thank you! This was on my list of "To-Do" but it always lost priority.
Merging...

Yes, thank you! This was on my list of "To-Do" but it always lost priority. Merging...
Sign in to join this conversation.