Repository navigation
Conversation
askYN only accepted an answer when ReadString returned no error, and reprompted otherwise. Once stdin reaches EOF (e.g. `gmailctl apply </dev/null`, a background job or a CI runner), every subsequent read fails immediately with io.EOF, so the loop printed "invalid choice" and reprompted forever instead of exiting. askOptions, used by `gmailctl edit`, had the same problem: fmt.Scanln keeps returning io.EOF, which was treated like any other invalid input. Treat the end of input as the final answer: - askYN defaults to "no", the same as an empty line, so `apply` exits without changing anything. An answer typed without a trailing newline (e.g. `printf y | gmailctl apply`) is still honored, since that is clearly what the user meant. - askOptions returns an error, which `edit` turns into an abort. This leaves the original config untouched and prints where the edited copy was saved, exactly like choosing "abort". Choosing "no (continue editing)" instead would reopen the editor and hit the same EOF again. In both cases a newline is printed, so that what follows doesn't end up on the prompt line. The prompts now take their input and output streams as arguments, so this behavior is covered by unit tests. Close #464.
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (78.12%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #467 +/- ##
==========================================
+ Coverage 39.22% 41.37% +2.14%
==========================================
Files 54 54
Lines 3681 3693 +12
==========================================
+ Hits 1444 1528 +84
+ Misses 2136 2063 -73
- Partials 101 102 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
askYN only accepted an answer when ReadString returned no error, and reprompted otherwise. Once stdin reaches EOF (e.g.
gmailctl apply </dev/null, a background job or a CI runner), every subsequent read fails immediately with io.EOF, so the loop printed "invalid choice" and reprompted forever instead of exiting.askOptions, used by
gmailctl edit, had the same problem: fmt.Scanln keeps returning io.EOF, which was treated like any other invalid input.Treat the end of input as the final answer:
applyexits without changing anything. An answer typed without a trailing newline (e.g.printf y | gmailctl apply) is still honored, since that is clearly what the user meant.editturns into an abort. This leaves the original config untouched and prints where the edited copy was saved, exactly like choosing "abort". Choosing "no (continue editing)" instead would reopen the editor and hit the same EOF again.In both cases a newline is printed, so that what follows doesn't end up on the prompt line.
The prompts now take their input and output streams as arguments, so this behavior is covered by unit tests.
Close #464.