forked from carlosbrando/lunchy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.go
55 lines (43 loc) · 979 Bytes
/
system.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
54
55
// 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"
"github.com/carlosbrando/lunchy/agents"
)
func (c *Command) launchctl() error {
agent, err := agents.FindOne(c.pattern)
if err != nil {
return err
}
if agent != nil {
switch c.command {
case "start":
fmt.Println("starting", agent.Name)
case "stop":
fmt.Println("stopping", agent.Name)
case "restart":
c.clone("stop").launchctl()
c.clone("start").launchctl()
}
runCmd("launchctl", c.args(agent.Fullpath)...)
}
return nil
}
func (c *Command) args(more ...string) []string {
var args []string
if c.force {
args = append(args, "-F")
}
if c.write {
args = append(args, "-w")
}
switch c.command {
case "start":
args = append([]string{"load"}, args...)
case "stop":
args = append([]string{"unload"}, args...)
}
return append(args, more...)
}