Skip to content

Commit

Permalink
feat: list sub
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakiyo committed Aug 23, 2023
1 parent 627530d commit 45b7cb8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
39 changes: 36 additions & 3 deletions cache/list.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
package cache

import _ "github.com/json-iterator/go"
import (
"fmt"
"io/fs"
"path/filepath"
"strings"

func List() []string {
// "io/fs"
// "path/filepath"

return []string{}
"github.com/Yakiyo/tilde/utils"
"github.com/Yakiyo/tilde/where"
"github.com/charmbracelet/log"
)

func List() {
if !utils.FsExists(where.Cache()) {
log.Fatal("Page cache not found. Please download the cache by using the `--update/-u` flag\n\n" +
"You can optionally enable auto cache downloading by adding `auto_update = true` in your config file\n" +
"Path to config file: " + where.Config())
}
cache := filepath.Join(where.Cache(), "pages")
m := map[string]bool{}
dirs := []string{
filepath.Join(cache, utils.Platform()),
filepath.Join(cache, "common"),
}
fmt.Println(dirs)
for _, dir := range dirs {
filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
if !d.IsDir() {
m[strings.TrimSuffix(d.Name(), ".md")] = true
}
return nil
})
}
for k := range m {
fmt.Println(k)
}
}
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ View community driven and simplified man pages in your terminal`,
fmt.Println("Successfully downloaded local cache")
}

if list := utils.Must(cmd.Flags().GetBool("list")); list {
cache.List()
}

if seed := utils.Must(cmd.Flags().GetBool("seed-config")); seed {
if err := viper.SafeWriteConfig(); err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 45b7cb8

Please sign in to comment.