MCPcopy
hub / github.com/wavetermdev/waveterm / FormatGoFile

Function FormatGoFile

pkg/waveappstore/waveappstore.go:409–439  ·  view source on GitHub ↗
(appId string, fileName string)

Source from the content-addressed store, hash-verified

407}
408
409func FormatGoFile(appId string, fileName string) error {
410 if err := ValidateAppId(appId); err != nil {
411 return fmt.Errorf("invalid appId: %w", err)
412 }
413
414 appDir, err := GetAppDir(appId)
415 if err != nil {
416 return err
417 }
418
419 filePath, err := validateAndResolveFilePath(appDir, fileName)
420 if err != nil {
421 return err
422 }
423
424 if filepath.Ext(filePath) != ".go" {
425 return fmt.Errorf("file is not a Go file: %s", fileName)
426 }
427
428 gofmtPath, err := waveapputil.ResolveGoFmtPath()
429 if err != nil {
430 return fmt.Errorf("failed to resolve gofmt path: %w", err)
431 }
432
433 cmd := exec.Command(gofmtPath, "-w", filePath)
434 if output, err := cmd.CombinedOutput(); err != nil {
435 return fmt.Errorf("gofmt failed: %w\nOutput: %s", err, string(output))
436 }
437
438 return nil
439}
440
441func ListAllAppFiles(appId string) (*fileutil.ReadDirResult, error) {
442 if err := ValidateAppId(appId); err != nil {

Callers 1

Calls 5

ResolveGoFmtPathFunction · 0.92
ValidateAppIdFunction · 0.85
GetAppDirFunction · 0.85
CombinedOutputMethod · 0.80

Tested by

no test coverage detected