Makefile 的另一個選擇 Taskfile

在 macOS 環境,除了使用 Makefile 之外,還有另一個選擇 Taskfile。

環境 Environment

  • macOS 12.3.1
  • Homebrew 3.4.5

安裝 Taskfile

Use brew command to install task

1
$ brew install go-task/tap/go-task

新增 Taskfile

Create Taskfile.yml and insert the following,

1
2
3
4
5
6
7
8
9
10
11
12
version: "3"

tasks:
build:
desc: Build the app
cmds:
- GOFLAGS=-mod=mod go build -o ./bin/app ./internal/main.go

run:
desc: Run the app
cmds:
- GOFLAGS=-mod=mod go run ./internal/main.go

Display the list of available tasks:

1
2
3
4
$ task --list
task: Available tasks for this project:
* build: Build the app
* run: Run the app

執行 Taskfile command

1
2
3
$ task run
task: [run] GOFLAGS=-mod=mod go run ./internal/main.go
...

進階使用可參考 Introduction to Taskfile: a Makefile alternative

參考資料 References