mirror of
https://github.com/go-task/task.git
synced 2026-09-02 04:02:08 +02:00
CLI variables are global to the invocation, not scoped to a task: `args.Parse` turns every word holding `=` into a global and every other word into a call, so `task build ENV=dev deploy` and `task build deploy ENV=dev` are the same command. The engine assumed the opposite and, as soon as a word matched a task, served only that task's variables — nothing at all when it had none. `task build <TAB>` and even `task build de<TAB>` went silent, where all five legacy wrappers offered task names at every position. The engine now unions the still-unset requirements of every task named on the line, and falls through to task names once they are all set. The line resolves itself: fill in what blocks execution, then add another task. Keeping the two families exclusive means each keeps a coherent directive, so nothing loses its trailing space. Task words are matched with FindMatchingTasks instead of a hand-built list of names truncated at their first `*`, which is why `task wildcard-foo <TAB>` used to offer task names rather than the variables of `wildcard-*`. Completion also disables fuzzy matching: a suggestion list has no "did you mean". Three fixes ride along. `--sort default` left the sorter nil and cleared the one NewExecutor had set, so completion listed tasks in Taskfile order while `--list` sorted them — and a single templated description silently restored the sort through GetTaskList. The bash wrapper never defined KeepOrder, losing the declaration order of `requires`; it now passes `compopt -o nosort`, which bash 3.2 ignores as it already ignores nospace. And the shell suite unsets TASK_EXE and GO_TASK_PROGNAME: fish, Nushell and PowerShell resolve the binary through them, so an ambient value silently tested something other than the binary just built.
24 lines
702 B
Go
24 lines
702 B
Go
package flags_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/go-task/task/v3"
|
|
"github.com/go-task/task/v3/internal/flags"
|
|
)
|
|
|
|
// WithFlags applies WithTaskSorter after NewExecutor set its default, so an
|
|
// unset --sort must still resolve to a sorter instead of clearing it.
|
|
func TestWithFlags_DefaultSorterIsNotCleared(t *testing.T) { //nolint:paralleltest // mutates package state
|
|
original := flags.TaskSort
|
|
t.Cleanup(func() { flags.TaskSort = original })
|
|
|
|
for _, sort := range []string{"", "default"} {
|
|
flags.TaskSort = sort
|
|
e := task.NewExecutor(flags.WithFlags())
|
|
require.NotNilf(t, e.TaskSorter, "--sort %q left the executor without a sorter", sort)
|
|
}
|
|
}
|