示例#1
0
文件: main.go 项目: rjkroege/go
func main() {
	log.SetFlags(0)
	log.SetPrefix("editinacme: ")
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: editinacme file\n")
		os.Exit(2)
	}
	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
	}

	file := flag.Arg(0)
	_, err := os.Stat(file)
	if err != nil {
		log.Fatal(err)
	}

	fullpath, err := filepath.Abs(file)
	if err != nil {
		log.Fatal(err)
	}
	file = fullpath

	r, err := acme.Log()
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("editing %s", file)

	out, err := exec.Command("plumb", "-d", "edit", file).CombinedOutput()
	if err != nil {
		log.Fatalf("executing plumb: %v\n%s", err, out)
	}

	for {
		ev, err := r.Read()
		if err != nil {
			log.Fatalf("reading acme log: %v", err)
		}
		if ev.Op == "del" && ev.Name == file {
			break
		}
	}
}
示例#2
0
文件: main.go 项目: aoeu/acme
func main() {
	flag.Parse()
	l, err := acme.Log()
	if err != nil {
		log.Fatal(err)
	}

	for {
		event, err := l.Read()
		if err != nil {
			log.Fatal(err)
		}
		if event.Name != "" && event.Op == "put" && strings.HasSuffix(event.Name, ".go") {
			reformat(event.ID, event.Name)
		}
	}
}