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

package main

import (
	"fmt"
	"log"
	"os"

	"flag"

	"github.com/go-openapi/loads"
	"github.com/go-openapi/loads/fmts"

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

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

func main() {
	var server *restapi.Server

	flag.Usage = func() {
		fmt.Fprint(os.Stderr, "Usage:\n")
		fmt.Fprint(os.Stderr, "  simple-to-do-list-api-server [OPTIONS]\n\n")

		title := "Simple To Do List API"
		if title != "" {
			fmt.Fprintf(os.Stderr, "%s\n\n", title)
		}
		desc := "This is a simple todo list API\nillustrating go-swagger codegen\ncapabilities.\n"
		if desc != "" {
			fmt.Fprintf(os.Stderr, "%s\n\n", desc)
		}
		flag.CommandLine.SetOutput(os.Stderr)
		flag.PrintDefaults()
	}

	// parse the CLI flags
	flag.Parse()                    // exit on error
	server = restapi.NewServer(nil) // the server has no API set yet, but configuration from flags is retrieved at this point

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