// This is an auxillary program that prints the ANWORK API usage documentation
// to a file. The output is in Github markdown format.
//
// Usage: genapidoc <output-file>
package main

import (
	"fmt"
	"io"
	"os"

	"github.com/ankeesler/anwork/api"
)

func gendoc(output io.Writer) {
	fmt.Fprintln(output, "Generated by genapidoc. DO NOT EDIT.")
	fmt.Fprintln(output)

	fmt.Fprintln(output, "# _anwork_ API usage, version", api.Version)
	fmt.Fprintln(output)

	api.MarkdownUsage(output)
}

func main() {
	if len(os.Args) != 2 {
		fmt.Println("Usage: genapidoc <output-file>")
		os.Exit(1)
	}

	output := os.Args[1]
	fmt.Printf("Generating documentation into %s\n", output)

	outputFile, err := os.Create(output)
	defer outputFile.Close()
	if err != nil {
		fmt.Printf("Error! %s\n", err.Error())
		os.Exit(1)
	}

	gendoc(outputFile)

	fmt.Println("Done.")
}
