Files
tapir/cmd/tapir/env.go
T
mathiasandClaude Opus 4.8 d3498898c0 feat(cli): add read-only list and show subcommands
tapir list — table of stored summaries (date, title|id, channel, AI,
fallback), recent-first. tapir show <video-id> — full summary with
highlights and takeaways. DSN + user id from TAPIR_DB_DSN/TAPIR_USER_ID,
never hardcoded. main.go gains a minimal os.Args[1] dispatcher kept flat
so Worker F's auth/run cases union cleanly at merge.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-02 20:58:09 +02:00

36 lines
984 B
Go

package main
import (
"context"
"fmt"
"os"
"gitea.d-ma.be/mathias/tapir/internal/adapters/store"
)
// Env var names for the read-only CLI. DSN and user id are never hardcoded — the
// store holds confidential summaries, so the caller supplies both.
const (
envDSN = "TAPIR_DB_DSN"
envUserID = "TAPIR_USER_ID"
)
// openStoreFromEnv reads TAPIR_DB_DSN and TAPIR_USER_ID and opens a store. The
// returned close func releases the pool; callers defer it. Both vars are
// required: an empty value is a usage error, not a silent default.
func openStoreFromEnv(ctx context.Context) (s *store.Store, userID string, closeFn func(), err error) {
dsn := os.Getenv(envDSN)
if dsn == "" {
return nil, "", nil, fmt.Errorf("%s is required", envDSN)
}
userID = os.Getenv(envUserID)
if userID == "" {
return nil, "", nil, fmt.Errorf("%s is required", envUserID)
}
s, err = store.New(ctx, dsn)
if err != nil {
return nil, "", nil, err
}
return s, userID, s.Close, nil
}