MCPcopy Index your code
hub / github.com/go-task/task / AlphaNumericWithRootTasksFirst

Function AlphaNumericWithRootTasksFirst

internal/sort/sorter.go:28–44  ·  view source on GitHub ↗

AlphaNumericWithRootTasksFirst sorts the JSON output so that tasks are in alpha numeric order by task name. It will also ensure that tasks that are not namespaced will be listed before tasks that are. We detect this by searching for a ':' in the task name.

(items []string, namespaces []string)

Source from the content-addressed store, hash-verified

26// namespaced will be listed before tasks that are. We detect this by searching
27// for a ':' in the task name.
28func AlphaNumericWithRootTasksFirst(items []string, namespaces []string) []string {
29 if len(namespaces) > 0 {
30 return AlphaNumeric(items, namespaces)
31 }
32 sort.Slice(items, func(i, j int) bool {
33 iContainsColon := strings.Contains(items[i], ":")
34 jContainsColon := strings.Contains(items[j], ":")
35 if iContainsColon == jContainsColon {
36 return items[i] < items[j]
37 }
38 if !iContainsColon && jContainsColon {
39 return true
40 }
41 return false
42 })
43 return items
44}

Calls 1

AlphaNumericFunction · 0.85

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…