(ctx *snap.Context)
| 59 | } |
| 60 | |
| 61 | func resolveTaskfilePath(ctx *snap.Context) (string, error) { |
| 62 | var fileFlag string |
| 63 | args := make([]string, 0, ctx.NArgs()) |
| 64 | for i := 0; i < ctx.NArgs(); i++ { |
| 65 | arg := strings.TrimSpace(ctx.Arg(i)) |
| 66 | if arg == "" { |
| 67 | continue |
| 68 | } |
| 69 | args = append(args, arg) |
| 70 | } |
| 71 | |
| 72 | for i := 0; i < len(args); i++ { |
| 73 | switch args[i] { |
| 74 | case "-f", "--file": |
| 75 | if i+1 >= len(args) { |
| 76 | return "", fmt.Errorf("missing value for %s", args[i]) |
| 77 | } |
| 78 | fileFlag = args[i+1] |
| 79 | i++ |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | if fileFlag != "" { |
| 84 | path, err := expandUserPath(fileFlag) |
| 85 | if err != nil { |
| 86 | return "", fmt.Errorf("expand taskfile path: %w", err) |
| 87 | } |
| 88 | abs, err := filepath.Abs(path) |
| 89 | if err != nil { |
| 90 | return "", fmt.Errorf("resolve taskfile path: %w", err) |
| 91 | } |
| 92 | return filepath.Clean(abs), nil |
| 93 | } |
| 94 | |
| 95 | candidates := []string{"Taskfile.yml", "Taskfile.yaml"} |
| 96 | for _, candidate := range candidates { |
| 97 | if _, err := os.Stat(candidate); err == nil { |
| 98 | abs, err := filepath.Abs(candidate) |
| 99 | if err != nil { |
| 100 | return "", err |
| 101 | } |
| 102 | return filepath.Clean(abs), nil |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | return "", fmt.Errorf("Taskfile.yml not found (use --file to specify path)") |
| 107 | } |
no test coverage detected