diff --git a/internal/flags/flags.go b/internal/flags/flags.go index 7d437537..8c21193e 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -184,7 +184,7 @@ func WithExecutorOptions() task.ExecutorOption { var sorter sort.Sorter switch TaskSort { case "none": - sorter = nil + sorter = sort.NoSort case "alphanumeric": sorter = sort.AlphaNumeric } diff --git a/internal/sort/sorter.go b/internal/sort/sorter.go index 404bc84a..14195973 100644 --- a/internal/sort/sorter.go +++ b/internal/sort/sorter.go @@ -9,6 +9,11 @@ import ( // A Sorter is any function that sorts a set of tasks. type Sorter func(items []string, namespaces []string) []string +// NoSort leaves the tasks in the order they are defined. +func NoSort(items []string, namespaces []string) []string { + return items +} + // AlphaNumeric sorts the JSON output so that tasks are in alpha numeric order // by task name. func AlphaNumeric(items []string, namespaces []string) []string { diff --git a/internal/sort/sorter_test.go b/internal/sort/sorter_test.go index e55f0f0f..50a0071e 100644 --- a/internal/sort/sorter_test.go +++ b/internal/sort/sorter_test.go @@ -79,3 +79,35 @@ func TestAlphaNumeric_Sort(t *testing.T) { }) } } + +func TestNoSort_Sort(t *testing.T) { + t.Parallel() + + item1 := "a-item1" + item2 := "m-item2" + item3 := "ns1:item3" + item4 := "ns2:item4" + item5 := "z-item5" + item6 := "ns3:item6" + + tests := []struct { + name string + items []string + want []string + }{ + { + name: "all items in order of definition", + items: []string{item3, item2, item5, item1, item4, item6}, + want: []string{item3, item2, item5, item1, item4, item6}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + NoSort(tt.items, nil) + assert.Equal(t, tt.want, tt.items) + }) + } +}