Error parsing arguments with multiple verbosity flags #716
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'm trying to do and why
Test multiple verbosity flags at once during development. (This came up while doing repros on #713.)
Steps to reproduce
Actual behavior
Expected behavior
The
createaction runs without argument parse errors.Other notes / implementation ideas
Environment
borgmatic version: main (this does not repro in 1.7.14)
borgmatic installation method: editable
Borg version: 1.2.4
Python version: 3.10.10
operating system and version: Manjaro stable
Localized the problem to
get_unparsable_arguments().. It's effectively dropping arguments as part of unique-ifying them. So interestingly this bug doesn't repro if all the verbosity values are different!Looking back at the PR where I proposed the approach to begin with, I guess I was onto something about this potentially breaking stuff....
Fixed.
The old approach was to get unparsable arguments after all actions parse args but before the global parser parses them. That could leave the global parser with deduped/uniqued arguments, which you didn't want if you had two flags (like
--verbosityand--log-file-verbosity) with the exact same value. Because that same duplicated value would get de-duplicated and then you'd have a bad time.The new approach is to still call that same
get_unparsable_arguments()function, but do it after all arguments have been parsed, including for each action and at the global level. Then,get_unparsable_arguments()still exists but strictly to find unknown arguments that no parser knows what to do with (e.g.,borgmatic --wtf). Then the deduplication doesn't matter. (If someone callsborgmatic --wtf --wtf, borgmatic will still error as expected.)Making this change though required several other changes like switching the global parser to using
parse_known_args()instead ofparse_args(), which itself had upstream implications on the construction of the parsers and even how--helpwas rendered.Long story short, I hate
argparseand this should be fixed now.Just released in borgmatic 1.7.15.