feat: interactive list when running empty root command
This commit is contained in:
33
cmd/root.go
33
cmd/root.go
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user