MCPcopy Index your code
hub / github.com/nikivdev/go / workspaceRemovePath

Function workspaceRemovePath

workspace.go:382–428  ·  view source on GitHub ↗
(ctx *snap.Context, doc *workspaceDocument, listKind workspaceList, rawPath, workspaceFile string)

Source from the content-addressed store, hash-verified

380}
381
382func workspaceRemovePath(ctx *snap.Context, doc *workspaceDocument, listKind workspaceList, rawPath, workspaceFile string) error {
383 paths := doc.list(listKind)
384 if len(paths) == 0 {
385 fmt.Fprintf(ctx.Stdout(), "No paths to remove from %s\n", workspaceListLabels[listKind])
386 return nil
387 }
388
389 target := strings.TrimSpace(rawPath)
390 if target == "" {
391 idx, err := fuzzyfinder.Find(
392 paths,
393 func(i int) string { return paths[i] },
394 fuzzyfinder.WithPromptString(fmt.Sprintf("remove from %s> ", workspaceListLabels[listKind])),
395 )
396 if err != nil {
397 if errors.Is(err, fuzzyfinder.ErrAbort) {
398 fmt.Fprintln(ctx.Stdout(), "Aborted.")
399 return nil
400 }
401 return fmt.Errorf("select path: %w", err)
402 }
403 target = paths[idx]
404 } else {
405 normalized, err := normalizeWorkspacePath(target)
406 if err == nil {
407 target = normalized
408 } else {
409 target = filepath.Clean(target)
410 }
411 }
412
413 filtered, removed := removeString(paths, target)
414 if !removed {
415 fmt.Fprintf(ctx.Stdout(), "Path not found in %s: %s\n", workspaceListLabels[listKind], target)
416 return nil
417 }
418
419 if err := doc.set(listKind, filtered); err != nil {
420 return err
421 }
422 if err := doc.save(workspaceFile); err != nil {
423 return fmt.Errorf("save workspace: %w", err)
424 }
425
426 fmt.Fprintf(ctx.Stdout(), "Removed from %s: %s\n", workspaceListLabels[listKind], target)
427 return nil
428}
429
430func containsString(list []string, candidate string) bool {
431 for _, v := range list {

Callers 1

workspacePathsCmdFunction · 0.70

Calls 5

normalizeWorkspacePathFunction · 0.70
removeStringFunction · 0.70
listMethod · 0.45
setMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected