app: fix boolean handling in argparse module
There was a complaint that tarantoolctl --show-system option is very hard to use. It incorrectly parsed passed values, and provided strange errors. tarantoolctl cat --show-system true Bad input for parameter "show-system". Expected boolean, got "true" tarantoolctl cat --show-system 1 Bad input for parameter "show-system". Expected boolean, got "1" tarantoolctl cat --show-system=true Bad input for parameter "show-system". Expected boolean, got "true" First of all, appeared that the complaining people didn't read documentation in 'tarantoolctl --help'. It explicitly says, that '--show-system' should go after a file name, and does not have a value. Secondly, even having taken the documentation into account, the errors indeed look ridiculous. 'Expected boolean, got "true"' looks especially weird. The problem appeared to be with argparse module, how it parses boolean parameters, and how stores parameter values not specified in a command line. All parameters were parsed into a dictionary: parameter name -> value. If a name is alone (no value), then it is boolean true. Otherwise it was always a string value. An attempt to specify an explicit parameter value 'true' led to storing string 'true' in that dictionary. Consequential check for boolean parameters was trivial: type(value) == 'boolean', which was obviously wrong, and didn't pass for 'true' string, but passed for an empty value. Closes #4076 (cherry picked from commit 03f85d4c)
Showing
- src/lua/argparse.lua 13 additions, 5 deletionssrc/lua/argparse.lua
- test/app/argparse.result 15 additions, 4 deletionstest/app/argparse.result
- test/app/argparse.test.lua 4 additions, 0 deletionstest/app/argparse.test.lua
- test/app/gh-4076-argparse-wrong-bool-handling.result 58 additions, 0 deletionstest/app/gh-4076-argparse-wrong-bool-handling.result
- test/app/gh-4076-argparse-wrong-bool-handling.test.lua 20 additions, 0 deletionstest/app/gh-4076-argparse-wrong-bool-handling.test.lua
Loading
Please register or sign in to comment