searchcmd

package
v0.0.0-...-d08559b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SearchCmd = &cobra.Command{
	Use:   "search <query>",
	Short: "search notes, links, and tasks",
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		cfg := config.Load()
		notesSvc := notes.NewService(notes.NewStore(cfg.NotesDir))
		linksSvc := links.NewService(links.NewStore(cfg.LinksDir), cfg.FetchLimit)
		tasksSvc := tasks.NewService(tasks.NewStore(cfg.TasksDir))

		results, err := search.New(notesSvc, linksSvc, tasksSvc).Query(args[0], exact)
		if err != nil {
			slog.Error("search failed", "err", err)
			os.Exit(1)
		}

		if !isTerminal() {
			for _, r := range results {
				fmt.Printf("[%-4s]  %-14s  %s\n", r.Kind, r.ID, r.Snippet)
			}
			return
		}

		p := tea.NewProgram(newPicker(results, args[0]), tea.WithAltScreen())
		final, err := p.Run()
		if err != nil {
			slog.Error("picker failed", "err", err)
			os.Exit(1)
		}

		picked := final.(pickerModel).selected
		if picked == nil {
			return
		}

		switch picked.Kind {
		case search.KindNote:
			if err := client.EditNote(picked.ID, false); err != nil {
				slog.Error("open note failed", "err", err)
				os.Exit(1)
			}
		case search.KindLink:
			l, err := linksSvc.Get(picked.ID)
			if err != nil {
				slog.Error("fetch link failed", "err", err)
				os.Exit(1)
			}
			fmt.Println(l.URL)
		case search.KindTask:
			t, err := tasksSvc.Get(picked.ID)
			if err != nil {
				slog.Error("fetch task failed", "err", err)
				os.Exit(1)
			}
			printTask(t)
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL