// Custom gets input and calls the given test function with the input to // check if the input is valid, a true return will return the string. func Custom(prefix string, test func(string) (string, bool)) (string, error) { var err error line := "" ok := false term, err := NewTerminal() if err != nil { return "", err } defer term.Close() for !ok { line, err = term.Prompt(prefix + ": ") if err != nil && err != io.EOF { se := errors.IsStackError(err) if se == nil || se.Err != io.EOF { return "", err } } line, ok = test(line) } return line, nil }
// Password retrieves a password from stdin without echoing it. func Password(prefix string) (string, error) { var err error line := "" term, err := NewTerminal() if err != nil { return "", err } defer term.Close() for line == "" { line, err = term.Password(prefix + ": ") if err != nil && err != io.EOF { se := errors.IsStackError(err) if se == nil || se.Err != io.EOF { return "", err } } if line == "" { log.Fprintln(os.Stderr, "red", prefix, errors.ErrEmpty) } } return line, nil }
// wrapErr wraps an error with the given service name. func (watcher *Watcher) wrapErr(err error) error { if err == nil { return nil } se := errors.IsStackError(err) if se != nil { se.Err = errors.Newf(errors.ErrSyncTmpl, watcher.Service.Name, se.Err) return se } return errors.Newf(errors.ErrSyncTmpl, watcher.Service.Name, err) }