Skip to content

Commit

Permalink
move main
Browse files Browse the repository at this point in the history
  • Loading branch information
momotaro98 committed Nov 3, 2020
1 parent a38812e commit a0754f2
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#### joe made this: http://goel.io/joe

qiic
.envrc

# Mac
.DS_Store

Expand Down
33 changes: 33 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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"
23 changes: 6 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) .
Expand All @@ -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}'
2 changes: 1 addition & 1 deletion backend.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package qiic

import (
"context"
Expand Down
53 changes: 26 additions & 27 deletions main.go → cmd/qiic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"sync"

"github.com/urfave/cli"

"github.com/momotaro98/qiic"
)

const Version = "1.2.0"
Expand All @@ -32,15 +34,15 @@ 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
}
if !(0 < argAnum && argAnum <= len(articles)) {
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
}
Expand All @@ -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
},
},
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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")
}
}()
Expand All @@ -204,7 +203,7 @@ func SaveAndRender(articles []*Article) error {
wg.Add(1)
go func() {
defer wg.Done()
Render(articles)
qiic.Render(articles)
}()

wg.Wait()
Expand Down
2 changes: 1 addition & 1 deletion content.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package qiic

import (
"time"
Expand Down
2 changes: 1 addition & 1 deletion frontend.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package qiic

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion frontend_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package qiic

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion handlefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package qiic

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package qiic

import (
"fmt"
Expand Down

0 comments on commit a0754f2

Please sign in to comment.