MCPcopy Create free account
hub / github.com/driangle/taskmd / runSpec

Function runSpec

apps/cli/internal/cli/spec.go:47–88  ·  view source on GitHub ↗
(_ *cobra.Command, _ []string)

Source from the content-addressed store, hash-verified

45}
46
47func runSpec(_ *cobra.Command, _ []string) error {
48 if specStdout {
49 fmt.Print(string(specTemplate))
50 return nil
51 }
52
53 targetDir := GetGlobalFlags().TaskDir
54
55 // Verify target directory exists
56 info, err := os.Stat(targetDir)
57 if err != nil {
58 return fmt.Errorf("directory does not exist: %s", targetDir)
59 }
60 if !info.IsDir() {
61 return fmt.Errorf("not a directory: %s", targetDir)
62 }
63
64 outputPath := filepath.Join(targetDir, specFilename)
65
66 absPath, err := filepath.Abs(outputPath)
67 if err != nil {
68 absPath = outputPath
69 }
70
71 // Check if file exists
72 if !specForce {
73 if _, err := os.Stat(outputPath); err == nil {
74 return fmt.Errorf("%s already exists at %s (use --force to overwrite)", specFilename, absPath)
75 }
76 }
77
78 // Write the file
79 if err := os.WriteFile(outputPath, specTemplate, 0644); err != nil {
80 return fmt.Errorf("failed to write %s: %w", specFilename, err)
81 }
82
83 if !GetGlobalFlags().Quiet {
84 fmt.Printf("Created %s\n", absPath)
85 }
86
87 return nil
88}

Calls 1

GetGlobalFlagsFunction · 0.85