aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-08-01 20:55:39 +0700
committerShulhan <ms@kilabit.info>2022-08-01 20:55:39 +0700
commitb14a924dc063b28a8d784a15b1fb234ba73913c1 (patch)
tree0e398ceada76dd53c1031ee55c84e4d2e6508dd0
parentf0be5f35c325da2aebea6e0d98f035ad23dc3019 (diff)
downloadciigo-b14a924dc063b28a8d784a15b1fb234ba73913c1.tar.xz
all: merge internal/cmd/goembed to cmd/ciigo-example
The internal/cmd/goembed is replaced as command "embed" of cmd/ciigo-example.
-rw-r--r--Makefile2
-rw-r--r--cmd/ciigo-example/main.go41
-rw-r--r--internal/cmd/goembed/main.go41
3 files changed, 42 insertions, 42 deletions
diff --git a/Makefile b/Makefile
index 0554704..40b749c 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ lint:
golangci-lint run ./...
test:
- go run ./internal/cmd/goembed
+ go run ./cmd/ciigo-example embed
CGO_ENABLED=1 go test -v -race ./...
install:
diff --git a/cmd/ciigo-example/main.go b/cmd/ciigo-example/main.go
index 0eeb52c..b23c4f7 100644
--- a/cmd/ciigo-example/main.go
+++ b/cmd/ciigo-example/main.go
@@ -6,13 +6,19 @@
package main
import (
+ "flag"
"log"
+ "strings"
"github.com/shuLhan/share/lib/memfs"
"git.sr.ht/~shulhan/ciigo"
)
+const (
+ cmdEmbed = "embed"
+)
+
var ciigoFS *memfs.MemFS
func main() {
@@ -26,11 +32,46 @@ func main() {
Address: ":8080",
}
+ cmd string
err error
)
+ flag.Parse()
+
+ cmd = strings.ToLower(flag.Arg(0))
+ if cmd == cmdEmbed {
+ doEmbed()
+ return
+ }
+
err = ciigo.Serve(opts)
if err != nil {
log.Fatal(err)
}
}
+
+func doEmbed() {
+ var (
+ opts = ciigo.EmbedOptions{
+ ConvertOptions: ciigo.ConvertOptions{
+ Root: "_example",
+ HtmlTemplate: "_example/html.tmpl",
+ },
+ EmbedOptions: memfs.EmbedOptions{
+ CommentHeader: `// SPDX-FileCopyrightText: 2019 Shulhan <ms@kilabit.info>
+// SPDX-License-Identifier: GPL-3.0-or-later
+`,
+ PackageName: "main",
+ VarName: "ciigoFS",
+ GoFileName: "cmd/ciigo-example/static.go",
+ },
+ }
+
+ err error
+ )
+
+ err = ciigo.GoEmbed(&opts)
+ if err != nil {
+ log.Fatal(err)
+ }
+}
diff --git a/internal/cmd/goembed/main.go b/internal/cmd/goembed/main.go
deleted file mode 100644
index 7d35377..0000000
--- a/internal/cmd/goembed/main.go
+++ /dev/null
@@ -1,41 +0,0 @@
-// 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.
-
-//go:generate go run generate_main.go
-
-package main
-
-import (
- "log"
-
- "github.com/shuLhan/share/lib/memfs"
-
- "git.sr.ht/~shulhan/ciigo"
-)
-
-func main() {
- var (
- opts = ciigo.EmbedOptions{
- ConvertOptions: ciigo.ConvertOptions{
- Root: "_example",
- HtmlTemplate: "_example/html.tmpl",
- },
- EmbedOptions: memfs.EmbedOptions{
- CommentHeader: `// SPDX-FileCopyrightText: 2019 Shulhan <ms@kilabit.info>
-// SPDX-License-Identifier: GPL-3.0-or-later
-`,
- PackageName: "main",
- VarName: "ciigoFS",
- GoFileName: "cmd/ciigo-example/static.go",
- },
- }
-
- err error
- )
-
- err = ciigo.GoEmbed(&opts)
- if err != nil {
- log.Fatal(err)
- }
-}