UUBulb 0a890a2021
make edit and service flag subcommands (#77)
* make edit and service argument subcommands

* generate uuid if non-exist, use default report_delay or ip_report_period value if not specified
2024-10-23 22:34:59 +08:00

38 lines
501 B
Go

package commands
import (
"os"
"github.com/nezhahq/service"
)
type Program struct {
Exit chan struct{}
Service service.Service
Run func()
}
func (p *Program) Start(s service.Service) error {
go p.run()
return nil
}
func (p *Program) Stop(s service.Service) error {
close(p.Exit)
if service.Interactive() {
os.Exit(0)
}
return nil
}
func (p *Program) run() {
defer func() {
if service.Interactive() {
p.Stop(p.Service)
} else {
p.Service.Stop()
}
}()
p.Run()
}