package main

import (
	"flag"
	"log"
	"os"

	"github.com/itzg/go-flagsfiller"
)

type cmd struct {
	cmd    func([]string, any)
	config any
}

func (c *cmd) Run() {
	if c.config != nil {
		flag.Parse()
		filler := flagsfiller.New()
		err := filler.Fill(flag.CommandLine, c.config)
		if err != nil {
			log.Fatal(err)
		}
		c.cmd(flag.Args()[1:], c.config)
	} else {
		c.cmd(os.Args[2:], c.config)
	}
}

var commands = map[string]cmd{
	"request": {
		request,
		nil,
	},
	"create": {
		create,
		&createFlags{},
	},
}
