diff options
| author | Shulhan <ms@kilabit.info> | 2022-05-19 17:50:08 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-05-19 17:50:08 +0700 |
| commit | 3287fa726ccd353c6278ad28db11921dce993d61 (patch) | |
| tree | b4d75051efb450ec39a304e53bc0a00b78bfd1c3 | |
| parent | 38cef79652548736a339ec1d838cf66b6a9d9a61 (diff) | |
| download | ciigo-3287fa726ccd353c6278ad28db11921dce993d61.tar.xz | |
cmd/ciigo: simplify and cleaning up the code
This changes move the flag "help" to command.
| -rw-r--r-- | cmd/ciigo/main.go | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/cmd/ciigo/main.go b/cmd/ciigo/main.go index e8bec17..5254243 100644 --- a/cmd/ciigo/main.go +++ b/cmd/ciigo/main.go @@ -42,6 +42,7 @@ import ( const ( cmdConvert = "convert" cmdEmbed = "embed" + cmdHelp = "help" cmdServe = "serve" cmdVersion = "version" @@ -49,69 +50,65 @@ const ( ) func main() { + var ( + htmlTemplate *string + outputFile *string + address *string + exclude *string + ) + flag.Usage = usage - isHelp := flag.Bool("help", false, "print help") - htmlTemplate := flag.String("template", "", "path to HTML template") - outputFile := flag.String("out", "ciigo_static.go", + htmlTemplate = flag.String("template", "", "path to HTML template") + outputFile = flag.String("out", "ciigo_static.go", "path to output of .go embed file") - address := flag.String("address", ":8080", + address = flag.String("address", ":8080", "the binding address for HTTP server") - exclude := flag.String("exclude", "", + exclude = flag.String("exclude", "", "a regex to exclude certain paths from being scanned during covert, embeded, watch, or serve") flag.Parse() - if *isHelp { - usage() - os.Exit(0) - } + var ( + command = strings.ToLower(flag.Arg(0)) + convertOpts = ciigo.ConvertOptions{ + Root: flag.Arg(1), + HtmlTemplate: *htmlTemplate, + Exclude: *exclude, + } + + err error + ) - command := flag.Arg(0) if len(command) == 0 { usage() os.Exit(1) } - - dir := flag.Arg(1) - if len(dir) == 0 { - dir = ciigo.DefaultRoot + if len(convertOpts.Root) == 0 { + convertOpts.Root = ciigo.DefaultRoot } - var err error - command = strings.ToLower(command) - switch command { case cmdConvert: - opts := ciigo.ConvertOptions{ - Root: dir, - HtmlTemplate: *htmlTemplate, - Exclude: *exclude, - } - err = ciigo.Convert(&opts) + err = ciigo.Convert(&convertOpts) case cmdEmbed: genOpts := ciigo.EmbedOptions{ - ConvertOptions: ciigo.ConvertOptions{ - Root: dir, - HtmlTemplate: *htmlTemplate, - Exclude: *exclude, - }, + ConvertOptions: convertOpts, EmbedOptions: memfs.EmbedOptions{ GoFileName: *outputFile, }, } err = ciigo.GoEmbed(&genOpts) + case cmdHelp: + usage() + case cmdServe: opts := ciigo.ServeOptions{ - ConvertOptions: ciigo.ConvertOptions{ - Root: dir, - HtmlTemplate: *htmlTemplate, - Exclude: *exclude, - }, - Address: *address, - IsDevelopment: true, + ConvertOptions: convertOpts, + Address: *address, + IsDevelopment: true, } err = ciigo.Serve(&opts) @@ -142,6 +139,10 @@ ciigo [-template <file>] [-exclude <regex>] convert <dir> and convert them into HTML files. The template "file" is optional, default to embedded HTML template. +ciigo help + + Print the usage (this output). + ciigo [-template <file>] [-exclude <regex>] [-out <file>] embed <dir> Convert all markup files inside directory "dir" recursively and then |
