Add manual import feature
If goimpl chooses wrong import then use manual import feature to avoid
the issue.
@@ -12,16 +12,17 @@ import (
func printUsage() {
fmt.Fprintf(os.Stderr, strings.Join([]string{
- "goimpl <file> <impl-package> <impl-struct> <interface>",
+ "goimpl <file> <impl-package> <impl-struct> <interface> [<import>..]",
"",
"Example:",
" goimpl blockbase.go test BlockBase module.Block",
+ " goimpl chainbase.go test ChainBase module.Chain \"github.com/icon-project/goloop/common/log\"",
"",
}, "\n"))
}
func main() {
- if len(os.Args) != 5 {
+ if len(os.Args) < 5 {
printUsage()
os.Exit(1)
}
@@ -29,6 +30,7 @@ func main() {
pkg := os.Args[2]
strt := os.Args[3]
inf := os.Args[4]
+ imps := os.Args[5:]
cmd := exec.Command("go",
"run",
"github.com/josharian/impl",
@@ -43,10 +45,13 @@ func main() {
lines := strings.Join([]string{
"// Code generated by go generate; DO NOT EDIT.",
"package %s",
+ "import (",
+ "%s",
+ ")",
"type %s struct{}",
"%s",
}, "\n")
- out := fmt.Sprintf(lines, pkg, strt, cout)
+ out := fmt.Sprintf(lines, pkg, strings.Join(imps, "\n"), strt, cout)
iout, err := imports.Process("", []byte(out), nil)
if err != nil {
