Exemplo n.º 1
0
func main() {
	err := instrument.InstrumentCmd(func(p *patch.PatchableFile) (patches patch.Patches) {
		for _, dec := range p.File.Decls {
			if fun, ok := dec.(*ast.FuncDecl); ok && fun.Name != nil && fun.Body != nil {
				patches = append(patches, patch.Insert(fun.Body.Lbrace+1, "println(`"+fun.Name.Name+"`);"))
			}
		}
		return patches
	}, os.Args...)
	if err != nil {
		println(err.Error())
		os.Exit(-1)
	}
}
Exemplo n.º 2
0
func main() {
	if len(os.Args) == 1 {
		usage()
		return
	}
	f := func(p *patch.PatchableFile) patch.Patches {
		patches := &visitors.PatchUnused{patch.Patches{}}
		autoimport := visitors.NewAutoImporter(p.File)
		scopes.WalkFile(visitors.NewMultiVisitor(visitors.NewUnused(patches), autoimport), p.File)
		return append(patches.Patches, autoimport.Patches...)
	}
	if err := instrument.InstrumentCmd(f, os.Args...); err != nil {
		fmt.Println(err)
		os.Exit(-1)
	}
}