Skip to content

Commit

Permalink
handle help and wrong flags
Browse files Browse the repository at this point in the history
  • Loading branch information
swaroopar committed Sep 27, 2023
1 parent d44fde4 commit a6213fa
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/eclipse-xpanse/policy-man/config"
"github.com/eclipse-xpanse/policy-man/log"
"github.com/eclipse-xpanse/policy-man/server"
"github.com/spf13/pflag"
)

// Add comments to describe server openAPI information
Expand All @@ -22,14 +23,20 @@ func main() {

cfg, err := config.LoadConf()
if err != nil {
fmt.Print("load config failed")
fmt.Print("loading config failed\n")
return
}

if err = log.InitLog(cfg.Log.Level, cfg.Log.Path); err != nil {
return
}

ctx := context.Background()

if isFlagPassed("help") {
return
}

go func() {
err := server.RunHTTPServer(ctx, cfg)
if err != nil {
Expand All @@ -40,3 +47,14 @@ func main() {

<-ctx.Done()
}

func isFlagPassed(name string) bool {
found := false
config.RootCmd.Flags().Visit(func(flag *pflag.Flag) {
if flag.Name == name {
found = true
return
}
})
return found
}

0 comments on commit a6213fa

Please sign in to comment.