Skip to content

Commit 5cb7d0e

Browse files
committed
commands: slices - backport slices.SortFunc
1 parent c05eb63 commit 5cb7d0e

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

internal/commands/mount.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"flag"
88
"fmt"
99
"io/fs"
10-
"slices"
1110
"strings"
1211

1312
"github.com/djdv/go-filesystem-utils/internal/command"
@@ -255,18 +254,6 @@ func makeMountSubcommands() []command.Command {
255254
return hosts
256255
}
257256

258-
func sortCommands(commands []command.Command) {
259-
slices.SortFunc(
260-
commands,
261-
func(a, b command.Command) int {
262-
return strings.Compare(
263-
a.Name(),
264-
b.Name(),
265-
)
266-
},
267-
)
268-
}
269-
270257
func makeMountSubcommand(host filesystem.Host, guestCommands []command.Command) command.Command {
271258
var (
272259
formalName = string(host)

internal/commands/slices_20.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build !go1.21
2+
3+
package commands
4+
5+
import (
6+
"github.com/djdv/go-filesystem-utils/internal/command"
7+
"golang.org/x/exp/slices"
8+
)
9+
10+
func sortCommands(commands []command.Command) {
11+
slices.SortFunc(commands, func(a, b command.Command) bool {
12+
return a.Name() < b.Name()
13+
})
14+
}

internal/commands/slices_21.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//go:build go1.21
2+
3+
package commands
4+
5+
import (
6+
"slices"
7+
"strings"
8+
9+
"github.com/djdv/go-filesystem-utils/internal/command"
10+
)
11+
12+
func sortCommands(commands []command.Command) {
13+
slices.SortFunc(
14+
commands,
15+
func(a, b command.Command) int {
16+
return strings.Compare(
17+
a.Name(),
18+
b.Name(),
19+
)
20+
},
21+
)
22+
}

0 commit comments

Comments
 (0)