Closed logicminds closed 3 years ago
I think this might be a problem with your regexp. That regexp matches any string because every element of it is optional. If you put ^
at the start and $
at the end, it should work:
roi.flag :usdcost, desc: 'The USD Cost of the equipment ie. 428.0', type: Float, must_match: /^\$?\d*\.?\d{0,2}$/
# ^ ^
# | |
# | |
# | |
The updated regex did the trick. The error message is not helpful to the user though. Is there a way to override the default error message?
error: invalid argument: --usdcost=$
Agreed it's not a great error message. It's tricky to improve because GLI defers this part of the parsing to Ruby's OptionParser
which is what is generating that error message.
Closing as original issue is not an issue. Feel free to open a new one about the not-very-good error message
Example of GLI command
cb coins roi --hashrate=54mh --power=130 --usdcost=$428.00
Example of associated flag
roi.flag :usdcost, desc: 'The USD Cost of the equipment ie. 428.0', type: Float, must_match: /\$?\d*\.?\d{0,2}/
Expectation
GLI would throw and exception or error that the provided value does not match the pattern. Without this $428 is a string when it should be a float.
Even changing the type to a String does not yield anything different.