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

Function selectSymlinkSource

main.go:722–757  ·  view source on GitHub ↗
(ctx *snap.Context)

Source from the content-addressed store, hash-verified

720}
721
722func 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
759func gatherSymlinkOptions(root string) ([]symlinkOption, error) {
760 var options []symlinkOption

Callers 1

mainFunction · 0.85

Calls 2

gatherSymlinkOptionsFunction · 0.85
promptCustomSymlinkPathFunction · 0.85

Tested by

no test coverage detected