(ctx context.Context, srcDir string, entry fs.DirEntry)
| 209 | } |
| 210 | |
| 211 | func readInput(ctx context.Context, srcDir string, entry fs.DirEntry) (input, bool, error) { |
| 212 | fullPath := filepath.Join(srcDir, entry.Name()) |
| 213 | if err := ensureContext(ctx, fmt.Sprintf("read %s", fullPath)); err != nil { |
| 214 | return input{}, false, err |
| 215 | } |
| 216 | if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".md") { |
| 217 | return input{}, false, nil |
| 218 | } |
| 219 | base := strings.TrimSuffix(entry.Name(), ".md") |
| 220 | segments, err := commandSegments(entry.Name(), base) |
| 221 | if err != nil { |
| 222 | return input{}, false, err |
| 223 | } |
| 224 | data, err := os.ReadFile(fullPath) |
| 225 | if err != nil { |
| 226 | return input{}, false, fmt.Errorf("docpost: read %s: %w", fullPath, err) |
| 227 | } |
| 228 | return input{ |
| 229 | fileName: entry.Name(), |
| 230 | baseName: base, |
| 231 | segments: segments, |
| 232 | raw: string(data), |
| 233 | }, true, nil |
| 234 | } |
| 235 | |
| 236 | func commandSegments(fileName string, base string) ([]string, error) { |
| 237 | if base == docpostAghKey { |
no test coverage detected