Add --global (-g) flag (#1029)

This will run a Taskfile from the home directory, i.e., `$HOME/Taskfile.yml`.
This commit is contained in:
Andrey Nering
2023-03-08 23:21:23 -03:00
committed by GitHub
parent 68aef2ef0d
commit 9c844850e4
4 changed files with 54 additions and 0 deletions

View File

@@ -72,6 +72,7 @@ func main() {
output taskfile.Output
color bool
interval time.Duration
global bool
)
pflag.BoolVar(&versionFlag, "version", false, "show Task version")
@@ -98,6 +99,7 @@ func main() {
pflag.BoolVarP(&color, "color", "c", true, "colored output. Enabled by default. Set flag to false or use NO_COLOR=1 to disable")
pflag.IntVarP(&concurrency, "concurrency", "C", 0, "limit number tasks to run concurrently")
pflag.DurationVarP(&interval, "interval", "I", 0, "interval to watch for changes")
pflag.BoolVarP(&global, "global", "g", false, "runs global Taskfile, from $HOME/Taskfile.{yml,yaml}")
pflag.Parse()
if versionFlag {
@@ -121,6 +123,19 @@ func main() {
return
}
if global && dir != "" {
log.Fatal("task: You can't set both --global and --dir")
return
}
if global {
home, err := os.UserHomeDir()
if err != nil {
log.Fatal("task: Failed to get user home directory: %w", err)
return
}
dir = home
}
if dir != "" && entrypoint != "" {
log.Fatal("task: You can't set both --dir and --taskfile")
return