(ctx *snap.Context, doc *workspaceDocument, listKind workspaceList, rawPath, workspaceFile string)
| 345 | } |
| 346 | |
| 347 | func 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 | |
| 382 | func workspaceRemovePath(ctx *snap.Context, doc *workspaceDocument, listKind workspaceList, rawPath, workspaceFile string) error { |
| 383 | paths := doc.list(listKind) |
no test coverage detected