MCPcopy Create free account
hub / github.com/lxn/walk / processFile

Function processFile

tools/ui2walk/ui2walk.go:1236–1323  ·  view source on GitHub ↗
(uiFilePath string)

Source from the content-addressed store, hash-verified

1234}
1235
1236func processFile(uiFilePath string) error {
1237 goLogicFilePath := uiFilePath[:len(uiFilePath)-3] + ".go"
1238 goUIFilePath := uiFilePath[:len(uiFilePath)-3] + "_ui.go"
1239
1240 uiFileInfo, err := os.Stat(uiFilePath)
1241 if err != nil {
1242 return err
1243 }
1244
1245 goUIFileInfo, err := os.Stat(goUIFilePath)
1246 if !*forceUpdate && err == nil && !uiFileInfo.ModTime().After(goUIFileInfo.ModTime()) {
1247 // The go file should be up-to-date
1248 return nil
1249 }
1250
1251 fmt.Printf("Processing '%s'\n", uiFilePath)
1252 defer fmt.Println("")
1253
1254 uiFile, err := os.Open(uiFilePath)
1255 if err != nil {
1256 return err
1257 }
1258 defer uiFile.Close()
1259
1260 reader := bufio.NewReader(uiFile)
1261
1262 ui, err := parseUI(reader)
1263 if err != nil {
1264 return err
1265 }
1266
1267 goLogicFile, err := os.OpenFile(goLogicFilePath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0666)
1268 if err == nil {
1269 defer goLogicFile.Close()
1270
1271 buf := new(bytes.Buffer)
1272
1273 if err := generateLogicCode(buf, ui); err != nil {
1274 return err
1275 }
1276
1277 if _, err := io.Copy(goLogicFile, buf); err != nil {
1278 return err
1279 }
1280 if err := goLogicFile.Close(); err != nil {
1281 return err
1282 }
1283 }
1284
1285 goUIFile, err := os.Create(goUIFilePath)
1286 if err != nil {
1287 return err
1288 }
1289 defer goUIFile.Close()
1290
1291 buf := new(bytes.Buffer)
1292
1293 if err := generateUICode(buf, ui); err != nil {

Callers 1

processDirectoryFunction · 0.85

Calls 5

parseUIFunction · 0.85
generateLogicCodeFunction · 0.85
generateUICodeFunction · 0.85
CreateMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…