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

Function runAdd

apps/cli/internal/cli/add.go:98–148  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

96}
97
98func runAdd(cmd *cobra.Command, args []string) error {
99 title := args[0]
100
101 if err := validateAddEnums(); err != nil {
102 return err
103 }
104 if err := ValidateFormat(addFormat, []string{"plain", "json"}); err != nil {
105 return err
106 }
107
108 flags := GetGlobalFlags()
109 scanDir := ResolveScanDir(nil)
110
111 id, err := resolveNextID(scanDir, flags)
112 if err != nil {
113 return err
114 }
115
116 outputDir := scanDir
117 if addGroup != "" {
118 outputDir = filepath.Join(scanDir, addGroup)
119 }
120
121 suffix := addSlug
122 if suffix == "" {
123 suffix = slug.Slugify(title)
124 }
125 filePath := filepath.Join(outputDir, fmt.Sprintf("%s-%s.md", id, suffix))
126
127 content, err := resolveTaskContent(cmd, id, title)
128 if err != nil {
129 return err
130 }
131
132 if err := os.MkdirAll(outputDir, 0755); err != nil {
133 return fmt.Errorf("failed to create directory: %w", err)
134 }
135 if err := os.WriteFile(filePath, []byte(content), 0644); err != nil {
136 return fmt.Errorf("failed to write task file: %w", err)
137 }
138
139 if err := outputAddResult(id, title, filePath); err != nil {
140 return err
141 }
142
143 if addEdit {
144 return openInEditor(filePath)
145 }
146
147 return nil
148}
149
150func resolveNextID(scanDir string, flags GlobalFlags) (string, error) {
151 taskScanner := scanner.NewScanner(scanDir, flags.Verbose, flags.IgnoreDirs)

Callers 1

captureAddOutputFunction · 0.85

Calls 8

validateAddEnumsFunction · 0.85
ValidateFormatFunction · 0.85
GetGlobalFlagsFunction · 0.85
ResolveScanDirFunction · 0.85
resolveNextIDFunction · 0.85
resolveTaskContentFunction · 0.85
outputAddResultFunction · 0.85
openInEditorFunction · 0.85

Tested by 1

captureAddOutputFunction · 0.68