From 45b7cb84bdf1ecb1fcc66dd82e8a112d5d9dc690 Mon Sep 17 00:00:00 2001 From: Yakiyo Date: Wed, 23 Aug 2023 08:54:05 +0000 Subject: [PATCH] feat: list sub --- cache/list.go | 39 ++++++++++++++++++++++++++++++++++++--- cmd/root.go | 4 ++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/cache/list.go b/cache/list.go index da8729b..5460e6c 100644 --- a/cache/list.go +++ b/cache/list.go @@ -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) + } } diff --git a/cmd/root.go b/cmd/root.go index 3fd3cc3..0721fda 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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)