Skip to content
Snippets Groups Projects
cmd.gotmpl 1 KiB
Newer Older
// Code generated by go-swagger/go-orus-api; DO NOT EDIT.

package cmd

import (
	"github.com/orus-io/go-flags"
	orusapi "orus.io/orus-io/go-orus-api"
	"orus.io/orus-io/go-orus-api/database"
)

var (
	Logger = orusapi.DefaultLogger(os.Stdout)
	LoggingOptions  = orusapi.MustLoggingOptions(orusapi.NewLoggingOptions(&Logger, os.Stdout))
	DatabaseOptions = &database.Options{}

	parser = flags.NewNamedParser("{{ dasherize (pascalize .Name) }}", flags.HelpFlag|flags.PassDoubleDash)
)

func Run() int {
	if _, err := parser.Parse(); err != nil {
		code := 1
		if fe, ok := err.(*flags.Error); ok {
			if fe.Type == flags.ErrHelp {
				code = 0
				// this error actually contains a help message for the user
				// so we print it on the console
				fmt.Println(err)
			} else {
				log.Error().Msg(err.Error())
			}
		} else {
			log.Err(err).Msg("")
		}
		return code
	}
	return 0
}

func init() {
	parser.AddGroup("Logging", "Logging options", LoggingOptions)
	parser.AddGroup("Database", "Database options", DatabaseOptions)
}