cmd/cli: Capitalizing launchd status error message

This commit is contained in:
Cuong Manh Le
2024-07-22 23:39:53 +07:00
committed by Cuong Manh Le
parent 50ef00526e
commit 139dd62ff3
+10 -2
View File
@@ -29,7 +29,7 @@ func newService(i service.Interface, c *service.Config) (service.Service, error)
case s.Platform() == "linux-systemd": case s.Platform() == "linux-systemd":
return &systemd{s}, nil return &systemd{s}, nil
case s.Platform() == "darwin-launchd": case s.Platform() == "darwin-launchd":
return &launchd{s}, nil return newLaunchd(s), nil
} }
return s, nil return s, nil
@@ -130,17 +130,25 @@ func (s *systemd) Status() (service.Status, error) {
return s.Service.Status() return s.Service.Status()
} }
func newLaunchd(s service.Service) *launchd {
return &launchd{
Service: s,
statusErrMsg: "Permission denied",
}
}
// launchd wraps a service.Service, and provide status command to // launchd wraps a service.Service, and provide status command to
// report the status correctly when not running as root on Darwin. // report the status correctly when not running as root on Darwin.
// //
// TODO: remove this wrapper once https://github.com/kardianos/service/issues/400 fixed. // TODO: remove this wrapper once https://github.com/kardianos/service/issues/400 fixed.
type launchd struct { type launchd struct {
service.Service service.Service
statusErrMsg string
} }
func (l *launchd) Status() (service.Status, error) { func (l *launchd) Status() (service.Status, error) {
if os.Geteuid() != 0 { if os.Geteuid() != 0 {
return service.StatusUnknown, errors.New("permission denied") return service.StatusUnknown, errors.New(l.statusErrMsg)
} }
return l.Service.Status() return l.Service.Status()
} }