feat(cli): add CLI for managing RSVPs and photo uploads

* implement runCLI function to handle subcommands
* add runRSVPCLI and runPhotosCLI for RSVP and photo management
* include usage instructions for CLI commands
* integrate CLI execution in main function
This commit is contained in:
2026-08-23 11:45:48 +02:00
parent 79e4c11a16
commit f96465b798
4 changed files with 347 additions and 4 deletions
+13 -3
View File
@@ -37,6 +37,12 @@ func main() {
if err != nil {
log.Fatalf("store: %v", err)
}
if len(os.Args) > 1 {
code := runCLI(cfg.Storage.DataDir, st, os.Args[1:])
st.Close()
os.Exit(code)
}
defer st.Close()
mailer := mail.New(cfg.Email)
@@ -85,12 +91,16 @@ func main() {
func staticHandler(fsys fs.FS) http.Handler {
fileServer := http.FileServer(http.FS(fsys))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
p := strings.TrimPrefix(r.URL.Path, "/")
p := strings.TrimSuffix(strings.TrimPrefix(r.URL.Path, "/"), "/")
if p == "" {
p = "index.html"
}
if _, err := fs.Stat(fsys, p); err != nil {
if _, err := fs.Stat(fsys, p+".html"); err == nil {
// A route name (e.g. "photos") can collide with a static asset
// directory of the same name; prefer the prerendered page in
// that case instead of falling through to a directory listing.
info, statErr := fs.Stat(fsys, p)
if statErr != nil || info.IsDir() {
if hinfo, err := fs.Stat(fsys, p+".html"); err == nil && !hinfo.IsDir() {
r2 := *r
r2.URL.Path = "/" + p + ".html"
fileServer.ServeHTTP(w, &r2)