Skip to content

Commit

Permalink
Merge pull request #640 from twpayne/trim-space
Browse files Browse the repository at this point in the history
Strip leading and trailing space from values read from user
  • Loading branch information
twpayne committed Mar 24, 2020
2 parents 96e0dea + bd78980 commit 453d152
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func (c *Config) prompt(s, choices string) (byte, error) {
if err != nil {
return 0, err
}
line = strings.TrimRight(line, "\r\n")
line = strings.TrimSpace(line)
if len(line) == 1 && strings.IndexByte(choices, line[0]) != -1 {
return line[0], nil
}
Expand Down
45 changes: 23 additions & 22 deletions cmd/docs.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,5 @@ func (c *Config) promptString(field string) string {
fmt.Fprintf(c.Stdout, "%s? ", field)
value, err := bufio.NewReader(c.Stdin).ReadString('\n')
panicOnError(err)
return strings.TrimRight(value, "\r\n")
return strings.TrimSpace(value)
}
4 changes: 2 additions & 2 deletions docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,8 @@ the same *pass-name* will only invoke `pass` once.
### `promptString` *prompt*

`promptString` takes a single argument is a string prompted to the user, and the
return value is the user's response to that prompt. It is only available when
generating the initial config file.
return value is the user's response to that prompt with all leading and trailing
space stripped. It is only available when generating the initial config file.

#### `promptString` examples

Expand Down

0 comments on commit 453d152

Please sign in to comment.