-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.go
40 lines (31 loc) · 765 Bytes
/
cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package cmd
import (
"errors"
"github.com/urfave/cli"
"github.com/firelizzard18/Tea-Service/client"
"github.com/firelizzard18/Tea-Service/cmds/_"
)
func init() {
cmds.Register("connect", "connect to a service").Executor(&Command{Command: client.CmdDefaults})
}
type Command struct {
client.Command
}
func (m *Command) Execute(c *cli.Context) error {
args := c.Args()
if len(args) != 1 {
return errors.New("Expected a single argument of the service to connect to")
}
cl, err := client.ConnectToDBus(c.GlobalString("dbus-bus"))
if err != nil {
return err
}
defer cl.Close()
out, err := cl.RequestOutput(args[0], m.GetOutType(), !m.Direct, m.Timeout)
if err != nil {
return err
}
defer out.Close()
client.DumpOutput(out)
return nil
}