Use autogen

This commit is contained in:
Eyal Posener 2020-05-10 06:04:42 +03:00
parent 0b15fb4d6e
commit 1f0264a9ce
5 changed files with 13 additions and 44 deletions

View File

@ -1,3 +1,5 @@
// Autogenerated by go run compflag/gen/main.go. DO NOT EDIT.
package compflag
import (
@ -8,10 +10,6 @@ import (
"github.com/posener/complete/v2/predict"
)
// Code auto generated with `go run ./gen`. DO NOT EDIT
//go:generate go run ./gen
// String if a flag function for a flag of type string.
func String(name string, value string, usage string, options ...predict.Option) *string {
return CommandLine.String(name, value, usage, options...)

View File

@ -1,10 +1,5 @@
package compflag
// Code auto generated with `go run ./gen`. DO NOT EDIT
//go:generate go run ./gen
{{ range . }}
// {{ .Name }} if a flag function for a flag of type {{ .Type }}.

View File

@ -3,15 +3,12 @@ package main
import (
"log"
"os"
"path/filepath"
"strings"
"text/template"
"github.com/posener/script"
"github.com/posener/autogen"
)
const tmplGlob = "gen/*.go.gotmpl"
//go:generate go run .
type flag struct {
Name string
@ -35,33 +32,9 @@ var flags = []flag{
{Name: "Duration", Type: "time.Duration"},
}
var tmpl = template.Must(template.ParseGlob(tmplGlob))
func main() {
for _, t := range tmpl.Templates() {
fileName := outFileName(t.Name())
f, err := os.Create(fileName)
if err != nil {
panic(err)
}
defer f.Close()
log.Printf("Writing %s", fileName)
err = t.Execute(f, flags)
if err != nil {
panic(err)
}
// Format the file.
err = script.ExecHandleStderr(os.Stderr, "goimports", "-w", fileName).ToStdout()
if err != nil {
panic(err)
}
err := autogen.Execute(flags)
if err != nil {
log.Fatal(err)
}
}
func outFileName(templateName string) string {
name := filepath.Base(templateName)
// Remove .gotmpl suffix.
return name[:strings.LastIndex(name, ".")]
}

3
go.mod
View File

@ -2,7 +2,8 @@ module github.com/posener/complete/v2
require (
github.com/hashicorp/go-multierror v1.0.0
github.com/posener/script v1.0.4
github.com/posener/autogen v0.0.2
github.com/posener/script v1.1.5
github.com/stretchr/testify v1.4.0
)

6
go.sum
View File

@ -8,8 +8,10 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/script v1.0.4 h1:nSuXW5ZdmFnQIueLB2s0qvs4oNsUloM1Zydzh75v42w=
github.com/posener/script v1.0.4/go.mod h1:Rg3ijooqulo05aGLyGsHoLmIOUzHUVK19WVgrYBPU/E=
github.com/posener/autogen v0.0.2 h1:Mw3UF18XT0eIG8Vu5SSFfHfNXNuuGowdyNP20UlB9pU=
github.com/posener/autogen v0.0.2/go.mod h1:23ND5WRzjjNM+lOMUvy4WudgDikSK3Sm0rmaXAfnIWo=
github.com/posener/script v1.1.5 h1:su+9YHNlevT+Hlq2Xul5skh5kYDIBE+x4xu+5mLDT9o=
github.com/posener/script v1.1.5/go.mod h1:Rg3ijooqulo05aGLyGsHoLmIOUzHUVK19WVgrYBPU/E=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=