Fix empty ListMultiple.

This commit is contained in:
Nuno Cruces 2021-07-08 18:56:28 +01:00
parent e54d4e9414
commit 317cca7fc8
5 changed files with 15 additions and 7 deletions

View File

@ -474,8 +474,10 @@ func lstResult(l []string, err error) {
if err != nil {
errResult(err)
}
os.Stdout.WriteString(strings.Join(l, zenutil.Separator))
os.Stdout.WriteString(zenutil.LineBreak)
if len(l) > 0 {
os.Stdout.WriteString(strings.Join(l, zenutil.Separator))
os.Stdout.WriteString(zenutil.LineBreak)
}
os.Exit(0)
}

View File

@ -42,7 +42,7 @@ if(Array.isArray(res)){res.join({{json .Separator}})}else{res.toString()}
var app=Application.currentApplication()
app.includeStandardAdditions=true
var res=app.chooseFromList({{json .Items}},{{json .Options}})
res.join({{json .Separator}})
if(res.length!==0)res.join({{json .Separator}})
{{- end}}
{{define "notify" -}}
var app=Application.currentApplication()

View File

@ -2,4 +2,4 @@ var app = Application.currentApplication()
app.includeStandardAdditions = true
var res = app.chooseFromList({{json .Items}}, {{json .Options}})
res.join({{json .Separator}})
if (res.length !== 0) res.join({{json .Separator}})

View File

@ -71,8 +71,11 @@ func strResult(opts options, out []byte, err error) (string, error) {
func lstResult(opts options, out []byte, err error) ([]string, error) {
str, err := strResult(opts, out, err)
if err == nil {
return strings.Split(str, zenutil.Separator), nil
if err != nil {
return nil, err
}
return nil, err
if len(out) == 0 {
return []string{}, nil
}
return strings.Split(str, zenutil.Separator), nil
}

View File

@ -98,6 +98,9 @@ func Test_lstResult(t *testing.T) {
sentinel := errors.New("sentinel")
cancel := exec.Command("false").Run()
if out, err := lstResult(options{}, []byte(""), nil); !reflect.DeepEqual(out, []string{}) || err != nil {
t.Errorf(`lstResult("out", nil) = %v, %v`, out, err)
}
if out, err := lstResult(options{}, []byte("out"), nil); !reflect.DeepEqual(out, []string{"out"}) || err != nil {
t.Errorf(`lstResult("out", nil) = %v, %v`, out, err)
}