forked from TrueCloudLab/restic
options: Fix sorting (and test)
This commit is contained in:
parent
55bdc1fa16
commit
be06983c80
2 changed files with 7 additions and 2 deletions
|
@ -34,6 +34,8 @@ func appendAllOptions(opts []Help, ns string, cfg interface{}) []Help {
|
||||||
opt.Namespace = ns
|
opt.Namespace = ns
|
||||||
opts = append(opts, opt)
|
opts = append(opts, opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Sort(helpList(opts))
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +59,6 @@ func listOptions(cfg interface{}) (opts []Help) {
|
||||||
opts = append(opts, h)
|
opts = append(opts, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(helpList(opts))
|
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +79,10 @@ func (h helpList) Len() int {
|
||||||
// Less reports whether the element with
|
// Less reports whether the element with
|
||||||
// index i should sort before the element with index j.
|
// index i should sort before the element with index j.
|
||||||
func (h helpList) Less(i, j int) bool {
|
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
|
return h[i].Namespace < h[j].Namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -291,8 +291,8 @@ func TestAppendAllOptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
[]Help{
|
[]Help{
|
||||||
Help{Namespace: "local", Name: "foo", Text: "bar text 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: "bar", Text: "bar text help"},
|
||||||
|
Help{Namespace: "sftp", Name: "foo", Text: "bar text help2"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue