mitchellh / cli

A Go library for implementing command-line interfaces.
Mozilla Public License 2.0
1.73k stars 123 forks source link

Fix discrepancy between BasicUi and MockUi #71

Closed moorara closed 4 years ago

moorara commented 6 years ago

I noticed the Ask method on BasicUi type uses bufio.Reader.ReadString() whereas the Ask method on MockUi uses fmt.Fscanln for reading from Reader input. This causes two problems:

When using BasicUi, one can enter a string with spaces. However, in tests when using MockUi, reading a string with spaces only returns the first word. When using BasicUi, one can press Enter key and get a empty string back without any error, while using MockUi in tests returns an unexpected newline error.

This discrepancy between the actual implementation of Ask and the mocked implementation of Ask makes testing of the two cases mentioned above very hard.

This PR addresses this issue and make the actual and mocked implementation working the same way.

mitchellh commented 4 years ago

Thanks! Sorry this took so long.