Skip to content

Commit

Permalink
Fix service flag parsing in main function
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Da Ros committed Feb 8, 2019
1 parent 69d1f35 commit c862f61
Showing 1 changed file with 24 additions and 32 deletions.
56 changes: 24 additions & 32 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,41 +77,33 @@ func (a *App) run() {
func main() {
a := &App{}
serviceControl, ok := viper.Get("service").(string)
if ok && serviceControl != "" {
switch serviceControl {
case "install":
configDir, ok := viper.Get("configDir").(string)
if !ok {
msg := "the -config-dir argument must be provided " +
"when installing the workflow connector as a service "
logger.Error(fmt.Errorf(msg))
os.Exit(1)
}
svc := newService(a, "-config-dir", configDir)
if err := service.Control(svc, serviceControl); err != nil {
logger.Error(err)
os.Exit(1)
}
err := svc.Run()
if err != nil {
logger.Errorf("unable to run the service: %s\n", err)
os.Exit(1)
}
default:
// Execute user specified control on service
svc := newService(a)
if err := service.Control(svc, serviceControl); err != nil {
logger.Error(err)
os.Exit(1)
}
err := svc.Run()
if err != nil {
logger.Errorf("unable to run the service: %s\n", err)
os.Exit(1)
}
if ok && serviceControl == "install" {
configDir, ok := viper.Get("configDir").(string)
if !ok {
msg := "the -config-dir argument must be provided " +
"when installing the workflow connector as a service "
logger.Error(fmt.Errorf(msg))
os.Exit(1)
}
svc := newService(a, "-config-dir", configDir)
if err := service.Control(svc, serviceControl); err != nil {
logger.Error(err)
os.Exit(1)
}
err := svc.Run()
if err != nil {
logger.Errorf("unable to run the service: %s\n", err)
os.Exit(1)
}
return
}
svc := newService(a)
err := svc.Run()
if err != nil {
logger.Errorf("unable to run the service: %s\n", err)
os.Exit(1)
}
return
}

func newService(a *App, args ...string) (svc service.Service) {
Expand Down

0 comments on commit c862f61

Please sign in to comment.