func setup(t *testing.T) { conf = myConf{} err := cfgp.Parse(&conf) if err != nil { t.Fatal("unable to parse configuration", err) } SetupLoggers(os.Stderr) }
func main() { c := Conf{} err := cfgp.Parse(&c) if err != nil { log.Fatal("Unable to parse configuration", err) } if c.Version { fmt.Println("to-laser - jscut post processor for Grbl laser cutters", Version, BuildTime) return } toPlunge := false toRetract := false s := bufio.NewScanner(os.Stdin) for s.Scan() { line := s.Text() if toPlunge { p, err := parsePower(c.Power) if err != nil { log.Fatalln(err) } fmt.Println(laserOnGcode, p) fmt.Println(delayGcode) toPlunge = false } if toRetract { fmt.Println(laserOffGcode) toRetract = false } matched, err := regexp.MatchString(plungeComment, line) if err != nil { log.Fatalln(err) } if matched { toPlunge = true continue } matched, err = regexp.MatchString(retractComment, line) if err != nil { log.Fatalln(err) } if matched { toRetract = true continue } // If line contains moves on Z axis skip it. matched, err = regexp.MatchString(".*Z.*", line) if err != nil { log.Fatalln(err) } if matched { continue } fmt.Println(line) } // Error parsing stdin. if err := s.Err(); err != nil { log.Fatalln(err) } // The End fmt.Println("M2") }
func main() { conf = myConf{ OutDir: "./out", } err := cfgp.Parse(&conf) if err != nil { log.Fatal("parsing configuration:", err) } if conf.Version { log.Fatalf("%s %s", Version, BuildTime) } SetupLoggers(os.Stdout) InfoLogger.Println("starting...") var r io.ReadCloser if conf.Csv != "" { r, err = os.Open(conf.Csv) if err != nil { log.Fatal("opening csv file:", err) } defer r.Close() } else { r = os.Stdin } nodes, err := GetData(r) if err != nil { log.Fatal("retrieving data:", err) } var dirName string // FIXME use filepath.Join if conf.Name != "" { dirName = fmt.Sprintf("%s/%s", conf.OutDir, conf.Name) } else { dirName = fmt.Sprintf("%s/%s", conf.OutDir, time.Now().Format("02-01-2006_15_04_05")) } err = os.MkdirAll(dirName, 0755) if err != nil { log.Fatal("creating folder:", err) } jsonW, err := os.Create(dirName + "/data.json") if err != nil { log.Fatal("writing json file:", err) } defer jsonW.Close() err = WriteData(jsonW, nodes) if err != nil { log.Fatal("writing json file:", err) } indexAvatarW, err := os.Create(dirName + "/index_avatar.html") if err != nil { log.Fatal("writing index_avatar.html:", err) } defer indexAvatarW.Close() err = createIndexWithAvatar(indexAvatarW) if err != nil { log.Fatal("writing index_avatar.html:", err) } indexGroupsW, err := os.Create(dirName + "/index_groups.html") if err != nil { log.Fatal("writing index_groups.html:", err) } defer indexGroupsW.Close() err = createIndexWithGroups(indexGroupsW) if err != nil { log.Fatal("writing index_groups.html:", err) } }