feat: interactive list when running empty root command

This commit is contained in:
Yehoshua Adam Sandler
2026-02-04 12:16:28 -06:00
parent d24e4f340e
commit 42ced28ea7
3 changed files with 226 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"sort"
"github.com/spf13/cobra"
"github.com/yeho/doks/internal/config"
@@ -39,7 +40,7 @@ and manuals. Access documents by key or search through content.`,
searchDocuments(searchFlag)
return
}
cmd.Help()
showInteractiveList()
},
}
@@ -203,3 +204,33 @@ func displayFile(filePath string, highlightLine int) {
}
fmt.Print(string(content))
}
func showInteractiveList() {
reg, err := registry.Load(cfg.RegistryPath())
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading registry: %v\n", err)
os.Exit(1)
}
entries := reg.List()
if len(entries) == 0 {
fmt.Println(tui.NoResultsStyle.Render("No documents registered. Use 'doks add <file>' to add documents."))
return
}
// Sort by key
sort.Slice(entries, func(i, j int) bool {
return entries[i].Key < entries[j].Key
})
selected, err := tui.RunList(entries)
if err != nil {
fmt.Fprintf(os.Stderr, "Error running TUI: %v\n", err)
os.Exit(1)
}
if selected != nil {
filePath := cfg.FilePath(selected.Filename)
displayFile(filePath, 0)
}
}