Merge pull request #3192 from DRON-666/fix-options

Fix formatting of `restic options` command
This commit is contained in:
MichaelEischer 2020-12-23 22:53:40 +01:00 committed by GitHub
commit 9c41e4a343
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 8 deletions

View file

@ -23,8 +23,14 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("All Extended Options:\n")
var maxLen int
for _, opt := range options.List() {
fmt.Printf(" %-15s %s\n", opt.Namespace+"."+opt.Name, opt.Text)
if l := len(opt.Namespace + "." + opt.Name); l > maxLen {
maxLen = l
}
}
for _, opt := range options.List() {
fmt.Printf(" %*s %s\n", -maxLen, opt.Namespace+"."+opt.Name, opt.Text)
}
},
}

View file

@ -125,6 +125,7 @@ type Target struct {
Name string `option:"name"`
ID int `option:"id"`
Timeout time.Duration `option:"timeout"`
Switch bool `option:"switch"`
Other string
}
@ -155,7 +156,15 @@ var setTests = []struct {
"timeout": "10m3s",
},
Target{
Timeout: time.Duration(10*time.Minute + 3*time.Second),
Timeout: 10*time.Minute + 3*time.Second,
},
},
{
Options{
"switch": "true",
},
Target{
Switch: true,
},
},
}
@ -202,6 +211,13 @@ var invalidSetTests = []struct {
"ns",
`time: missing unit in duration "?2134"?`,
},
{
Options{
"switch": "yes",
},
"ns",
`strconv.ParseBool: parsing "yes": invalid syntax`,
},
}
func TestOptionsApplyInvalid(t *testing.T) {
@ -213,9 +229,9 @@ func TestOptionsApplyInvalid(t *testing.T) {
t.Fatalf("expected error %v not found", test.err)
}
matched, err := regexp.MatchString(test.err, err.Error())
if err != nil {
t.Fatal(err)
matched, e := regexp.MatchString(test.err, err.Error())
if e != nil {
t.Fatal(e)
}
if !matched {
@ -226,11 +242,11 @@ func TestOptionsApplyInvalid(t *testing.T) {
}
func TestListOptions(t *testing.T) {
var teststruct = struct {
teststruct := struct {
Foo string `option:"foo" help:"bar text help"`
}{}
var tests = []struct {
tests := []struct {
cfg interface{}
opts []Help
}{
@ -281,7 +297,7 @@ func TestListOptions(t *testing.T) {
}
func TestAppendAllOptions(t *testing.T) {
var tests = []struct {
tests := []struct {
cfgs map[string]interface{}
opts []Help
}{