2023-10-07 16:53:14 +02:00
|
|
|
package sway
|
|
|
|
|
|
|
|
import (
|
2024-02-14 15:12:39 +01:00
|
|
|
"git.milar.in/milarin/slices"
|
2023-10-07 16:53:14 +02:00
|
|
|
)
|
|
|
|
|
2024-02-14 17:21:50 +01:00
|
|
|
// RunCommand runs all provided commands.
|
|
|
|
// It will return an array of errors
|
|
|
|
// which represent the result of each command.
|
|
|
|
// The last error is for communication problems only.
|
2024-02-14 16:48:50 +01:00
|
|
|
func (c *Client) RunCommand(cmd string) ([]error, error) {
|
2024-02-14 16:36:12 +01:00
|
|
|
results, err := sendMessage[[]commandResult](c, 0, cmd)
|
|
|
|
if err != nil {
|
2024-02-14 15:12:39 +01:00
|
|
|
return nil, err
|
2023-10-07 16:53:14 +02:00
|
|
|
}
|
|
|
|
|
2024-02-14 15:12:39 +01:00
|
|
|
errors := slices.Map(slices.Filter(results, commandResult.HasError), commandResult.GetError)
|
|
|
|
return errors, nil
|
2023-10-07 16:53:14 +02:00
|
|
|
}
|