// Code generated by go-swagger; DO NOT EDIT.

package main

import (
	"errors"
	"log"
	"os"

	flags "github.com/jessevdk/go-flags"

	"github.com/go-openapi/loads"

	"github.com/go-swagger/go-swagger/examples/tutorials/todo-list/server-1/restapi"
	"github.com/go-swagger/go-swagger/examples/tutorials/todo-list/server-1/restapi/operations"
)

func main() {
	swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
	if err != nil {
		log.Fatalln(err)
	}

	api := operations.NewTodoListAPI(swaggerSpec)
	server := restapi.NewServer(api)
	server.ConfigureFlags() // inject API-specific custom flags. Must be called before args parsing

	parser := flags.NewParser(server, flags.Default)
	parser.ShortDescription = "A To Do list application"
	parser.LongDescription = "The product of a tutorial on goswagger.io"
	for _, optsGroup := range api.CommandLineOptionsGroups {
		_, err := parser.AddGroup(optsGroup.ShortDescription, optsGroup.LongDescription, optsGroup.Options)
		if err != nil {
			log.Fatalln(err)
		}
	}

	if _, err := parser.Parse(); err != nil {
		code := 1
		fe := new(flags.Error)
		if errors.As(err, &fe) {
			if fe.Type == flags.ErrHelp {
				code = 0
			}
		}
		os.Exit(code)
	}

	server.ConfigureAPI() // configure handlers, routes and middleware

	if err := server.Serve(); err != nil {
		_ = server.Shutdown()

		log.Fatalln(err)
	}
}
