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

Method openFile

apps/cli/internal/cli/input.go:52–79  ·  view source on GitHub ↗

openFile opens a file and returns a reader and cleanup function

(filePath string)

Source from the content-addressed store, hash-verified

50
51// openFile opens a file and returns a reader and cleanup function
52func (ir *InputResolver) openFile(filePath string) (io.Reader, func() error, error) {
53 // Expand relative path to absolute
54 absPath, err := filepath.Abs(filePath)
55 if err != nil {
56 return nil, nil, fmt.Errorf("failed to resolve path %s: %w", filePath, err)
57 }
58
59 // Check if file exists
60 if _, err := os.Stat(absPath); os.IsNotExist(err) {
61 return nil, nil, fmt.Errorf("file not found: %s", absPath)
62 }
63
64 // Open the file
65 file, err := os.Open(absPath)
66 if err != nil {
67 return nil, nil, fmt.Errorf("failed to open file %s: %w", absPath, err)
68 }
69
70 if ir.verbose {
71 fmt.Fprintf(os.Stderr, "Reading from file: %s\n", absPath)
72 }
73
74 cleanup := func() error {
75 return file.Close()
76 }
77
78 return bufio.NewReader(file), cleanup, nil
79}
80
81// ReadAll reads all content from the resolved input source
82func (ir *InputResolver) ReadAll(args []string) ([]byte, error) {

Callers 1

ResolveInputMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected