// 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-openapi/loads/fmts"

	"github.com/go-swagger/go-swagger/examples/flags/xgo-flags/restapi"
	"github.com/go-swagger/go-swagger/examples/flags/xgo-flags/restapi/operations"
)

func init() {
	loads.AddLoader(fmts.YAMLMatcher, fmts.YAMLDoc)
}

func main() {
	server := restapi.NewServer(nil)

	parser := flags.NewParser(server, flags.Default)
	parser.ShortDescription = "Simple To Do List API"
	parser.LongDescription = "This is a simple todo list API\nillustrating go-swagger codegen\ncapabilities.\n"

	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)
	}

	// spec loaded at run time from the provided CLI flags
	if server.Spec == "" {
		log.Fatalln("a spec must be provided by the command line")
	}

	swaggerSpec, err := loads.Spec(string(server.Spec))
	if err != nil {
		log.Fatalln(err)
	}
	api := operations.NewSimpleToDoListAPIAPI(swaggerSpec)
	server.SetAPI(api)

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

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

		log.Fatalln(err)
	}
}
