all repos

anpi @ 2ef9e52b45dd5ef6b734c944cf861c4e633597ad

yaml to anki importer
3 files changed, 19 insertions(+), 4 deletions(-)
add cli interface
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2025-04-30 18:24:05 +0300
Parent: bf3f487
M go.mod
···
        3
        3
         go 1.24.2

      
        4
        4
         

      
        5
        5
         require (

      
        
        6
        +	github.com/alecthomas/kong v1.10.0

      
        6
        7
         	github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b

      
        7
        8
         	gopkg.in/yaml.v3 v3.0.1

      
        8
        9
         )

      
M go.sum
···
        
        1
        +github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=

      
        
        2
        +github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=

      
        
        3
        +github.com/alecthomas/kong v1.10.0 h1:8K4rGDpT7Iu+jEXCIJUeKqvpwZHbsFRoebLbnzlmrpw=

      
        
        4
        +github.com/alecthomas/kong v1.10.0/go.mod h1:p2vqieVMeTAnaC83txKtXe8FLke2X07aruPWXyMPQrU=

      
        
        5
        +github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=

      
        
        6
        +github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=

      
        1
        7
         github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b h1:EY/KpStFl60qA17CptGXhwfZ+k1sFNJIUNR8DdbcuUk=

      
        2
        8
         github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=

      
        
        9
        +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=

      
        
        10
        +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=

      
        3
        11
         gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

      
        4
        12
         gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

      
        5
        13
         gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

      
M main.go
···
        4
        4
         	"fmt"

      
        5
        5
         	"log/slog"

      
        6
        6
         	"os"

      
        
        7
        +	"path/filepath"

      
        7
        8
         	"strings"

      
        8
        9
         

      
        
        10
        +	"github.com/alecthomas/kong"

      
        9
        11
         	"github.com/gomarkdown/markdown"

      
        10
        12
         	"github.com/gomarkdown/markdown/html"

      
        11
        13
         	mdParser "github.com/gomarkdown/markdown/parser"

      ···
        13
        15
         	"github.com/olexsmir/anpi/parser"

      
        14
        16
         )

      
        15
        17
         

      
        16
        
        -const importFile = "import.yml"

      
        
        18
        +//nolint:gochecknoglobals // comment to make linter happy

      
        
        19
        +var cli struct {

      
        
        20
        +	File string `help:"path to import file" name:"file" type:"path"`

      
        
        21
        +}

      
        17
        22
         

      
        18
        23
         func main() {

      
        19
        
        -	if err := run(); err != nil {

      
        
        24
        +	_ = kong.Parse(&cli)

      
        
        25
        +	if err := run(cli.File); err != nil {

      
        20
        26
         		fmt.Fprintf(os.Stderr, "error: %v\n", err)

      
        21
        27
         		os.Exit(1)

      
        22
        28
         	}

      
        23
        29
         }

      
        24
        30
         

      
        25
        
        -func run() error {

      
        
        31
        +func run(fpath string) error {

      
        26
        32
         	anki := anki.NewAnkiClient()

      
        27
        33
         

      
        28
        
        -	f, err := os.ReadFile(importFile)

      
        
        34
        +	f, err := os.ReadFile(filepath.Clean(fpath))

      
        29
        35
         	if err != nil {

      
        30
        36
         		return err

      
        31
        37
         	}