Taskfile demo

https://github.com/yangyang5214/blog/issues/1

makefile 很好用,但是有些语法我不会。 go-task yml & shell 不错,推荐

Taskfile.yml

https://github.com/go-task/task/blob/main/.golangci.yml

yaml 复制代码
# go install github.com/go-task/task/v3/cmd/task@latest
version: '3'

vars:
  APPS: { sh: find app -maxdepth 1 -mindepth 1 -type d -print | xargs -L 1 }
  MODULE_NAME: { sh: go list -m }

tasks:
  desc: init go mod
  init:
    cmds:
      - go get -u google.golang.org/protobuf/cmd/protoc-gen-go
      - go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc
      - go get -u github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2
      - go get -u github.com/google/wire/cmd/wire
      - go get -u github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
      - go get -u github.com/envoyproxy/protoc-gen-validate
      - go get -u github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2
      - go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
      - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
      - go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
      - go install github.com/envoyproxy/protoc-gen-validate@latest
      - go install github.com/google/wire/cmd/wire@latest

  format:
    desc: Format *go code
    vars:
      GO_FILES: "find . ! -path './vendor/*' -type f -name '*.go'"
    cmds:
      - ({{.GO_FILES}} | xargs gofmt -s -w)
      - ({{.GO_FILES}} | xargs gci write --section Standard --section Default --section "Prefix({{.MODULE_NAME}})")
      - ({{.GO_FILES}} | xargs golines -w --max-len=180 --reformat-tags --shorten-comments --ignore-generated)
      - go mod edit -fmt

  wire:
    desc: Run wire cmd for apps
    cmds:
      - for: { var: APPS, as: APP }
        cmd: cd {{.APP}} && wire ./... && cd -
      - task format

  mod:
    desc: Downloads and tidy Go modules
    cmds:
      - go mod download
      - go mod tidy

  lint:
    desc: Run golangci-lint
    sources:
      - './**/*.go'
      - .golangci.yml
    cmds:
      - golangci-lint run

add zsh completion

https://github.com/sawadashota/go-task-completions

Clone the repository inside your oh-my-zsh repo:

git clone https://github.com/sawadashota/go-task-completions.git ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/task

Enable it in your .zshrc by adding it to your plugin list and reloading the completion:

# ... 是之前已经存在的 plugin 
# 例如我的修改为 plugins=(git task)
plugins=(... task)
autoload -U compinit && compinit

Reference

https://github.com/go-task/task/issues/103 Add Bash, ZSH and Windows command line completion #103

相关推荐
一个热爱生活的普通人34 分钟前
golang的切片(Slice)底层实现解析
后端·go
孤雪心殇2 天前
简单易懂,解析Go语言中的Map
开发语言·数据结构·后端·golang·go
zhuyasen2 天前
告别低效!Go 开发框架 Sponge 与 AI 助手深度联动,打造极速开发新体验
低代码·go·deepseek
NPE~3 天前
Bug:Goland debug失效详细解决步骤【合集】
go·bug·goland·dlv失效
喵个咪3 天前
开箱即用的GO后台管理系统 Kratos Admin - 交互式API文档 Swagger UI
后端·go·swagger
小石潭记丶4 天前
goland无法debug项目
go
千舟4 天前
自己动手编写tcp/ip协议栈4:tcp数据传输和四次挥手
网络协议·go
CHSnake4 天前
gRPC和gRPC-gateway
go
喵个咪5 天前
开箱即用的GO后台管理系统 Kratos Admin - 后端项目结构说明
后端·微服务·go
烛阴6 天前
Go语言内置包:提升开发效率的必备神器!
后端·go