Dan Anglin
cee274318d
Create new FlagSets to create new subcommands. - The version subcommand prints the version and build info. - The generate subcommand generates the CV PDF documentation.
39 lines
677 B
Go
39 lines
677 B
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
type Runner interface {
|
|
Parse([]string) error
|
|
Name() string
|
|
Run() error
|
|
}
|
|
|
|
//go:embed templates/tex/*
|
|
var templates embed.FS
|
|
|
|
func main() {
|
|
commandMap := map[string]Runner{
|
|
"version": NewVersionCommand(),
|
|
"generate": NewGenerateCommand(),
|
|
}
|
|
|
|
subcommand := os.Args[1]
|
|
|
|
runner, ok := commandMap[subcommand]
|
|
|
|
if !ok {
|
|
log.Fatalf("ERROR: unknown subcommand '%s'.", subcommand)
|
|
}
|
|
|
|
if err := runner.Parse(os.Args[2:]); err != nil {
|
|
log.Fatalf("ERROR: unable to parse the command line flags; %v.", err)
|
|
}
|
|
|
|
if err := runner.Run(); err != nil {
|
|
log.Fatalf("ERROR: unable to run '%s'; %v.", runner.Name(), err)
|
|
}
|
|
}
|