Skip to content

Commit d1b06ac

Browse files
Add a Makefile
Signed-off-by: Chris Cummer <[email protected]>
1 parent 54e2216 commit d1b06ac

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

Makefile

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.PHONY: build help install lint test uninstall
2+
3+
# Set go modules to on and use GoCenter for immutable modules
4+
export GO111MODULE = on
5+
export GOPROXY = https://proxy.golang.org,direct
6+
7+
# Determines the path to this Makefile
8+
THIS_FILE := $(lastword $(MAKEFILE_LIST))
9+
10+
APP=til
11+
12+
## build: builds a local version
13+
build:
14+
go build -o bin/${APP}
15+
@echo "Done building"
16+
17+
## help: prints this help message
18+
help:
19+
@echo "Usage: \n"
20+
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
21+
22+
## install: installs a local version of the app
23+
install:
24+
@echo "Installing ${APP}..."
25+
@go clean
26+
@go install -ldflags="-s -w"
27+
$(eval INSTALLPATH = $(shell which ${APP}))
28+
@echo "${APP} installed into ${INSTALLPATH}"
29+
30+
## lint: runs a number of code quality checks against the source code
31+
lint:
32+
@echo "\033[35mhttps://github.com/kisielk/errcheck\033[0m"
33+
errcheck ./til.go
34+
35+
@echo "\033[35mhttps://golang.org/cmd/vet/k\033[0m"
36+
go vet ./til.go
37+
38+
@echo "\033[35m# https://staticcheck.io/docs/k\033[0m"
39+
staticcheck ./til.go
40+
41+
@echo "\033[35m# https://github.com/mdempsky/unconvert\033[0m"
42+
unconvert ./...
43+
44+
## test: runs the test suite
45+
test: build
46+
go test ./...
47+
48+
## uninstall: uninstals a locally-installed version
49+
uninstall:
50+
@rm ~/go/bin/${APP}

bin/til

11 MB
Binary file not shown.

til.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ editor: ""
3333
targetDirectory: "~/Documents/til"
3434
`
3535
defaultEditor = "open"
36-
3736
fileExtension = "md"
3837

3938
// A custom datetime format that plays nicely with GitHub Pages filename restrictions
@@ -66,9 +65,6 @@ var (
6665

6766
// Red writes red text
6867
Red = Colour("\033[1;31m%s\033[0m")
69-
70-
// Yellow writes yellow text
71-
Yellow = Colour("\033[1;33m%s\033[0m")
7268
)
7369

7470
// globalConfig holds and makes available all the user-configurable
@@ -196,7 +192,7 @@ func makeConfigDir() {
196192
func makeConfigFile() {
197193
cPath := getConfigPath()
198194

199-
fileInfo, err := os.Stat(cPath)
195+
_, err := os.Stat(cPath)
200196

201197
if err != nil {
202198
// Something went wrong trying to find the config file.
@@ -217,7 +213,7 @@ func makeConfigFile() {
217213
}
218214

219215
// Let's double-check that the file's there now
220-
fileInfo, err = os.Stat(cPath)
216+
fileInfo, err := os.Stat(cPath)
221217
if err != nil {
222218
Fail(errors.New(errConfigFileAssert))
223219
}
@@ -495,7 +491,7 @@ func readPage(filePath string) *Page {
495491
Fail(err)
496492
}
497493

498-
err = frontmatter.Unmarshal(([]byte)(data), page)
494+
err = frontmatter.Unmarshal(data, page)
499495
if err != nil {
500496
Fail(err)
501497
}

til_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ func Test_Page_CreatedAt(t *testing.T) {
2222

2323
actual := page.CreatedAt()
2424

25-
assert.Equal(t, 2020, int(actual.Year()))
25+
assert.Equal(t, 2020, actual.Year())
2626
assert.Equal(t, 5, int(actual.Month()))
27-
assert.Equal(t, 7, int(actual.Day()))
27+
assert.Equal(t, 7, actual.Day())
2828
}
2929

3030
func Test_Page_CreatedMonth(t *testing.T) {

0 commit comments

Comments
 (0)