console-rs / dialoguer

Rust utility library for nice command line prompts and similar things
MIT License
1.33k stars 142 forks source link

Add `validate_with` function to password prompt #219

Closed qt2 closed 1 year ago

qt2 commented 2 years ago

Closes #150

Implement validation function in Password which would be useful for checking the strength of passwords. This PR includes:

smbcloudXYZ commented 1 year ago

Are you still working on this? I check the test it's failing

qt2 commented 1 year ago

Are you still working on this? I check the test it's failing

Sorry for the late reply. The test failure was due to an incorrectly configured import in doc-test. I will fix it and commit it later. Thank you for pointing this out.

qt2 commented 1 year ago

@pksunkara

In order for interact_on to function without mut, the validator needs Fn instead of FnMut, so a new PasswordValidator trait was added separately from the Validator for Input. Also replaced &String with &str where possible.

pksunkara commented 1 year ago

You don't need a password validator trait and the String -> str. I won't be merging them. Please keep it similar to Input except for the mut part.

qt2 commented 1 year ago

@pksunkara

Hmm, I have no idea using V::Err in validate_with method. Simply adopting your change suggestion raised an error "associated type Err not found for V". Could you tell me some workaround on it, if possible?

qt2 commented 1 year ago

If using E instead of V::Err is fine, then I'll revert the last commit.

pksunkara commented 1 year ago

I was mistaken, Input has a trait already. So, this trait is okay with me.

The only change I would request is to keep the original &String and not &str. The validate function should be dealing in &T where T is the output of the prompt, which is String in the password prompt.

smbcloudXYZ commented 1 year ago

Hey @pksunkara, how's the release process for this?

pksunkara commented 1 year ago

Done.