Skip to content

Commit

Permalink
convert: strip prefix in source list
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinburke committed Dec 28, 2020
1 parent 8119cf9 commit 4e1720f
Show file tree
Hide file tree
Showing 3 changed files with 357 additions and 5 deletions.
10 changes: 5 additions & 5 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func Translate(c *Config) error {
return err
}

var knownFuncs = make(map[string]int)
var visitedPaths = make(map[string]bool)
knownFuncs := make(map[string]int)
visitedPaths := make(map[string]bool)
// Locate all the assets.
for _, input := range c.Input {
if err := findFiles(input.Path, c.Prefix, input.Recursive, &toc, c.Ignore, knownFuncs, visitedPaths); err != nil {
Expand Down Expand Up @@ -54,6 +54,8 @@ func Translate(c *Config) error {
if err != nil {
return err
}
relative = strings.TrimPrefix(relative, c.Prefix)
relative = strings.TrimPrefix(relative, "/")
if _, err = fmt.Fprintf(buf, "// %s (%s)\n", filepath.ToSlash(relative), bits(asset.Size)*byte_); err != nil {
return err
}
Expand Down Expand Up @@ -223,9 +225,7 @@ func findFiles(dirOrFile, prefix string, recursive bool, toc *[]Asset, ignore []
}

// If we have a leading slash, get rid of it.
if len(asset.Name) > 0 && asset.Name[0] == '/' {
asset.Name = asset.Name[1:]
}
asset.Name = strings.TrimPrefix(asset.Name, "/")

// This shouldn't happen.
if len(asset.Name) == 0 {
Expand Down
3 changes: 3 additions & 0 deletions testdata/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ out/nocompress-memcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
out/nocompress-nomemcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
GO_BINDATA_TEST=true $(GOPATH)/bin/go-bindata --modtime=1136214245 --nocompress -nomemcopy -o $@ in/...

out/prefix.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
GO_BINDATA_TEST=true $(GOPATH)/bin/go-bindata --modtime=1136214245 --prefix in -o $@ in/...

errcheck:
go get github.com/kisielk/errcheck

Expand Down
349 changes: 349 additions & 0 deletions testdata/out/prefix.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4e1720f

Please sign in to comment.