Skip to content

Commit

Permalink
Merge pull request #2 from msqtt/master
Browse files Browse the repository at this point in the history
Fix cli info bug and rewrite makefile 🥚
  • Loading branch information
msqtt committed Mar 15, 2023
2 parents 7031d66 + 97c2b03 commit 05a9a48
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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.
Expand Down
29 changes: 19 additions & 10 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
28 changes: 18 additions & 10 deletions cli/makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
OS = linux
ARCH = amd64
EXE = bobibo_$(OS)_$(ARCH)
IS_STATIC = 0
VERSION=V1.0.1
all: build
VERSION=V1.1.0
EXE=bobibo
DESTDIR :=

.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) $(DESTDIR)/usr/bin/$(EXE)
@echo install Success !!!

.PHONY: uninstall
uninstall:
rm -f /usr/bin/$(EXE)
@echo uninstall Success !!!
14 changes: 14 additions & 0 deletions cli/makefile_cross
Original file line number Diff line number Diff line change
@@ -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 !!!

0 comments on commit 05a9a48

Please sign in to comment.