Merge pull request #15 from pblaszczyk/fix

Fix for handling prefix value and output not formatted according to go fmt.
This commit is contained in:
jimt 2014-01-03 12:11:32 -08:00
commit 37aa0dc02e
4 changed files with 22 additions and 5 deletions

View File

@ -9,7 +9,11 @@ import (
"io"
)
var newline = []byte{'\n'}
var (
newline = []byte{'\n'}
dataindent = []byte{'\t', '\t'}
space = []byte{' '}
)
type ByteWriter struct {
io.Writer
@ -24,7 +28,10 @@ func (w *ByteWriter) Write(p []byte) (n int, err error) {
for n = range p {
if w.c%12 == 0 {
w.Writer.Write(newline)
w.Writer.Write(dataindent)
w.c = 0
} else {
w.Writer.Write(space)
}
fmt.Fprintf(w.Writer, "0x%02x,", p[n])

View File

@ -21,7 +21,8 @@ func CreateTOC(dir, pkgname string) error {
// After startup of the program, all generated data files will
// put themselves in this map. The key is the full filename, as
// supplied to go-bindata.
var go_bindata = make(map[string]func() []byte)`, pkgname)
var go_bindata = make(map[string]func() []byte)
`, pkgname)
return ioutil.WriteFile(file, []byte(code), 0600)
}
@ -31,7 +32,6 @@ var go_bindata = make(map[string]func() []byte)`, pkgname)
func WriteTOCInit(output io.Writer, filename, prefix, funcname string) {
filename = strings.Replace(filename, prefix, "", 1)
fmt.Fprintf(output, `
func init() {
go_bindata[%q] = %s
}

View File

@ -62,7 +62,8 @@ func %s() []byte {
gz.Close()
return b.Bytes()
}`)
}
`)
}
// input -> gzip -> gowriter -> output.
@ -77,7 +78,8 @@ func %s() []byte {
fmt.Fprint(output, `
}
}`)
}
`)
}
// input -> gzip -> gowriter -> output.

View File

@ -11,6 +11,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
"unicode"
)
@ -90,7 +91,14 @@ func parseArgs() {
pipe = flag.NArg() == 0
if !pipe {
sepsuffix := false
if strings.HasSuffix(*prefix, string(filepath.Separator)) {
sepsuffix = true
}
*prefix, _ = filepath.Abs(filepath.Clean(*prefix))
if sepsuffix {
*prefix += string(filepath.Separator)
}
in, _ = filepath.Abs(filepath.Clean(flag.Args()[0]))
*out = safeFilename(*out, in)
}