Skip to content

Commit

Permalink
ingest: process tldr cheat sheets
Browse files Browse the repository at this point in the history
  • Loading branch information
joshi4 committed May 11, 2024
1 parent b9fa7a1 commit 1116998
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion ingest/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,62 @@
package main

import (
"errors"
"fmt"
"io/fs"
"log/slog"
"path/filepath"

"golang.org/x/sync/errgroup"

"github.com/getsavvyinc/savvy-cli/ingest/parser"
)

const tldrPath = "tldr/pages/"

const maxConcurrency = 500

func main() {
// Code
logger := slog.Default()
cheatsheetParser := parser.New(parser.TLDR)

var g errgroup.Group
g.SetLimit(maxConcurrency)

err := filepath.Walk(tldrPath, func(path string, info fs.FileInfo, err error) error {
logger := logger.With("path", path)
if err != nil {
logger.Error(err.Error())
return nil
}

if info.IsDir() {
logger.Info("skipping directory")
return nil
}

g.Go(func() error {
cheatSheet, err := cheatsheetParser.Parse(path)
if err != nil && !errors.Is(err, parser.ErrRequiredMdFile) {
err = fmt.Errorf("failed to parse file: %w", err)
logger.Error(err.Error(), "provider", cheatsheetParser.Provider())
return err
}
if cheatSheet == nil {
logger.Warn("cheat sheet is nil")
return fmt.Errorf("cheat sheet is nil: %s", path)
}
return nil
})

return nil
})

if err != nil {
logger.Error(err.Error())
}

if err := g.Wait(); err != nil {
logger.Error(err.Error(), "component", "errgroup")
}
}

0 comments on commit 1116998

Please sign in to comment.