package main

import (
	"fmt"
	"os"

	"go-doc/internal/swagger"

	"github.com/spf13/cobra"
)

var (
	version = "1.2.0"
	commit  = "dev"
	date    = "unknown"
)

func main() {
	rootCmd := &cobra.Command{
		Use:     "go-doc",
		Short:   "Generate Swagger documentation from go-zero API files",
		Long:    `go-doc is a tool that converts go-zero .api files into OpenAPI specifications (Swagger 2.0 or OpenAPI 3.0).`,
		Version: fmt.Sprintf("%s (commit: %s, built at: %s)", version, commit, date),
		RunE:    swagger.Command,
	}

	rootCmd.Flags().StringVarP(&swagger.VarStringAPI, "api", "a", "", "API file path (required)")
	rootCmd.Flags().StringVarP(&swagger.VarStringDir, "dir", "d", "", "Output directory (required)")
	rootCmd.Flags().StringVarP(&swagger.VarStringFilename, "filename", "f", "", "Output filename without extension (optional, defaults to API filename)")
	rootCmd.Flags().BoolVarP(&swagger.VarBoolYaml, "yaml", "y", false, "Generate YAML format instead of JSON")
	rootCmd.Flags().StringVarP(&swagger.VarStringSpecVersion, "spec-version", "s", "swagger2.0", "OpenAPI specification version: swagger2.0 or openapi3.0")

	if err := rootCmd.MarkFlagRequired("api"); err != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n", err)
		os.Exit(1)
	}
	if err := rootCmd.MarkFlagRequired("dir"); err != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n", err)
		os.Exit(1)
	}

	if err := rootCmd.Execute(); err != nil {
		os.Exit(1)
	}
}
