Skip to content

Commit

Permalink
Merge pull request #58 from k1LoW/packr
Browse files Browse the repository at this point in the history
Use gobuffalo/packr
  • Loading branch information
k1LoW committed Nov 14, 2018
2 parents a8e653c + 0c674c9 commit cbbc905
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist/
*-packr.go
testdb.sqlite3
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ test:
cover: depsdev
GO111MODULE=on goveralls -service=travis-ci

template:
$(GO) generate

doc: build
./tbls doc pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -a test/additional_data.yml -f sample/postgres
./tbls doc my://root:mypass@localhost:33306/testdb -a test/additional_data.yml -f sample/mysql
Expand Down Expand Up @@ -56,8 +53,10 @@ test_too_many_tables: build
ulimit -n 256 && ./tbls doc pg://postgres:pgpass@localhost:55432/too_many?sslmode=disable -f /tmp
ulimit -n 256 && ./tbls diff pg://postgres:pgpass@localhost:55432/too_many?sslmode=disable /tmp

build: template
build:
packr
$(GO) build -ldflags="$(BUILD_LDFLAGS)"
packr clean

depsdev:
GO111MODULE=off go get golang.org/x/tools/cmd/cover
Expand All @@ -68,12 +67,14 @@ depsdev:
GO111MODULE=off go get github.com/tcnksm/ghr
GO111MODULE=off go get github.com/Songmu/ghch/cmd/ghch
GO111MODULE=off go get github.com/xo/usql
GO111MODULE=off go get github.com/jessevdk/go-assets-builder
GO111MODULE=off go get github.com/gobuffalo/packr/packr

crossbuild: depsdev
$(eval ver = v$(shell gobump show -r version/))
packr
GO111MODULE=on goxz -pv=$(ver) -arch=386,amd64 -build-ldflags="$(RELEASE_BUILD_LDFLAGS)" \
-d=./dist/$(ver)
packr clean

prerelease:
$(eval ver = v$(shell gobump show -r version/))
Expand Down
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
module github.com/k1LoW/tbls

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-sql-driver/mysql v1.4.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/gobuffalo/packr v1.20.0
github.com/jessevdk/go-assets v0.0.0-20160921144138-4f4301a06e15
github.com/lib/pq v0.0.0-20180523175426-90697d60dd84
github.com/mattn/go-runewidth v0.0.2
github.com/mattn/go-sqlite3 v1.9.0
github.com/pkg/errors v0.8.0
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.0.0
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.1 // indirect
github.com/stretchr/testify v1.2.2 // indirect
github.com/xo/dburl v0.0.0-20180921222126-e33971d4c132
google.golang.org/appengine v1.1.0 // indirect
gopkg.in/yaml.v2 v2.2.1
Expand Down
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/gobuffalo/envy v1.6.8 h1:ExvxBMO2VoANkwLkQcY8yTB73YkkIOfi9CyinoE+vyk=
github.com/gobuffalo/envy v1.6.8/go.mod h1:N+GkhhZ/93bGZc6ZKhJLP6+m+tCNPKwgSpH9kaifseQ=
github.com/gobuffalo/packd v0.0.0-20181111195323-b2e760a5f0ff h1:FFjrU4aPGxtiWlhmLdeqEGFcs17YJfJ/i3Zm+cO5fkQ=
github.com/gobuffalo/packd v0.0.0-20181111195323-b2e760a5f0ff/go.mod h1:Yf2toFaISlyQrr5TfO3h6DB9pl9mZRmyvBGQb/aQ/pI=
github.com/gobuffalo/packr v1.20.0 h1:XDHu3L931kHjr0v80vJ9hAxOMavbSpzuwAXDONsMYcM=
github.com/gobuffalo/packr v1.20.0/go.mod h1:JDytk1t2gP+my1ig7iI4NcVaXr886+N0ecUga6884zw=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jessevdk/go-assets v0.0.0-20160921144138-4f4301a06e15 h1:cW/amwGEJK5MSKntPXRjX4dxs/nGxGT8gXKIsKFmHGc=
github.com/jessevdk/go-assets v0.0.0-20160921144138-4f4301a06e15/go.mod h1:Fdm/oWRW+CH8PRbLntksCNtmcCBximKPkVQYvmMl80k=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/lib/pq v0.0.0-20180523175426-90697d60dd84 h1:it29sI2IM490luSc3RAhp5WuCYnc6RtbfLVAB7nmC5M=
github.com/lib/pq v0.0.0-20180523175426-90697d60dd84/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4 h1:Mlji5gkcpzkqTROyE4ZxZ8hN7osunMb2RuGVrbvMvCc=
github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/mattn/go-runewidth v0.0.2 h1:UnlwIPBGaTZfPQ6T1IGzPI0EkYAQmT9fAEJ/poFC63o=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-sqlite3 v1.9.0 h1:pDRiWfl+++eC2FEFRy6jXmQlvp4Yh3z1MJKg4UeYM/4=
Expand All @@ -20,9 +30,12 @@ github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/xo/dburl v0.0.0-20180921222126-e33971d4c132 h1:cRKJ4yZeCZbCEXJmjZMa9s2z+3eavo2a4qu/usvVopI=
github.com/xo/dburl v0.0.0-20180921222126-e33971d4c132/go.mod h1:g6rdekR8vgfVZrkLWfobLTm0kVez7GAN23mWtkGCJ14=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
24 changes: 12 additions & 12 deletions output/md/md.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"text/template"

"github.com/gobuffalo/packr"
"github.com/k1LoW/tbls/schema"
"github.com/mattn/go-runewidth"
"github.com/pkg/errors"
Expand All @@ -26,15 +27,16 @@ func Output(s *schema.Schema, path string, force bool, adjust bool, erFormat str
return fmt.Errorf("Error: %s", "output files already exists.")
}

box := packr.NewBox("./templates")

// README.md
file, err := os.Create(filepath.Join(fullPath, "README.md"))
defer file.Close()
if err != nil {
return errors.WithStack(err)
}
f, _ := Assets.Open(filepath.Join("/", "index.md.tmpl"))
bs, _ := ioutil.ReadAll(f)
tmpl := template.Must(template.New("index").Funcs(funcMap()).Parse(string(bs)))
ts, _ := box.FindString("index.md.tmpl")
tmpl := template.Must(template.New("index").Funcs(funcMap()).Parse(ts))
er := false
if _, err := os.Lstat(filepath.Join(fullPath, fmt.Sprintf("schema.%s", erFormat))); err == nil {
er = true
Expand All @@ -57,9 +59,8 @@ func Output(s *schema.Schema, path string, force bool, adjust bool, erFormat str
file.Close()
return errors.WithStack(err)
}
f, _ := Assets.Open(filepath.Join("/", "table.md.tmpl"))
bs, _ := ioutil.ReadAll(f)
tmpl := template.Must(template.New(t.Name).Funcs(funcMap()).Parse(string(bs)))
ts, _ := box.FindString("table.md.tmpl")
tmpl := template.Must(template.New(t.Name).Funcs(funcMap()).Parse(ts))
er := false
if _, err := os.Lstat(filepath.Join(fullPath, fmt.Sprintf("%s.%s", t.Name, erFormat))); err == nil {
er = true
Expand Down Expand Up @@ -91,13 +92,13 @@ func Diff(s *schema.Schema, path string, adjust bool, erFormat string) error {
return fmt.Errorf("Error: %s", "target files does not exists.")
}

box := packr.NewBox("./templates")
dmp := diffmatchpatch.New()

// README.md
a := new(bytes.Buffer)
f, _ := Assets.Open(filepath.Join("/", "index.md.tmpl"))
bs, _ := ioutil.ReadAll(f)
tmpl := template.Must(template.New("index").Funcs(funcMap()).Parse(string(bs)))
ts, _ := box.FindString("index.md.tmpl")
tmpl := template.Must(template.New("index").Funcs(funcMap()).Parse(ts))
er := false
if _, err := os.Lstat(filepath.Join(fullPath, fmt.Sprintf("schema.%s", erFormat))); err == nil {
er = true
Expand Down Expand Up @@ -129,9 +130,8 @@ func Diff(s *schema.Schema, path string, adjust bool, erFormat string) error {
// tables
for _, t := range s.Tables {
a := new(bytes.Buffer)
f, _ := Assets.Open(filepath.Join("/", "table.md.tmpl"))
bs, _ := ioutil.ReadAll(f)
tmpl := template.Must(template.New(t.Name).Funcs(funcMap()).Parse(string(bs)))
ts, _ := box.FindString("table.md.tmpl")
tmpl := template.Must(template.New(t.Name).Funcs(funcMap()).Parse(ts))
er := false
if _, err := os.Lstat(filepath.Join(fullPath, fmt.Sprintf("%s.%s", t.Name, erFormat))); err == nil {
er = true
Expand Down
29 changes: 0 additions & 29 deletions output/md/templates.go

This file was deleted.

0 comments on commit cbbc905

Please sign in to comment.