summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md12
-rw-r--r--add.go2
-rw-r--r--main.go7
-rw-r--r--ui.go6
4 files changed, 14 insertions, 13 deletions
diff --git a/README.md b/README.md
index e1605de..ee4d8eb 100644
--- a/README.md
+++ b/README.md
@@ -22,19 +22,21 @@ go run . -rawDictionary=raw-wiktextract-data.jsonl -deck="Français" -model="Bas
```
Usage of french-wiktionary-flashcards:
+ -apiURL string
+ Base URL to access the anki-connect plugin API. (default
+ "http://localhost:8765")
-deck string
- Name of the deck where new Anki cards will be created.
+ Name of the deck where new Anki cards will be created.
-dictionary string
- Path to the parsed dictionary data. This will be generated
+ Path to the parsed dictionary data. This will be generated
from rawDictionary. (default "dictionary.sqlite3")
-model string
- Name of the card type ('model') for new Anki cards.
+ Name of the card type ('model') for new Anki cards.
-rawDictionary string
- Path to the raw wiktionary data. You can get this by
+ 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). (default "raw-wiktextract-data.jsonl")
-
```
# TODO
diff --git a/add.go b/add.go
index baabef7..5116c86 100644
--- a/add.go
+++ b/add.go
@@ -41,7 +41,7 @@ type options struct {
DuplicateScope string `json:"duplicateScope"`
}
-func addCard(c *http.Client, deckName, modelName, front, back string) tea.Cmd {
+func addCard(c *http.Client, apiURL, deckName, modelName, front, back string) tea.Cmd {
return func() tea.Msg {
if back == "" {
return errMsg(errors.New("definition is blank"))
diff --git a/main.go b/main.go
index 55dc411..9dacd95 100644
--- a/main.go
+++ b/main.go
@@ -13,15 +13,12 @@ import (
_ "github.com/mattn/go-sqlite3"
)
-const (
- apiURL = "http://localhost:8765"
-)
-
func main() {
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.")
+ apiURL := flag.String("apiURL", "http://localhost:8765", "Base URL to access the anki-connect plugin API.")
flag.Parse()
@@ -52,7 +49,7 @@ func main() {
c := http.DefaultClient
c.Timeout = 5 * time.Second
- p := tea.NewProgram(initialModel(c, db, *deckName, *modelName))
+ p := tea.NewProgram(initialModel(c, db, *apiURL, *deckName, *modelName))
if _, err := p.Run(); err != nil {
log.Fatalf("Unexpected error encountered while running program: %s", err)
}
diff --git a/ui.go b/ui.go
index 9855203..e4eb311 100644
--- a/ui.go
+++ b/ui.go
@@ -27,6 +27,7 @@ type model struct {
vp viewport.Model
ankiDeck string
ankiModel string
+ apiURL string
}
type (
@@ -35,7 +36,7 @@ type (
wordAddedMsg string
)
-func initialModel(c *http.Client, db *sql.DB, ankiDeck, ankiModel string) model {
+func initialModel(c *http.Client, db *sql.DB, apiURL, ankiDeck, ankiModel string) model {
ti := textinput.New()
ti.Placeholder = ""
ti.Focus()
@@ -53,6 +54,7 @@ func initialModel(c *http.Client, db *sql.DB, ankiDeck, ankiModel string) model
vp: vp,
ankiDeck: ankiDeck,
ankiModel: ankiModel,
+ apiURL: apiURL,
}
}
@@ -109,7 +111,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.wordInput.SetValue("")
m.vp.SetContent("")
case tea.KeyEnter:
- return m, addCard(m.c, m.ankiDeck, m.ankiModel, m.currentWord, m.currentDefinition)
+ return m, addCard(m.c, m.apiURL, m.ankiDeck, m.ankiModel, m.currentWord, m.currentDefinition)
}
case errMsg: