main.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
  2. // license. Its contents can be found at:
  3. // http://creativecommons.org/publicdomain/zero/1.0/
  4. package main
  5. import (
  6. "flag"
  7. "fmt"
  8. bindata "gitea.ckfah.com/go-script/internal"
  9. "os"
  10. "path/filepath"
  11. "regexp"
  12. "strings"
  13. )
  14. func main() {
  15. cfg := parseArgs()
  16. err := bindata.Translate(cfg)
  17. if err != nil {
  18. fmt.Fprintf(os.Stderr, "bindata: %v\n", err)
  19. os.Exit(1)
  20. }
  21. }
  22. // parseArgs create s a new, filled configuration instance
  23. // by reading and parsing command line options.
  24. //
  25. // This function exits the program with an error, if
  26. // any of the command line options are incorrect.
  27. func parseArgs() *bindata.Config {
  28. var version bool
  29. c := bindata.NewConfig()
  30. flag.Usage = func() {
  31. fmt.Printf("Usage: %s [options] <input directories>\n\n", os.Args[0])
  32. flag.PrintDefaults()
  33. }
  34. flag.BoolVar(&c.Debug, "debug", c.Debug, "Do not embed the assets, but provide the embedding API. Contents will still be loaded from disk.")
  35. 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.")
  36. flag.StringVar(&c.Tags, "tags", c.Tags, "Optional set of build tags to include.")
  37. flag.StringVar(&c.Prefix, "prefix", c.Prefix, "Optional path prefix to strip off asset names.")
  38. flag.StringVar(&c.Package, "pkg", c.Package, "Package name to use in the generated code.")
  39. 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.")
  40. flag.BoolVar(&c.NoCompress, "nocompress", c.NoCompress, "Assets will *not* be GZIP compressed when this flag is specified.")
  41. flag.BoolVar(&c.NoMetadata, "nometadata", c.NoMetadata, "Assets will not preserve size, mode, and modtime info.")
  42. flag.BoolVar(&c.HttpFileSystem, "fs", c.HttpFileSystem, "Whether generate instance http.FileSystem interface code.")
  43. flag.UintVar(&c.Mode, "mode", c.Mode, "Optional file mode override for all files.")
  44. flag.Int64Var(&c.ModTime, "modtime", c.ModTime, "Optional modification unix timestamp override for all files.")
  45. flag.StringVar(&c.Output, "o", c.Output, "Optional name of the output file to be generated.")
  46. flag.BoolVar(&version, "version", false, "Displays version information.")
  47. ignore := make([]string, 0)
  48. flag.Var((*bindata.AppendSliceValue)(&ignore), "ignore", "Regex pattern to ignore")
  49. flag.Parse()
  50. patterns := make([]*regexp.Regexp, 0)
  51. for _, pattern := range ignore {
  52. patterns = append(patterns, regexp.MustCompile(pattern))
  53. }
  54. c.Ignore = patterns
  55. if version {
  56. fmt.Printf("%s\n", bindata.Version())
  57. os.Exit(0)
  58. }
  59. // Make sure we have input paths.
  60. if flag.NArg() == 0 {
  61. fmt.Fprintf(os.Stderr, "Missing <input dir>\n\n")
  62. flag.Usage()
  63. os.Exit(1)
  64. }
  65. // Create input configurations.
  66. c.Input = make([]bindata.InputConfig, flag.NArg())
  67. for i := range c.Input {
  68. c.Input[i] = parseInput(flag.Arg(i))
  69. }
  70. return c
  71. }
  72. // parseRecursive determines whether the given path has a recursive indicator and
  73. // returns a new path with the recursive indicator chopped off if it does.
  74. //
  75. // ex:
  76. // /path/to/foo/... -> (/path/to/foo, true)
  77. // /path/to/bar -> (/path/to/bar, false)
  78. func parseInput(path string) bindata.InputConfig {
  79. if strings.HasSuffix(path, "/...") {
  80. return bindata.InputConfig{
  81. Path: filepath.Clean(path[:len(path)-4]),
  82. Recursive: true,
  83. }
  84. } else {
  85. return bindata.InputConfig{
  86. Path: filepath.Clean(path),
  87. Recursive: false,
  88. }
  89. }
  90. }