diff --git a/.gitignore b/.gitignore index 7c8968d..0f31557 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ #### joe made this: http://goel.io/joe +qiic +.envrc + # Mac .DS_Store diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..02ee397 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,33 @@ +before: + hooks: + - go mod download +builds: +- env: + - CGO_ENABLED=0 + main: ./cmd/qiic/main.go + binary: qiic +archives: +- replacements: + darwin: Darwin + 386: i386 + amd64: x86_64 +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' +brews: +- tap: + owner: momotaro98 + name: homebrew-qiic + token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}" + folder: Formula + homepage: https://github.com/momotaro98/qiic + description: qiic + test: | + system "#{bin}/qiic --version" diff --git a/Makefile b/Makefile index bafaab7..191fa37 100644 --- a/Makefile +++ b/Makefile @@ -4,26 +4,23 @@ GOVERSION=$(shell go version) GOOS=$(word 1,$(subst /, ,$(word $(words $(GOVERSION)), $(GOVERSION)))) GOARCH=$(word 2,$(subst /, ,$(word $(words $(GOVERSION)), $(GOVERSION)))) GOCMD=go +BINPATH=./cmd/qiic GOBUILD=$(GOCMD) build GOCLEAN=$(GOCMD) clean GOTEST=$(GOCMD) test -BINARY_DIR=build -RELEASE_DIR=$(CURDIR)/release/$(VERSION) -BINARY_NAME=qiic .PHONY: build test clean all: build test build: - $(GOBUILD) -o $(BINARY_DIR)/$(PRODUCT_NAME)_$(GOOS)_$(GOARCH)/$(BINARY_NAME) -v + $(GOBUILD) $(BINPATH) test: $(GOTEST) -v ./... clean: - $(GOCLEAN) - rm -rf $(BINARY_DIR) + rm -f ./qiic docker-build: docker build -t $(PRODUCT_NAME):$(VERSION) . @@ -33,14 +30,6 @@ docker-run: && docker run --rm \ $(PRODUCT_NAME):$(VERSION) -$(RELEASE_DIR): - @mkdir -p $@ - -release-darwin-amd64: - @$(MAKE) build release-zip GOOS=darwin GOARCH=amd64 - -release-zip: $(RELEASE_DIR) - @echo " * Creating zip for $(GOOS)/$(GOARCH)" - cd $(BINARY_DIR) && zip -9 $(RELEASE_DIR)/$(PRODUCT_NAME)_$(GOOS)_$(GOARCH).zip $(PRODUCT_NAME)_$(GOOS)_$(GOARCH)/* - -release-files: release-darwin-amd64 +.PHONY: help +help: ## Help command + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/backend.go b/backend.go index 8ada581..3ab18a4 100644 --- a/backend.go +++ b/backend.go @@ -1,4 +1,4 @@ -package main +package qiic import ( "context" diff --git a/main.go b/cmd/qiic/main.go similarity index 79% rename from main.go rename to cmd/qiic/main.go index 77ff923..b35eec7 100644 --- a/main.go +++ b/cmd/qiic/main.go @@ -9,6 +9,8 @@ import ( "sync" "github.com/urfave/cli" + + "github.com/momotaro98/qiic" ) const Version = "1.2.0" @@ -32,7 +34,7 @@ func main() { if err != nil { return fmt.Errorf("Error! Argument is required to be number\nUsage Example: qiic a 3") } - articles, err := Load() + articles, err := qiic.Load() if err != nil { return err } @@ -40,7 +42,7 @@ func main() { return fmt.Errorf("Error! The argument number is out of range of the articles Access Number\nUsage Example: qiic a 3\nCheck Articles Number with\nqiic u\n or\nqiic l") } targetArticle := articles[argAnum-1] // need decrement - err = OpenBrowser(targetArticle.URL) + err = qiic.OpenBrowser(targetArticle.URL) if err != nil { return err } @@ -52,11 +54,11 @@ func main() { Aliases: []string{"l", "ls"}, Usage: "list local saved articles", Action: func(ctx *cli.Context) error { - articles, err := Load() + articles, err := qiic.Load() if err != nil { return err } - Render(articles) + qiic.Render(articles) return nil }, }, @@ -82,21 +84,18 @@ func main() { page := ctx.Int("page") if username == "" { - msg := "username is required" - fmt.Println(msg) - return fmt.Errorf(msg) + return fmt.Errorf("username is required") } // Fetch from API Server - req := &UserStockRequest{ + req := &qiic.UserStockRequest{ UserName: username, - GetRequest: GetRequest{ + GetRequest: qiic.GetRequest{ Page: page, }, } - articles, _, err := GetArticles(context.Background(), req) + articles, _, err := qiic.GetArticles(context.Background(), req) if err != nil { - fmt.Println(err) return err } @@ -133,31 +132,29 @@ func main() { var ( c = context.Background() - req ArticlesGetRequester + req qiic.ArticlesGetRequester ) if token != "" { - c = SetToken(c, token) - req = &ReqGetAuthenticatedUserItems{ - GetRequest{ + c = qiic.SetToken(c, token) + req = &qiic.ReqGetAuthenticatedUserItems{ + GetRequest: qiic.GetRequest{ Page: 1, }, } } else if username != "" { - c = SetUserName(context.Background(), username) - req = &ReqGetUserItems{ - GetRequest{ + c = qiic.SetUserName(context.Background(), username) + req = &qiic.ReqGetUserItems{ + GetRequest: qiic.GetRequest{ Page: 1, }, } } else { - msg := "either token or username is required" - fmt.Println(msg) - return fmt.Errorf(msg) + return fmt.Errorf("either token or username is required") } // Fetch from API Server - articles, err := CollectUserItems(c, req) + articles, err := qiic.CollectUserItems(c, req) if err != nil { fmt.Println(err) return err @@ -173,7 +170,7 @@ func main() { end := start + ArtPerPage num := len(articles) if num <= start { - articles = []*Article{} + articles = []*qiic.Article{} } else if num < end { articles = articles[start:num] } else { @@ -185,17 +182,19 @@ func main() { }, } - app.Run(os.Args) + if err := app.Run(os.Args); err != nil { + fmt.Println(err) + } } -func SaveAndRender(articles []*Article) error { +func SaveAndRender(articles []*qiic.Article) error { var wg sync.WaitGroup // Save file wg.Add(1) go func() { defer wg.Done() - if err := Save(articles); err != nil { + if err := qiic.Save(articles); err != nil { fmt.Println("saving a file for cache failed") } }() @@ -204,7 +203,7 @@ func SaveAndRender(articles []*Article) error { wg.Add(1) go func() { defer wg.Done() - Render(articles) + qiic.Render(articles) }() wg.Wait() diff --git a/content.go b/content.go index 67635b6..991c7e4 100644 --- a/content.go +++ b/content.go @@ -1,4 +1,4 @@ -package main +package qiic import ( "time" diff --git a/frontend.go b/frontend.go index aba087b..43e1454 100644 --- a/frontend.go +++ b/frontend.go @@ -1,4 +1,4 @@ -package main +package qiic import ( "fmt" diff --git a/frontend_test.go b/frontend_test.go index 10faadf..e0aa5ce 100644 --- a/frontend_test.go +++ b/frontend_test.go @@ -1,4 +1,4 @@ -package main +package qiic import ( "fmt" diff --git a/handlefile.go b/handlefile.go index 5cb83cf..0461fe1 100644 --- a/handlefile.go +++ b/handlefile.go @@ -1,4 +1,4 @@ -package main +package qiic import ( "encoding/json" diff --git a/utils.go b/utils.go index 48f590f..2901680 100644 --- a/utils.go +++ b/utils.go @@ -1,4 +1,4 @@ -package main +package qiic import ( "fmt"