-
Notifications
You must be signed in to change notification settings - Fork 1
/
Justfile
167 lines (141 loc) · 4.98 KB
/
Justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#
# This is a Justfile for https://github.com/casey/just and is much like a Makefile for make
# I highly recommend using just for basic automation.
#
alias ver := version
# set load-dotenv := false # Not supported yet
# load-dotenv := false
# Like in make the first recipe is used by default.
# I like listing all the recipes by default.
# I also like wiping the terminal buffer like CLS in DOS. It makes me happy. :-)
@_default:
just _term-wipe
just --list
# The real cleaner
@_clean:
rm -f *.out
rm -f output.txt
rm -rf dist
# Cleanup around here!
clean:
just _term-wipe
just _clean
@just _dir-list
# Directory Lister
_dir-list:
#!/bin/sh
if [[ ! -z "$(which lsd)" ]]; then
echo "$ lsd -al"
lsd -al
elif [[ "$(uname -s)" = "Darwin" ]]; then
echo "$ ls -alG"
ls -alG
else
echo "$ ls -al --color=always"
ls -al --color=always
fi
# Distribution Helper
@dist sub="release":
just dist-{{sub}}
# Distribution Releaser
dist-release:
#!/bin/sh
just _term-wipe
just _clean
git checkout master
git push --all && git push --tags
goreleaser
# goreleaser release --skip-publish
ver="$(git tag | tail -1)"
ver="${ver:1}"
if [ -d "distro/templar_${ver}" ]; then
echo "WARNING: Do you need to tag a new release first?"
echo "A directory already exists for templar_${ver}"
else
mkdir -p "distro/templar_${ver}"
cd dist
mv *.{deb,gz,md,rpm,txt,yaml,zip} ../distro/templar_${ver}/
fi
git checkout develop
# Distribution Tester
dist-test:
just _term-wipe
@just _clean
@# goreleaser --snapshot --skip-publish --rm-dist
goreleaser release --skip-publish
# Run the command line app
run +args="":
just _term-wipe
# NOTE: Just itself ALWAYS loads a .env file if present
go run cmd/templar/main.go {{args}}
# Run a test
@test cmd="help" +data="example.env":
just _term-wipe
just test-{{cmd}} "{{data}}"
# Run Go Unit Tests
@test-coverage +data='':
just _term-wipe
echo "You need to run:"
echo "go test -coverprofile=c.out"
echo "go tool cover -func=c.out"
# Test with debug enabled
test-debug +data="example.env":
@# CLI_ENV_VAR="Sound and fury" go run cmd/templar/main.go example.tmpl --data-file example.env CLI_VAR="As you like it" --debug
CLI_ENV_VAR="Sound and fury" CLI_VAR="As you like it" go run cmd/templar/main.go example.tmpl --data-file {{data}} --debug
# Test the help system
test-help +data="example.env":
go run cmd/templar/main.go --help
# Test example.env with .env
test-stdout +data="example.json -f example2.json":
@# CLI_ENV_VAR="Sound and fury" go run cmd/templar/main.go example.tmpl --data-file example.env CLI_VAR="As you like it"
CLI_ENV_VAR="Sound and fury" CLI_VAR="As you like it" go run cmd/templar/main.go example.tmpl --data-file {{data}}
# Test example.env with out .env
test-no-dotenv +data="example.env":
#!/bin/sh
if [ -z "{{data}}" ]; then
echo 'CLI_ENV_VAR="Sound and fury" CLI_VAR="As you like it" go run cmd/templar/main.go example.tmpl --no-dotenv'
CLI_ENV_VAR="Sound and fury" CLI_VAR="As you like it" go run cmd/templar/main.go example.tmpl --no-dotenv
else
echo 'CLI_ENV_VAR="Sound and fury" CLI_VAR="As you like it" go run cmd/templar/main.go example.tmpl --data-file {{data}} --no-dotenv'
CLI_ENV_VAR="Sound and fury" CLI_VAR="As you like it" go run cmd/templar/main.go example.tmpl --data-file {{data}} --no-dotenv
fi
# CLI_ENV_VAR="Sound and fury" go run cmd/templar/main.go example.tmpl --data-file example.env CLI_VAR="As you like it" --no-dotenv
# Test creating an output file
test-with-file +data="example.env":
#!/bin/sh
rm -f output.txt
if [ -z "{{data}}" ]; then
CLI_ENV_VAR="Sound and fury" CLI_VAR="As you like it" go run cmd/templar/main.go --output-file output.txt example.tmpl
else
CLI_ENV_VAR="Sound and fury" CLI_VAR="As you like it" go run cmd/templar/main.go --output-file output.txt example.tmpl --data-file {{data}}
fi
# CLI_ENV_VAR="Sound and fury" go run cmd/templar/main.go --output-file output.txt example.tmpl --env-file example.env CLI_VAR="As you like it"
# CLI_ENV_VAR="Sound and fury" CLI_VAR="As you like it" go run cmd/templar/main.go --output-file output.txt example.tmpl --env-file {{data}}
# CLI_ENV_VAR="Sound and fury" CLI_VAR="As you like it" go run cmd/templar/main.go --output-file output.txt example.tmpl --data-file {{data}}
cat output.txt
# Run Go Unit Tests
test-unit +data='':
just _term-wipe
@# go test
@# hr
go test -coverprofile=c.out
@hr
go tool cover -func=c.out
# Wipes the terminal buffer for a clean start
_term-wipe:
#!/bin/sh
if [[ ${#VISUAL_STUDIO_CODE} -gt 0 ]]; then
clear
elif [[ ${KITTY_WINDOW_ID} -gt 0 ]] || [[ ${#TMUX} -gt 0 ]] || [[ "${TERM_PROGRAM}" = 'vscode' ]]; then
printf '\033c'
elif [[ "$(uname)" == 'Darwin' ]] || [[ "${TERM_PROGRAM}" = 'Apple_Terminal' ]] || [[ "${TERM_PROGRAM}" = 'iTerm.app' ]]; then
osascript -e 'tell application "System Events" to keystroke "k" using command down'
elif [[ -x "$(which tput)" ]]; then
tput reset
elif [[ -x "$(which reset)" ]]; then
reset
else
clear
fi
@version:
cat templar.go | grep -F 'Version =' | cut -d'"' -f2