From 97c2b038532c495b369505d8c1a82a0b33f10fde Mon Sep 17 00:00:00 2001 From: mosquito Date: Wed, 15 Mar 2023 18:59:09 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20cli=20info=20bug=20and=20rewrite=20makefi?= =?UTF-8?q?le=20=F0=9F=A5=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- cli/cli.go | 29 +++++++++++++++++++---------- cli/makefile | 27 +++++++++++++++++---------- cli/makefile_cross | 14 ++++++++++++++ 4 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 cli/makefile_cross diff --git a/README.md b/README.md index 5fe33df..8425a9b 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ options: - `-r` enable reverse the character color. - `-g` enable gif mode, print every frame of gif image. -- `-s value` set the scale for images(value default 0.5, [1.0, +)). +- `-s value` set the scale for images(value default 0.5, (0, +)). - `-t value` set the threshold of binarization(value default generate by OTSU, [0, 255]). > use `bobibo help` to print options. diff --git a/cli/cli.go b/cli/cli.go index 1ff32b0..e9511a8 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -14,17 +14,19 @@ var ( func main() { if len(os.Args) <= 1 { - fmt.Println("Please input a path of image :P") - fmt.Println("Use help to print options :P") - fmt.Println("Use version to print version :P") + fmt.Println("Please input a path of image.") + fmt.Println("Or using help to print options.") + fmt.Println("Or using version to print version.") + fmt.Println(":P") os.Exit(1) } path := os.Args[1] if path == "help" { - fmt.Println("Use -r to reverse the char color :P") - fmt.Println("Use -g to enable gif analyzation, default: disable :P") - fmt.Println("Use -s [d]{[0, +)} to set the scale of art :P") - fmt.Println("Use -t [d]{[0, 255]} to set the threshold of binarization :P") + fmt.Println("Options:") + fmt.Println(" -r reverse the char color.") + fmt.Println(" -g enable gif analyzation, default: disable.") + fmt.Println(" -s [d](0, +) set the scale of art. [default: 0.5]") + fmt.Println(" -t [d][0, 255] set the threshold of binarization. [default: gen by ostu]") os.Exit(0) } else if path == "version" { fmt.Printf("BoBiBo %s :P\n", version) @@ -50,15 +52,22 @@ func main() { case "-s": f, err := strconv.ParseFloat(os.Args[i+3], 64) if err != nil { - fmt.Println(err.Error()) - fmt.Println("The range of scale must be [0, +)") + fmt.Println("The range of scale must at (0, +).") + os.Exit(1) + } + if f == 0 { + fmt.Println("The range of scale must at (0, +).") os.Exit(1) } scale = f case "-t": i, err := strconv.ParseInt(os.Args[i+3], 10, 64) if err != nil { - fmt.Println("The range of threshold must be [0, 255]") + fmt.Println("The range of threshold must at [0, 255].") + os.Exit(1) + } + if i < 0 || i > 255 { + fmt.Println("The range of threshold must at [0, 255].") os.Exit(1) } threshold = int(i) diff --git a/cli/makefile b/cli/makefile index c1e8dc2..cf78be4 100644 --- a/cli/makefile +++ b/cli/makefile @@ -1,14 +1,21 @@ -OS = linux -ARCH = amd64 -EXE = bobibo_$(OS)_$(ARCH) -IS_STATIC = 0 -VERSION=V1.0.1 -all: build +VERSION=V1.1.0 +EXE=bobibo +.PHONY: default +default: build + +.PHONY: build build: cli.go - CGO_ENABLED=$(IS_STATIC) GOOS=$(OS) GOARCH=$(ARCH) go build -ldflags="-X 'main.version=$(VERSION)' -s -w" -o $(EXE) + go build -ldflags="-X 'main.version=$(VERSION)' -s -w" -o $(EXE) + upx $(EXE) # upx not found ? install it or remove this line. @echo Build Success !!! -compress: $(EXE) - upx $(EXE) -o $(EXE)_cprs - @echo Compress Success !!! +.PHONY: install +install: $(EXE) + install -Dm755 $(EXE) /usr/bin/$(EXE) + @echo install Success !!! + +.PHONY: uninstall +uninstall: + rm -f /usr/bin/$(EXE) + @echo uninstall Success !!! diff --git a/cli/makefile_cross b/cli/makefile_cross new file mode 100644 index 0000000..08617a3 --- /dev/null +++ b/cli/makefile_cross @@ -0,0 +1,14 @@ +OS = linux +ARCH = amd64 +EXE = bobibo_$(OS)_$(ARCH) +IS_STATIC = 0 +VERSION=V1.1.0 +all: build + +build: cli.go + CGO_ENABLED=$(IS_STATIC) GOOS=$(OS) GOARCH=$(ARCH) go build -ldflags="-X 'main.version=$(VERSION)' -s -w" -o $(EXE) + @echo Build Success !!! + +compress: $(EXE) + upx $(EXE) -o $(EXE)_cprs + @echo Compress Success !!!