Skip to content

Commit

Permalink
support update command and print usage with cli when no argument
Browse files Browse the repository at this point in the history
  • Loading branch information
konoui committed Apr 10, 2020
1 parent bb08cb2 commit 2cf0e13
Show file tree
Hide file tree
Showing 8 changed files with 433 additions and 248 deletions.
35 changes: 16 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@ VERSION := $(shell git describe --tags --abbrev=0)
REVISION := $(shell git rev-parse --short HEAD)
LDFLAGS := -X 'main. version=$(VERSION)' -X 'main. revision=$(REVISION)'
SRC_DIR := ./
BIN_DIR := bin
BINARY := bin/tldr
WORKFLOW_DIR := "$${HOME}/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.2569C1E1-8114-4B77-9506-52AA966313A9"
BIN_NAME := tldr
BINARY := bin/$(BIN_NAME)
ASSETS_DIR := assets
ASSETS := $(ASSETS_DIR)/* $(BINARY) README.md
ARTIFACT_DIR := .artifact
ARTIFACT := ${ARTIFACT_DIR}/tldr.alfredworkflow
ARTIFACT_NAME := $(ARTIFACT_DIR)/$(BIN_NAME).alfredworkflow

GOLANGCI_LINT_VERSION := v1.22.2
export GO111MODULE=on
## For local test
WORKFLOW_DIR := "$${HOME}/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.2569C1E1-8114-4B77-9506-52AA966313A9"

## Build binaries on your environment
GOLANGCI_LINT_VERSION := v1.22.2
export GO111MODULE=on

## Build binaries on your environment
build:
CGO_ENABLED=0 go build -ldflags "${LDFLAGS}" -o ${BINARY} ./${SRC_DIR}
CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BINARY) $(SRC_DIR)

## Format source codes
fmt:
Expand All @@ -27,35 +26,33 @@ fmt:

## Lint
lint:
@(if ! type golangci-lint >/dev/null 2>&1; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} ;fi)
@(if ! type golangci-lint >/dev/null 2>&1; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin $(GOLANGCI_LINT_VERSION) ;fi)
golangci-lint run ./...

## Build macos binaries
darwin:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "${LDFLAGS} -s -w" -o ${BINARY} ./${SRC_DIR}
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "${LDFLAGS} -s -w" -o $(BINARY) $(SRC_DIR)

## Run tests for my project
test:
go test -v ./...

## Install Binary and Assets to Workflow Directory
install: build
@(cp ${BINARY} ${WORKFLOW_DIR}/)
@(cp ${ASSETS_DIR}/* ${WORKFLOW_DIR}/)
@(cp $(ASSETS) $(WORKFLOW_DIR)/)

## GitHub Release and uploads artifacts
release: darwin
@(if ! type ghr >/dev/null 2>&1; then go get -u github.com/tcnksm/ghr ;fi)
@(if [ ! -e ${ARTIFACT_DIR} ]; then mkdir ${ARTIFACT_DIR} ; fi)
@(cp ${BINARY} ${ARTIFACT_DIR})
@(cp ${ASSETS_DIR}/* ${ARTIFACT_DIR})
@(zip -j ${ARTIFACT} ${ARTIFACT_DIR}/*)
@ghr -replace ${VERSION} ${ARTIFACT}
@(if [ ! -e $(ARTIFACT_DIR) ]; then mkdir $(ARTIFACT_DIR) ; fi)
@(cp $(ASSETS) $(ARTIFACT_DIR))
@(zip -j $(ARTIFACT_NAME) $(ARTIFACT_DIR)/*)
@ghr -replace $(VERSION) $(ARTIFACT_NAME)

## Clean Binary
clean:
rm -f ${BIN_DIR}/*
rm -f ${ARTIFACT_DIR}/*
rm -f $(BIN_NAME)
rm -f $(ARTIFACT_DIR)/*

## Show help
help:
Expand Down
191 changes: 184 additions & 7 deletions assets/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
<key>vitoclose</key>
<false/>
</dict>
<dict>
<key>destinationuid</key>
<string>3F654141-1E91-49E3-9F81-31616D250C71</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>1D881CA9-D4C5-412D-8F3A-E40DC1034FD3</key>
<array>
Expand All @@ -43,6 +53,42 @@
<key>vitoclose</key>
<false/>
</dict>
<dict>
<key>destinationuid</key>
<string>3F654141-1E91-49E3-9F81-31616D250C71</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>248D939C-014D-43E3-8D98-D485348147EC</key>
<array>
<dict>
<key>destinationuid</key>
<string>AD0FF323-07C7-45D1-8E4B-B7A28847F8DD</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>3F654141-1E91-49E3-9F81-31616D250C71</key>
<array>
<dict>
<key>destinationuid</key>
<string>248D939C-014D-43E3-8D98-D485348147EC</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>7B74E407-A98B-42B6-9994-39ADD96B446D</key>
<array>
Expand All @@ -57,6 +103,19 @@
<false/>
</dict>
</array>
<key>AD0FF323-07C7-45D1-8E4B-B7A28847F8DD</key>
<array>
<dict>
<key>destinationuid</key>
<string>AF4626B4-D8E7-4CA6-89EA-2519E97A5A3A</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>CA38E469-AAA8-4B30-9FBD-DA5E02F4E718</key>
<array>
<dict>
Expand Down Expand Up @@ -88,6 +147,8 @@
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<false/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
Expand Down Expand Up @@ -127,7 +188,7 @@
<key>uid</key>
<string>1D881CA9-D4C5-412D-8F3A-E40DC1034FD3</string>
<key>version</key>
<integer>2</integer>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
Expand All @@ -144,7 +205,7 @@
<key>uid</key>
<string>E07B8BD1-1F99-4F81-97EA-A84B26C81DF6</string>
<key>version</key>
<integer>2</integer>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
Expand All @@ -153,6 +214,8 @@
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<false/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
Expand All @@ -170,8 +233,7 @@
<key>runningsubtext</key>
<string></string>
<key>script</key>
<string>q="$1"
./tldr ${nextCmd} ${q} --workflow --fuzzy</string>
<string>./tldr ${nextCmd} --workflow --fuzzy</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
Expand All @@ -190,7 +252,26 @@
<key>uid</key>
<string>15F87A1B-0525-43F3-A55A-B5901B9222F8</string>
<key>version</key>
<integer>2</integer>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>inputstring</key>
<string>{var:nextAction}</string>
<key>matchcasesensitive</key>
<false/>
<key>matchmode</key>
<integer>0</integer>
<key>matchstring</key>
<string>cmd</string>
</dict>
<key>type</key>
<string>alfred.workflow.utility.filter</string>
<key>uid</key>
<string>7B74E407-A98B-42B6-9994-39ADD96B446D</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
Expand All @@ -210,6 +291,74 @@
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>lastpathcomponent</key>
<false/>
<key>onlyshowifquerypopulated</key>
<false/>
<key>removeextension</key>
<false/>
<key>text</key>
<string>{query}</string>
<key>title</key>
<string>Results:</string>
</dict>
<key>type</key>
<string>alfred.workflow.output.notification</string>
<key>uid</key>
<string>AF4626B4-D8E7-4CA6-89EA-2519E97A5A3A</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>./tldr ${nextCmd} &gt; /dev/null
ret=$1
if [ $retl -ne 0 ]; then
echo "Update Failed"
return
fi
echo "Update Success"</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>AD0FF323-07C7-45D1-8E4B-B7A28847F8DD</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argument</key>
<string></string>
<key>variables</key>
<dict>
<key>nextCmd</key>
<string>{query}</string>
</dict>
</dict>
<key>type</key>
<string>alfred.workflow.utility.argument</string>
<key>uid</key>
<string>3F654141-1E91-49E3-9F81-31616D250C71</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand All @@ -220,12 +369,12 @@
<key>matchmode</key>
<integer>0</integer>
<key>matchstring</key>
<string>cmd</string>
<string>shell</string>
</dict>
<key>type</key>
<string>alfred.workflow.utility.filter</string>
<key>uid</key>
<string>7B74E407-A98B-42B6-9994-39ADD96B446D</string>
<string>248D939C-014D-43E3-8D98-D485348147EC</string>
<key>version</key>
<integer>1</integer>
</dict>
Expand All @@ -252,13 +401,41 @@
<key>ypos</key>
<integer>120</integer>
</dict>
<key>248D939C-014D-43E3-8D98-D485348147EC</key>
<dict>
<key>xpos</key>
<integer>530</integer>
<key>ypos</key>
<integer>360</integer>
</dict>
<key>3F654141-1E91-49E3-9F81-31616D250C71</key>
<dict>
<key>xpos</key>
<integer>455</integer>
<key>ypos</key>
<integer>360</integer>
</dict>
<key>7B74E407-A98B-42B6-9994-39ADD96B446D</key>
<dict>
<key>xpos</key>
<integer>390</integer>
<key>ypos</key>
<integer>240</integer>
</dict>
<key>AD0FF323-07C7-45D1-8E4B-B7A28847F8DD</key>
<dict>
<key>xpos</key>
<integer>610</integer>
<key>ypos</key>
<integer>330</integer>
</dict>
<key>AF4626B4-D8E7-4CA6-89EA-2519E97A5A3A</key>
<dict>
<key>xpos</key>
<integer>775</integer>
<key>ypos</key>
<integer>325</integer>
</dict>
<key>CA38E469-AAA8-4B30-9FBD-DA5E02F4E718</key>
<dict>
<key>xpos</key>
Expand Down
Loading

0 comments on commit 2cf0e13

Please sign in to comment.