MCPcopy
hub / github.com/jesseduffield/lazygit / CreateFileWithContent

Method CreateFileWithContent

pkg/commands/oscommands/os.go:159–178  ·  view source on GitHub ↗

CreateFileWithContent creates a file with the given content

(path string, content string)

Source from the content-addressed store, hash-verified

157
158// CreateFileWithContent creates a file with the given content
159func (c *OSCommand) CreateFileWithContent(path string, content string) error {
160 msg := utils.ResolvePlaceholderString(
161 c.Tr.Log.CreateFileWithContent,
162 map[string]string{
163 "path": path,
164 },
165 )
166 c.LogCommand(msg, false)
167 if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
168 c.Log.Error(err)
169 return err
170 }
171
172 if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
173 c.Log.Error(err)
174 return utils.WrapError(err)
175 }
176
177 return nil
178}
179
180// Remove removes a file or directory at the specified path
181func (c *OSCommand) Remove(filename string) error {

Callers 3

SaveTemporaryPatchMethod · 0.80
SwitchToEditorMethod · 0.80
RecordDirectoryMethod · 0.80

Calls 5

LogCommandMethod · 0.95
ResolvePlaceholderStringFunction · 0.92
WrapErrorFunction · 0.92
DirMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected