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

Function workspaceAddPath

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

Source from the content-addressed store, hash-verified

345}
346
347func workspaceAddPath(ctx *snap.Context, doc *workspaceDocument, listKind workspaceList, rawPath, workspaceFile string) error {
348 pathValue := strings.TrimSpace(rawPath)
349 if pathValue == "" {
350 current, _ := os.Getwd()
351 reader := bufio.NewReader(ctx.Stdin())
352 value, err := promptWithDefault(ctx.Stdout(), reader, fmt.Sprintf("Path to add to %s", workspaceListLabels[listKind]), current)
353 if err != nil {
354 return err
355 }
356 pathValue = value
357 }
358
359 normalized, err := normalizeWorkspacePath(pathValue)
360 if err != nil {
361 return fmt.Errorf("normalize path: %w", err)
362 }
363
364 paths := doc.list(listKind)
365 if containsString(paths, normalized) {
366 fmt.Fprintf(ctx.Stdout(), "Path already present in %s: %s\n", workspaceListLabels[listKind], normalized)
367 return nil
368 }
369
370 paths = append(paths, normalized)
371 if err := doc.set(listKind, paths); err != nil {
372 return err
373 }
374 if err := doc.save(workspaceFile); err != nil {
375 return fmt.Errorf("save workspace: %w", err)
376 }
377
378 fmt.Fprintf(ctx.Stdout(), "Added to %s: %s\n", workspaceListLabels[listKind], normalized)
379 return nil
380}
381
382func workspaceRemovePath(ctx *snap.Context, doc *workspaceDocument, listKind workspaceList, rawPath, workspaceFile string) error {
383 paths := doc.list(listKind)

Callers 1

workspacePathsCmdFunction · 0.70

Calls 6

promptWithDefaultFunction · 0.70
normalizeWorkspacePathFunction · 0.70
containsStringFunction · 0.70
listMethod · 0.45
setMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected