writeConfigFile writes .taskmd.yaml to the project root.
(root, taskDirPath string, idStrategy idStrategyConfig, quiet bool)
| 632 | |
| 633 | // writeConfigFile writes .taskmd.yaml to the project root. |
| 634 | func writeConfigFile(root, taskDirPath string, idStrategy idStrategyConfig, quiet bool) (created bool, err error) { |
| 635 | configPath := filepath.Join(root, configFilename) |
| 636 | |
| 637 | if !projectInitForce { |
| 638 | if _, err := os.Stat(configPath); err == nil { |
| 639 | if !quiet { |
| 640 | abs, _ := filepath.Abs(configPath) |
| 641 | fmt.Fprintf(os.Stderr, "Skipped %s (already exists, use --force to overwrite)\n", abs) |
| 642 | } |
| 643 | return false, nil |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | content := fmt.Sprintf("dir: %s\n", taskDirPath) |
| 648 | content += buildIDConfigYAML(idStrategy) |
| 649 | |
| 650 | if err := os.WriteFile(configPath, []byte(content), 0644); err != nil { |
| 651 | return false, fmt.Errorf("failed to write %s: %w", configFilename, err) |
| 652 | } |
| 653 | return true, nil |
| 654 | } |
| 655 | |
| 656 | // buildIDConfigYAML returns the id: section for .taskmd.yaml. |
| 657 | // Returns empty string for the default sequential strategy. |
no test coverage detected