Skip to content

Commit beeb966

Browse files
committed
Add a 'daemon status' command
1 parent 9793c1c commit beeb966

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

common/service.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,22 @@ func (srv Service) Disable() error {
120120

121121
return nil
122122
}
123+
124+
func (srv Service) Status() error {
125+
status, err := srv.Service.Status()
126+
if err != nil {
127+
return tracerr.Wrap(err)
128+
}
129+
130+
switch status {
131+
case service.StatusRunning:
132+
fmt.Println("git-auto-sync-daemon is Running!")
133+
case service.StatusStopped:
134+
fmt.Println("git-auto-sync-daemon is NOT Running!")
135+
case service.StatusUnknown:
136+
default:
137+
fmt.Println("git-auto-sync-daemon status is Unknown. How mysterious!")
138+
}
139+
140+
return nil
141+
}

daemon.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,31 @@ import (
1616

1717
var errRepoPathInvalid = errors.New("Not a valid git repo")
1818

19-
// func daemonStatus(ctx *cli.Context) error {
20-
// FIXME: Implement 'daemonStatus'
19+
func daemonStatus(ctx *cli.Context) error {
20+
s, err := common.NewService()
21+
if err != nil {
22+
return tracerr.Wrap(err)
23+
}
24+
25+
err = s.Status()
26+
if err != nil {
27+
return tracerr.Wrap(err)
28+
}
29+
30+
config, err := cfg.Read()
31+
if err != nil {
32+
return tracerr.Wrap(err)
33+
}
2134

22-
// Print out the configuration
23-
// Print out uptime
24-
// Print out if there are any 'rebasing' issues and we are paused
35+
fmt.Println("Monitoring - ")
36+
for _, repoPath := range config.Repos {
37+
fmt.Println(" ", repoPath)
38+
}
39+
40+
// FIXME: Print out if there are any 'rebasing' issues and we are paused
2541

26-
// return nil
27-
// }
42+
return nil
43+
}
2844

2945
func daemonList(ctx *cli.Context) error {
3046
config, err := cfg.Read()

main.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,11 @@ func main() {
104104
Aliases: []string{"d"},
105105
Usage: "Interact with the background daemon",
106106
Subcommands: []*cli.Command{
107-
// FIXME: Add a command to show the daemon's logs
108-
// {
109-
// Name: "status",
110-
// Usage: "Show the Daemon's status",
111-
// Action: daemonStatus,
112-
// },
107+
{
108+
Name: "status",
109+
Usage: "Show the Daemon's status",
110+
Action: daemonStatus,
111+
},
113112
{
114113
Name: "list",
115114
Aliases: []string{"ls"},

0 commit comments

Comments
 (0)