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)
| 26 | // namespaced will be listed before tasks that are. We detect this by searching |
| 27 | // for a ':' in the task name. |
| 28 | func 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 | } |
searching dependent graphs…