From 6271d521f025dd19d11adef435b3b35af9b9ce10 Mon Sep 17 00:00:00 2001 From: JBD Date: Fri, 1 Nov 2019 15:01:49 -0700 Subject: [PATCH] Add more comprehensive help text. --- statik.go | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/statik.go b/statik.go index 9dc325e9..725db24c 100644 --- a/statik.go +++ b/statik.go @@ -36,22 +36,53 @@ const nameSourceFile = "statik.go" var namePackage string var ( - flagSrc = flag.String("src", path.Join(".", "public"), "The path of the source directory.") - flagDest = flag.String("dest", ".", "The destination path of the generated package.") - flagNoMtime = flag.Bool("m", false, "Ignore modification times on files.") - flagNoCompress = flag.Bool("Z", false, "Do not use compression to shrink the files.") - flagForce = flag.Bool("f", false, "Overwrite destination file if it already exists.") - flagTags = flag.String("tags", "", "Write build constraint tags") - flagPkg = flag.String("p", "statik", "Name of the generated package") - flagPkgCmt = flag.String("c", "Package statik contains static assets.", "The package comment. An empty value disables this comment.\n") - flagInclude = flag.String("include", "*.*", "The patterns of files to be included (by comma separated).\n") + flagSrc = flag.String("src", path.Join(".", "public"), "") + flagDest = flag.String("dest", ".", "") + flagNoMtime = flag.Bool("m", false, "") + flagNoCompress = flag.Bool("Z", false, "") + flagForce = flag.Bool("f", false, "") + flagTags = flag.String("tags", "", "") + flagPkg = flag.String("p", "statik", "") + flagPkgCmt = flag.String("c", "", "") + flagInclude = flag.String("include", "*.*", "") ) +const helpText = `statik [options] + +Options: +-src The source directory of the assets. "public" by default. +-dest The destination directory of the generated package. "." by default. + +-f Override destination if it already exists, false by default. +-include Wildcard to filter files to include, "*.*" by default. +-m Ignore modification times on files, false by default. +-Z Do not use compression, false by default. + +-p Name of the generated package, "statik" by default. +-tags Build tags for the generated package. +-c Godoc for the generated package. + +-help Prints this text. + +Examples: + +Generates a statik package from ./assets directory. Overrides +if there is already an existing package. + + $ statik -src=assets -f + +Generates a statik package only with the ".js" files +from the ./public directory. + + $ statik -include=*.js +` + // mtimeDate holds the arbitrary mtime that we assign to files when // flagNoMtime is set. var mtimeDate = time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC) func main() { + flag.Usage = help flag.Parse() namePackage = *flagPkg @@ -286,3 +317,8 @@ func exitWithError(err error) { fmt.Println(err) os.Exit(1) } + +func help() { + fmt.Println(helpText) + os.Exit(1) +}