From 471df4d7a1654f35756a202e26a5d28815222012 Mon Sep 17 00:00:00 2001 From: David Schlachter Date: Thu, 8 Jan 2026 11:14:39 -0500 Subject: More flexible and better documentation --- main.go | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index e73b06f..55dc411 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,8 @@ package main import ( + "database/sql" + "flag" "log" "net/http" "time" @@ -12,26 +14,46 @@ import ( ) const ( - rawDictionary = "/home/david/work/french-wiktionary-flashcards/raw-wiktextract-data.jsonl" - dictionary = "dictionary.sqlite3" - - apiURL = "http://localhost:8765" - deckName = "Français" - modelName = "Basic-830ae" + apiURL = "http://localhost:8765" ) func main() { - db, err := setupDatabase() + rawDict := flag.String("rawDictionary", "raw-wiktextract-data.jsonl", "Path to the raw wiktionary data. You can get this by downloading and unzipping https://kaikki.org/frwiktionary/raw-wiktextract-data.jsonl.gz (for French).") + dict := flag.String("dictionary", "dictionary.sqlite3", "Path to the parsed dictionary data. This will be generated from rawDictionary.") + deckName := flag.String("deck", "", "Name of the deck where new Anki cards will be created.") + modelName := flag.String("model", "", "Name of the card type ('model') for new Anki cards.") + + flag.Parse() + + if dict == nil { + log.Fatal("The -dictionary flag cannot be an empty string. (If not provided, it defaults to dictionary.sqlite3.)") + } + if rawDict == nil { + log.Fatal("The -rawDictionary flag cannot be an empty string. (If not provided, it defaults to aw-wiktextract-data.jsonl.)") + } + if deckName == nil { + log.Fatal("The -deck flag must be provided (name of the deck where Anki cards will be created).") + } + if modelName == nil { + log.Fatal("The -model flag must be provided. This is the name of the card type ('model') for any Anki cards created by this program. This appears under 'Type' on the dialog for creating new cards in Anki.") + } + + db, err := sql.Open("sqlite3", *dict) if err != nil { - log.Fatalf("setting up database: %s", err) + log.Fatalf("Failed to create or open dictionary at '%s': %s", *dict, err) } defer db.Close() + err = setupDatabase(*rawDict, db) + if err != nil { + log.Fatalf("Failed to set up database: %s", err) + } + c := http.DefaultClient c.Timeout = 5 * time.Second - p := tea.NewProgram(initialModel(c, db)) + p := tea.NewProgram(initialModel(c, db, *deckName, *modelName)) if _, err := p.Run(); err != nil { - log.Fatal(err) + log.Fatalf("Unexpected error encountered while running program: %s", err) } } -- cgit v1.2.3