1d87d93172
- Implement global CLI config at ~/.config/jade/config.yml - Add jade depo commands (add, list, remove, set-default) - Support depository short names and context-aware detection - Remove tag_prefix config, hardcode + syntax for consistency - Update depository resolution: flag -> context -> default - Auto-initialize .jade/ directory structure when adding depos - Update documentation with new multi-depository workflow
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"git.jnss.me/joakim/jadedepo/internal/engine"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
searchCmd = &cobra.Command{
|
|
Use: "search [query]",
|
|
Short: "Search notes by content or tags",
|
|
Run: searchNotes,
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(searchCmd)
|
|
}
|
|
|
|
func searchNotes(cmd *cobra.Command, args []string) {
|
|
jd, err := engine.GetInstance()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
var results []string
|
|
|
|
if len(args) == 0 {
|
|
fmt.Fprintf(os.Stderr, "Error: query required when not searching by tag\n")
|
|
os.Exit(1)
|
|
}
|
|
query := strings.Join(args, " ")
|
|
results, err = jd.SearchContent(query)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error searching: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if len(results) == 0 {
|
|
fmt.Println("No matches found")
|
|
return
|
|
}
|
|
|
|
fmt.Printf("Found %d match(es):\n\n", len(results))
|
|
for _, path := range results {
|
|
// Load note to get title
|
|
note, err := engine.LoadNote(jd.Config.DepoPath, path)
|
|
if err != nil {
|
|
fmt.Printf(" %s\n", path)
|
|
continue
|
|
}
|
|
fmt.Printf(" %s (%s)\n", note.Title, path)
|
|
}
|
|
}
|