bindata/go-bindata/main.go
Jim Teeuwen a36b3d3839 Adds the -r command line flag. This determines if the input
directory should be processed recursively or not. The default
is false.

Fixes the package to use this flag.

Revises the README and adds a docs.go file which holds
package documentation.
2013-10-30 16:08:29 +01:00

69 lines
2.0 KiB
Go

// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/
package main
import (
"flag"
"fmt"
"github.com/jteeuwen/go-bindata"
"os"
"path/filepath"
)
func main() {
cfg := parseArgs()
err := bindata.Translate(cfg)
if err != nil {
fmt.Fprintf(os.Stderr, "bindata: %v\n", err)
os.Exit(1)
}
}
// parseArgs create s a new, filled configuration instance
// by reading and parsing command line options.
//
// This function exits the program with an error, if
// any of the command line options are incorrect.
func parseArgs() *bindata.Config {
var version bool
c := bindata.NewConfig()
flag.Usage = func() {
fmt.Printf("Usage: %s [options] <input dir> [<output file>]\n\n", os.Args[0])
flag.PrintDefaults()
}
flag.BoolVar(&c.Debug, "debug", c.Debug, "Do not embed the assets, but provide the embedding API. Contents will still be loaded from disk.")
flag.StringVar(&c.Tags, "tags", c.Tags, "Optional set of uild tags to include.")
flag.StringVar(&c.Prefix, "prefix", c.Prefix, "Optional path prefix to strip off asset names.")
flag.StringVar(&c.Package, "pkg", c.Package, "Package name to use in the generated code.")
flag.BoolVar(&c.Recursive, "r", c.Recursive, "Recursive processing of the target directory and all its sub-directories.")
flag.BoolVar(&c.NoMemCopy, "nomemcopy", c.NoMemCopy, "Use a .rodata hack to get rid of unnecessary memcopies. Refer to the documentation to see what implications this carries.")
flag.BoolVar(&c.NoCompress, "nocompress", c.NoCompress, "Assets will *not* be GZIP compressed when this flag is specified.")
flag.BoolVar(&version, "version", false, "Displays version information.")
flag.Parse()
if version {
fmt.Printf("%s\n", Version())
os.Exit(0)
}
// Make sure we have in/output paths.
if flag.NArg() == 0 {
fmt.Fprintf(os.Stderr, "Missing input path.\n")
os.Exit(1)
}
c.Input = filepath.Clean(flag.Arg(0))
if flag.NArg() > 1 {
c.Output = filepath.Clean(flag.Arg(1))
}
return c
}