MCPcopy Create free account
hub / github.com/nikivdev/go / promptCustomSymlinkPath

Function promptCustomSymlinkPath

main.go:807–833  ·  view source on GitHub ↗
(out io.Writer, in io.Reader)

Source from the content-addressed store, hash-verified

805}
806
807func 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
835func expandUserPath(path string) (string, error) {
836 path = strings.TrimSpace(path)

Callers 1

selectSymlinkSourceFunction · 0.85

Calls 1

expandUserPathFunction · 0.70

Tested by

no test coverage detected