Skip to content

Commit

Permalink
Use autogen
Browse files Browse the repository at this point in the history
  • Loading branch information
posener committed May 10, 2020
1 parent 0b15fb4 commit 1f0264a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 44 deletions.
6 changes: 2 additions & 4 deletions compflag/flags.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Autogenerated by go run compflag/gen/main.go. DO NOT EDIT.

package compflag

import (
Expand All @@ -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...)
Expand Down
5 changes: 0 additions & 5 deletions compflag/gen/flags.go.gotmpl
Original file line number Diff line number Diff line change
@@ -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 }}.
Expand Down
37 changes: 5 additions & 32 deletions compflag/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 1f0264a

Please sign in to comment.