From c00ba4dad1b044fdc6a4e1cc1611995ce5f0d33a Mon Sep 17 00:00:00 2001 From: "wanglei.w" Date: Fri, 31 Mar 2023 14:50:47 +0800 Subject: [PATCH] to version 0.1.1 --- .gitignore | 1 + main.go | 17 +++++++++++----- makefile | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ scripts/main.go | 9 +++++++-- 4 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 makefile diff --git a/.gitignore b/.gitignore index e69de29..9b1960e 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +output/ \ No newline at end of file diff --git a/main.go b/main.go index f0c70c1..838b41c 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ import ( var ( pagePath = "wiki_pages" wikiGit = "git@github.com:u2takey/gptwiki-pages.git" + Version = "0.1.0" ) func main() { @@ -102,7 +103,7 @@ func main() { } return nil }, - Version: "0.1", + Version: Version, } _ = app.Run(os.Args) @@ -138,7 +139,7 @@ func SavePage(source, pages, folder, command, wiki, branch string) error { //} commandPath := GetWikiPathForCommand(pages, folder, command) if err := ioutil.WriteFile(commandPath, - []byte(fmt.Sprintf("#%s \n## chatgpt \n%s", command, wiki)), 0o666); err != nil { + []byte(fmt.Sprintf("# %s \n## chatgpt \n%s", command, wiki)), 0o666); err != nil { return err } //err = w.AddGlob("*") @@ -225,15 +226,21 @@ func Init() *cli.Command { &cli.StringFlag{Name: "chatgpt-key"}, &cli.StringFlag{Name: "folder", Value: "common"}, &cli.StringFlag{Name: "lang", Value: "zh"}, - &cli.StringFlag{Name: "prompt", Value: "请详细解释命令:%s"}, + &cli.StringFlag{Name: "prompt", Value: ""}, }, Action: func(c *cli.Context) error { key := c.String("chatgpt-key") folder := c.String("folder") lang := c.String("lang") prompt := c.String("prompt") - if len(lang) == 0 { - prompt = "Please explain the command in detail: %s" + if len(lang) > 0 { + if lang == "zh" && prompt == "" { + prompt = "请详细解释命令:%s" + } + } else { + if prompt == "" { + prompt = "Please explain the command in detail: %s" + } } config := Config{ GptKey: key, diff --git a/makefile b/makefile new file mode 100644 index 0000000..2437d10 --- /dev/null +++ b/makefile @@ -0,0 +1,53 @@ +# All targets. +.PHONY: lint test build publish clean help + +# Current version of the project. +VersionMain ?= 0.1.1 + + +# Target binaries. You can build multiple binaries for a single project. +TARGETS := wiki +PLAT_FROM := linux darwin windows + +# Project main package location (can be multiple ones). +CMD_DIR := . +# Project output directory. +OUTPUT_DIR := ./output +# Git commit sha. +COMMIT := $(shell git rev-parse --short HEAD) +# Build Date +BUILD_DATE=$(shelldate +%FT%T%z) +# Version File +VERSION_FILE=main + +lint: ## use golint to do lint + golint ./... + +test: ## test + go test -cover ./... + +build: ## build local binary for targets on + @for target in $(TARGETS); do \ + go build -o $(OUTPUT_DIR)/$${target} \ + -ldflags "-s -w -X $(VERSION_FILE).Version=$(VersionMain)-$(COMMIT)" \ + $(CMD_DIR)/.; \ + done + + +build-all: # build cross for targets + @for plat in $(PLAT_FROM); do \ + for target in $(TARGETS); do \ + CGO_ENABLED=0 GOOS=$${plat} GOARCH=amd64 go build -o $(OUTPUT_DIR)/$${target}_$${plat}_amd64 \ + -ldflags "-s -w -X $(VERSION_FILE).Version=$(VersionMain)-$(COMMIT)" \ + $(CMD_DIR)/.; \ + done \ + done + + +.PHONY: clean +clean: # clean bin files + -rm -vrf ${OUTPUT_DIR} + +.PHONY: help +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/scripts/main.go b/scripts/main.go index c36a75e..3159a46 100644 --- a/scripts/main.go +++ b/scripts/main.go @@ -54,7 +54,7 @@ func Init() *cli.Command { &cli.StringFlag{Name: "chatgpt-key"}, &cli.StringFlag{Name: "folder", Value: "common"}, &cli.StringFlag{Name: "lang", Value: "zh"}, - &cli.StringFlag{Name: "prompt", Value: "请详细解释命令:%s"}, + &cli.StringFlag{Name: "prompt", Value: ""}, &cli.BoolFlag{Name: "override", Value: false}, &cli.IntFlag{Name: "worker", Value: 10}, }, @@ -67,8 +67,13 @@ func Init() *cli.Command { prompt := c.String("prompt") if len(lang) > 0 { pages += "." + lang + if lang == "zh" && prompt == "" { + prompt = "请详细解释命令:%s" + } } else { - prompt = "Please explain the command in detail: %s" + if prompt == "" { + prompt = "Please explain the command in detail: %s" + } } fmt.Println("start", pages, folder)