resolveTaskDir determines the task directory using proper precedence.
()
| 190 | |
| 191 | // resolveTaskDir determines the task directory using proper precedence. |
| 192 | func resolveTaskDir() string { |
| 193 | // --project flag takes highest precedence |
| 194 | if projectFlag != "" { |
| 195 | dir, err := resolveProjectDir(projectFlag) |
| 196 | if err != nil { |
| 197 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) |
| 198 | os.Exit(1) |
| 199 | } |
| 200 | return dir |
| 201 | } |
| 202 | |
| 203 | // Check if --task-dir or --dir was explicitly passed on the CLI |
| 204 | taskDirFlag := rootCmd.PersistentFlags().Lookup("task-dir") |
| 205 | dirFlag := rootCmd.PersistentFlags().Lookup("dir") |
| 206 | |
| 207 | if taskDirFlag != nil && taskDirFlag.Changed { |
| 208 | return taskDirFlag.Value.String() |
| 209 | } |
| 210 | if dirFlag != nil && dirFlag.Changed { |
| 211 | return dirFlag.Value.String() |
| 212 | } |
| 213 | |
| 214 | // Check config file: support both "task-dir" and "dir" YAML keys. |
| 215 | // We must bypass viper's pflag binding (which returns the flag default) |
| 216 | // by checking the config file values directly via viper.InConfig. |
| 217 | if viper.InConfig("task-dir") { |
| 218 | return resolveRelativeToConfig(viper.GetString("task-dir")) |
| 219 | } |
| 220 | if viper.InConfig("dir") { |
| 221 | return resolveRelativeToConfig(viper.GetString("dir")) |
| 222 | } |
| 223 | |
| 224 | // Fall back to the taskDir variable (set directly in tests) |
| 225 | if taskDir != "" { |
| 226 | return taskDir |
| 227 | } |
| 228 | |
| 229 | // No local config found — check for default_project in global config |
| 230 | if dir := resolveDefaultProject(); dir != "" { |
| 231 | return dir |
| 232 | } |
| 233 | |
| 234 | return "." |
| 235 | } |
| 236 | |
| 237 | // GlobalFlags holds global flag values |
| 238 | type GlobalFlags struct { |