(ctx *snap.Context)
| 720 | } |
| 721 | |
| 722 | func selectSymlinkSource(ctx *snap.Context) (string, error) { |
| 723 | root, err := os.Getwd() |
| 724 | if err != nil { |
| 725 | return "", fmt.Errorf("determine working directory: %w", err) |
| 726 | } |
| 727 | |
| 728 | options, err := gatherSymlinkOptions(root) |
| 729 | if err != nil { |
| 730 | return "", fmt.Errorf("gather symlink options: %w", err) |
| 731 | } |
| 732 | |
| 733 | options = append(options, symlinkOption{ |
| 734 | Label: "Enter custom path…", |
| 735 | Custom: true, |
| 736 | }) |
| 737 | |
| 738 | idx, err := fuzzyfinder.Find( |
| 739 | options, |
| 740 | func(i int) string { |
| 741 | return options[i].Label |
| 742 | }, |
| 743 | fuzzyfinder.WithPromptString("symlink source> "), |
| 744 | ) |
| 745 | if err != nil { |
| 746 | if errors.Is(err, fuzzyfinder.ErrAbort) { |
| 747 | return "", errSymlinkSelectionAborted |
| 748 | } |
| 749 | return "", fmt.Errorf("select original path: %w", err) |
| 750 | } |
| 751 | |
| 752 | selected := options[idx] |
| 753 | if selected.Custom { |
| 754 | return promptCustomSymlinkPath(ctx.Stdout(), ctx.Stdin()) |
| 755 | } |
| 756 | return selected.Path, nil |
| 757 | } |
| 758 | |
| 759 | func gatherSymlinkOptions(root string) ([]symlinkOption, error) { |
| 760 | var options []symlinkOption |
no test coverage detected