forked from carlosbrando/lunchy
/
status.go
53 lines (42 loc) · 922 Bytes
/
status.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
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2013 Carlos Brando. All rights reserved.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.
package main
import (
"fmt"
"regexp"
"strings"
"github.com/carlosbrando/lunchy/agents"
)
var headerPrinted bool = false
// printHeader prints the header if it was not printed before.
func printHeader(header string) {
if !headerPrinted {
fmt.Println(header)
headerPrinted = true
}
}
func (c *Command) status() error {
out, err := runCmd("launchctl", "list")
if err != nil {
return err
}
output := strings.Split(out, "\n")
agents, err := agents.Find(c.pattern)
if err != nil {
return err
}
for _, line := range output {
for _, agent := range agents {
matched, err := regexp.MatchString(agent.Name, line)
if err != nil {
return err
}
if matched {
printHeader(output[0])
fmt.Println(line)
}
}
}
return nil
}