Python click: allow user to retry input upon validation failure
It can be a frustrating experience for a user if you naïvely reject their input without giving them another chance to correct their input, or know why it is wrong:
Using the above assign
command with a namer longer than 32 characters will cause the command to abort. This frustration compounds if the command takes multiple options, since the user may have already given input to several options, only to have to retry and enter it all over again.
Instead it is much better to let the user retry straightaway if their input fails:
The above implementation is better because:
- The user can try again any number of times (they can
CTRL-C
to abort) - The user is told why their input was rejected
- (As a bonus) the user can easily distinguish at a glance that it is an error because of the styling