diff options
| author | Shulhan <ms@kilabit.info> | 2019-08-06 00:13:54 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2019-08-14 00:41:34 +0700 |
| commit | b1dd2bce666fe8217c35b9fab443035f25bfad26 (patch) | |
| tree | 2b92c84d41bcabff29f7ff9f53139cee9e8e4368 /cmd | |
| parent | b1bdf9d3fa2c830d4c59d3a56111e26a92619108 (diff) | |
| download | ciigo-b1dd2bce666fe8217c35b9fab443035f25bfad26.tar.xz | |
cmd/ciigo: a CLI to convert, generate, and serve markup files
Here are the usage of CLI,
ciigo [-template <file>] convert <dir>
Scan the "dir" recursively to find markup files (.adoc or .md) and
convert them into HTML files.
The template "file" is optional, default to "templates/html.tmpl" in
the current directory.
ciigo [-template <file>] [-out <file>] generate <dir>
Convert all markup files inside directory "dir" recursively and then
embed them into ".go" source file.
The output file is optional, default to "ciigo_static.go" in current
directory.
ciigo [-template <file>] [-address <ip:port>] serve <dir>
Serve all files inside directory "dir" using HTTP server, watch
changes on markup files and convert them to HTML files automatically.
If the address is not set, its default to ":8080".
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/ciigo-example/main.go | 2 | ||||
| -rw-r--r-- | cmd/ciigo/main.go | 118 |
2 files changed, 119 insertions, 1 deletions
diff --git a/cmd/ciigo-example/main.go b/cmd/ciigo-example/main.go index 2b98c13..a636b0e 100644 --- a/cmd/ciigo-example/main.go +++ b/cmd/ciigo-example/main.go @@ -13,7 +13,7 @@ import ( ) func main() { - srv := ciigo.NewServer("./content", ":8080") + srv := ciigo.NewServer("./content", ":8080", "./templates/html.tmpl") srv.Start() } diff --git a/cmd/ciigo/main.go b/cmd/ciigo/main.go new file mode 100644 index 0000000..9427be2 --- /dev/null +++ b/cmd/ciigo/main.go @@ -0,0 +1,118 @@ +// Copyright 2019, Shulhan <ms@kilabit.info>. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// +// ciigo is a CLI to convert, generate, and/or serve a directory that contains +// markup files, as HTML files. +// +// Usage +// +// The following section describe how to use ciigo CLI. +// +// ciigo [-template <file>] convert <dir> +// +// Scan the "dir" recursively to find markup files (.adoc or .md) and convert +// them into HTML files. +// The template "file" is optional, default to "templates/html.tmpl" in the +// current directory. +// +// ciigo [-template <file>] [-out <file>] generate <dir> +// +// Convert all the markup files inside directory "dir" recursively and then +// embed them into ".go" source file. +// The output file is optional, default to "ciigo_static.go" in current +// directory. +// +// ciigo [-template <file>] [-address <ip:port>] serve <dir> +// +// Serve all files inside directory "dir" using HTTP server, watch changes on +// markup files and convert them to HTML files. +// If the address is not set, its default to ":8080". +// +package main + +import ( + "flag" + "fmt" + "os" + "strings" + + "github.com/shuLhan/ciigo" + "github.com/shuLhan/share/lib/debug" +) + +func main() { + isHelp := flag.Bool("h", false, "print help") + isHelp = flag.Bool("help", false, "print help") + htmlTemplate := flag.String("template", "templates/html.tmpl", + "path to HTML template") + outputFile := flag.String("out", "ciigo_static.go", + "path to output of .go generated file") + address := flag.String("address", ":8080", + "the binding address for HTTP server") + + flag.Parse() + + if *isHelp { + usage() + os.Exit(0) + } + + command := flag.Arg(0) + if len(command) == 0 { + usage() + os.Exit(1) + } + + dir := flag.Arg(1) + if len(dir) == 0 { + dir = "." + } + + command = strings.ToLower(command) + switch command { + case "convert": + ciigo.Convert(dir, *htmlTemplate) + case "generate": + ciigo.Generate(dir, *outputFile, *htmlTemplate) + case "serve": + debug.Value = 2 + srv := ciigo.NewServer(dir, *address, *htmlTemplate) + srv.Start() + default: + usage() + os.Exit(1) + } +} + +func usage() { + fmt.Println(` += ciigo + +A CLI to convert, generate, and/or serve a directory that contains markup +files, as HTML files. + +== Usage + +ciigo [-template <file>] convert <dir> + + Scan the "dir" recursively to find markup files (.adoc or .md) + and convert them into HTML files. + The template "file" is optional, default to "templates/html.tmpl" in + the current directory. + +ciigo [-template <file>] [-out <file>] generate <dir> + + Convert all markup files inside directory "dir" recursively and then + embed them into ".go" source file. + The output file is optional, default to "ciigo_static.go" in current + directory. + +ciigo [-template <file>] [-address <ip:port>] serve <dir> + + Serve all files inside directory "dir" using HTTP server, watch + changes on markup files and convert them to HTML files automatically. + If the address is not set, its default to ":8080". +`) +} |
