(out io.Writer, in io.Reader)
| 805 | } |
| 806 | |
| 807 | func promptCustomSymlinkPath(out io.Writer, in io.Reader) (string, error) { |
| 808 | reader := bufio.NewReader(in) |
| 809 | for { |
| 810 | fmt.Fprint(out, "Enter path to the original file: ") |
| 811 | line, err := reader.ReadString('\n') |
| 812 | if err != nil { |
| 813 | if errors.Is(err, io.EOF) { |
| 814 | if strings.TrimSpace(line) == "" { |
| 815 | return "", errSymlinkSelectionAborted |
| 816 | } |
| 817 | } else { |
| 818 | return "", fmt.Errorf("read path: %w", err) |
| 819 | } |
| 820 | } |
| 821 | path := strings.TrimSpace(line) |
| 822 | if path == "" { |
| 823 | fmt.Fprintln(out, "Path cannot be empty.") |
| 824 | continue |
| 825 | } |
| 826 | expanded, err := expandUserPath(path) |
| 827 | if err != nil { |
| 828 | fmt.Fprintf(out, "Invalid path: %v\n", err) |
| 829 | continue |
| 830 | } |
| 831 | return filepath.Clean(expanded), nil |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | func expandUserPath(path string) (string, error) { |
| 836 | path = strings.TrimSpace(path) |
no test coverage detected