2013-10-29 15:17:14 +00:00
// 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 (
2013-10-29 17:23:52 +00:00
"flag"
2013-10-29 15:17:14 +00:00
"fmt"
2013-10-29 17:23:52 +00:00
"os"
"path/filepath"
2014-04-29 22:42:13 +00:00
"regexp"
2013-11-08 15:14:25 +00:00
"strings"
2015-01-26 23:45:06 +00:00
"github.com/jteeuwen/go-bindata"
2013-10-29 15:17:14 +00:00
)
func main ( ) {
2013-10-30 13:45:04 +00:00
cfg := parseArgs ( )
err := bindata . Translate ( cfg )
2013-10-29 17:23:52 +00:00
if err != nil {
2013-10-30 13:45:04 +00:00
fmt . Fprintf ( os . Stderr , "bindata: %v\n" , err )
2013-10-30 14:24:59 +00:00
os . Exit ( 1 )
2013-10-29 17:23:52 +00:00
}
}
// 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.
2013-10-30 13:45:04 +00:00
func parseArgs ( ) * bindata . Config {
var version bool
2013-10-29 17:23:52 +00:00
2013-10-30 01:11:04 +00:00
c := bindata . NewConfig ( )
2013-10-29 17:23:52 +00:00
flag . Usage = func ( ) {
2013-11-16 11:08:37 +00:00
fmt . Printf ( "Usage: %s [options] <input directories>\n\n" , os . Args [ 0 ] )
2013-10-29 17:23:52 +00:00
flag . PrintDefaults ( )
}
2013-10-30 13:45:04 +00:00
flag . BoolVar ( & c . Debug , "debug" , c . Debug , "Do not embed the assets, but provide the embedding API. Contents will still be loaded from disk." )
2015-01-26 23:45:06 +00:00
flag . BoolVar ( & c . Dev , "dev" , c . Dev , "Similar to debug, but does not emit absolute paths. Expects a rootDir variable to already exist in the generated code's package." )
2014-04-10 16:10:22 +00:00
flag . StringVar ( & c . Tags , "tags" , c . Tags , "Optional set of build tags to include." )
2013-10-30 13:45:04 +00:00
flag . StringVar ( & c . Prefix , "prefix" , c . Prefix , "Optional path prefix to strip off asset names." )
2013-10-30 01:11:04 +00:00
flag . StringVar ( & c . Package , "pkg" , c . Package , "Package name to use in the generated code." )
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." )
2013-10-30 13:45:04 +00:00
flag . BoolVar ( & c . NoCompress , "nocompress" , c . NoCompress , "Assets will *not* be GZIP compressed when this flag is specified." )
2015-03-10 14:41:54 +00:00
flag . UintVar ( & c . Mode , "mode" , c . Mode , "Optional file mode override for all files." )
flag . Int64Var ( & c . ModTime , "modtime" , c . ModTime , "Optional modification unix timestamp override for all files." )
2013-11-16 11:08:37 +00:00
flag . StringVar ( & c . Output , "o" , c . Output , "Optional name of the output file to be generated." )
2013-10-29 17:23:52 +00:00
flag . BoolVar ( & version , "version" , false , "Displays version information." )
2014-04-29 22:42:13 +00:00
ignore := make ( [ ] string , 0 )
flag . Var ( ( * AppendSliceValue ) ( & ignore ) , "ignore" , "Regex pattern to ignore" )
2013-10-29 17:23:52 +00:00
flag . Parse ( )
2014-04-29 22:42:13 +00:00
patterns := make ( [ ] * regexp . Regexp , 0 )
for _ , pattern := range ignore {
patterns = append ( patterns , regexp . MustCompile ( pattern ) )
}
c . Ignore = patterns
2013-10-29 17:23:52 +00:00
if version {
fmt . Printf ( "%s\n" , Version ( ) )
os . Exit ( 0 )
}
2013-11-16 11:19:19 +00:00
// Make sure we have input paths.
2013-10-29 17:23:52 +00:00
if flag . NArg ( ) == 0 {
2013-11-08 19:31:55 +00:00
fmt . Fprintf ( os . Stderr , "Missing <input dir>\n\n" )
flag . Usage ( )
2013-10-29 17:23:52 +00:00
os . Exit ( 1 )
}
2013-11-16 11:19:19 +00:00
// Create input configurations.
c . Input = make ( [ ] bindata . InputConfig , flag . NArg ( ) )
for i := range c . Input {
c . Input [ i ] = parseInput ( flag . Arg ( i ) )
}
2013-10-30 13:45:04 +00:00
return c
2013-10-29 15:17:14 +00:00
}
2013-11-08 15:14:25 +00:00
// parseRecursive determines whether the given path has a recrusive indicator and
// returns a new path with the recursive indicator chopped off if it does.
//
// ex:
// /path/to/foo/... -> (/path/to/foo, true)
// /path/to/bar -> (/path/to/bar, false)
func parseInput ( path string ) bindata . InputConfig {
if strings . HasSuffix ( path , "/..." ) {
2013-11-16 11:19:19 +00:00
return bindata . InputConfig {
Path : filepath . Clean ( path [ : len ( path ) - 4 ] ) ,
Recursive : true ,
}
2013-11-08 15:14:25 +00:00
} else {
2013-11-16 11:19:19 +00:00
return bindata . InputConfig {
Path : filepath . Clean ( path ) ,
Recursive : false ,
}
2013-11-08 15:14:25 +00:00
}
}