mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +00:00
options: Fix sorting (and test)
This commit is contained in:
parent
55bdc1fa16
commit
be06983c80
@ -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
|
||||
}
|
||||
|
||||
|
@ -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"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user