Something went wrong. Try again.
Something went wrong. Try again.
record-keeper Taskfile
3.4 kB 123 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124#!/usr/bin/env bash# =========================================================# Taskfile gives you a set of quick tasks for your project.# Requires GNU awk + sed to be installed and available on# your system's path.## More info:# https://taskfile.sh/about# https://github.com/Enrise/Taskfile# https://taskfile.build# =========================================================
DATABASE_URL="record-keeper.db"TOOL_PREFIX="go tool -modfile tools/go.mod"GOOSE_CONFIG="-dir sql/migrations sqlite $DATABASE_URL"
# =========================================================## development# =========================================================function task:dev { ## run the application with reloading on file changes go run ./cmd/www}
# =========================================================## tools# =========================================================function task:up { ## migrate up the db $TOOL_PREFIX goose $GOOSE_CONFIG up}
function task:down { ## migrate down the db $TOOL_PREFIX goose $GOOSE_CONFIG down}
function task:goose { ## run the goose binary directly $TOOL_PREFIX goose $GOOSE_CONFIG "$@"}
function task:sqlc { ## run the sqlc binary directly $TOOL_PREFIX sqlc "$@"}
function task:stringer { ## run the stringer binary directly $TOOL_PREFIX stringer "$@"}
# =========================================================## build# =========================================================
function task:build { ## build the cmd/web application go build -o=./bin/www ./cmd/www}
function task:preview { ## run the cmd/web application task:build ./bin/web}
# =========================================================## testing# =========================================================
function task:test { ## run all tests go test -v -race -buildvcs ./...}
function task:coverage { ## run all tests and display coverage task:test go test -v -race -buildvcs -coverprofile=tmp/coverage.out ./... go tool cover -html=tmp/coverage.out}
# =========================================================## misc# =========================================================
function task:init { ## prepare project for local development task:tidy task:dev-deps task:help}
function task:upgradeable { ## list direct dependencies that have upgrades available go list -u -f '{{if (and (not (or .Main .Indirect)) .Update)}}{{.Path}}: {{.Version}} -> {{.Update.Version}}{{end}}' -m all}
# =========================================================## Taskfile# =========================================================
set -eo pipefail
BLUE=$(printf '\033[36m')YELLOW=$(printf '\033[33m')RED=$(printf '\033[31m')# shellcheck disable=2034GREEN=$(printf '\033[32m')RESET=$(printf '\033[0m')
function title { echo -e "\n${BLUE}=>${RESET} $1\n"}
function task:help { ## show all available tasks title "Available tasks" awk 'BEGIN {FS = " { [#][#][ ]?"} /^([a-zA-Z_-]*:?.*)(\{ )?[#][#][ ]?/ \ {printf "\033[33m%-34s\033[0m %s\n", $1, $2}' $0 |\ sed -E "s/[#]{2,}[ ]*/${RESET}/g" |\ sed -E "s/function task:*/ /g" echo -e "\n${BLUE}Usage:${RESET} ./Taskfile ${YELLOW}<task>${RESET} <args>"}
echo -e "${BLUE}Taskfile${RESET}"# shellcheck disable=2068,2145if [[ ! "$(declare -F task:${@-help})" ]]; then title "Task not found" echo -e "Task ${RED}$1${RESET} doesn't exist." task:help exit 1fi# shellcheck disable=2068,2145task:${@-help}