diff --git a/src/restic/options/options.go b/src/restic/options/options.go index 03d06c32d..55ef59609 100644 --- a/src/restic/options/options.go +++ b/src/restic/options/options.go @@ -34,6 +34,8 @@ func appendAllOptions(opts []Help, ns string, cfg interface{}) []Help { opt.Namespace = ns opts = append(opts, opt) } + + sort.Sort(helpList(opts)) return opts } @@ -57,7 +59,6 @@ func listOptions(cfg interface{}) (opts []Help) { opts = append(opts, h) } - sort.Sort(helpList(opts)) return opts } @@ -78,6 +79,10 @@ func (h helpList) Len() int { // Less reports whether the element with // index i should sort before the element with index j. func (h helpList) Less(i, j int) bool { + if h[i].Namespace == h[j].Namespace { + return h[i].Name < h[j].Name + } + return h[i].Namespace < h[j].Namespace } diff --git a/src/restic/options/options_test.go b/src/restic/options/options_test.go index 7b9eb7db8..f5d43b9a7 100644 --- a/src/restic/options/options_test.go +++ b/src/restic/options/options_test.go @@ -291,8 +291,8 @@ func TestAppendAllOptions(t *testing.T) { }, []Help{ Help{Namespace: "local", Name: "foo", Text: "bar text help"}, - Help{Namespace: "sftp", Name: "foo", Text: "bar text help2"}, Help{Namespace: "sftp", Name: "bar", Text: "bar text help"}, + Help{Namespace: "sftp", Name: "foo", Text: "bar text help2"}, }, }, }