search

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KeyMap = keymap{
	Enter: key.NewBinding(
		key.WithKeys("enter"),
		key.WithHelp("enter", "select"),
	),

	Back: key.NewBinding(
		key.WithKeys("esc"),
		key.WithHelp("esc", "back"),
	),
	Quit: key.NewBinding(
		key.WithKeys("ctrl+c"),
		key.WithHelp("ctrl+c", "quit"),
	),
	Space: key.NewBinding(
		key.WithKeys(" "),
		key.WithHelp("space", "toggle"),
	),
	Up: key.NewBinding(
		key.WithKeys("up", "k"),
		key.WithHelp("↑/k", "up"),
	),
	Down: key.NewBinding(
		key.WithKeys("down", "j"),
		key.WithHelp("↓/j", "down"),
	),
}

KeyMap reusable key mappings shared across models

View Source
var SearchCmd = &cobra.Command{
	Use:   "search",
	Short: "search searches for packages",
	Long: `Search for Nix packages on the Nixpkgs repository
	`,
	Example: `bsf search <package name>`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) < 1 {

			fmt.Println(errorStyle.Render(fmt.Errorf("error: %v", "package name is required").Error()))
			os.Exit(1)
		}
		var err error
		conf, err := configure.PreCheckConf()
		if err != nil {
			fmt.Println(styles.ErrorStyle.Render("error:", err.Error()))
			os.Exit(1)
		}

		if os.Getenv("BSF_DEBUG") != "" && strings.ToLower(os.Getenv("BSF_DEBUG")) == "true" {

			if f, err := tea.LogToFile("debug.log", "help"); err != nil {
				fmt.Println("Couldn't open a file for logging:", err)
				os.Exit(1)
			} else {
				defer func() {
					err = f.Close()
					if err != nil {
						log.Fatal(err)
					}
				}()
			}
		}

		sc, err = search.NewClientWithAddr(conf.BuildSafeAPI, conf.BuildSafeAPITLS)
		if err != nil {
			fmt.Println(errorStyle.Render(fmt.Errorf("error: %v", err).Error()))
			os.Exit(1)
		}

		packages, err := sc.ListPackages(cmd.Context(), &buildsafev1.ListPackagesRequest{

			PageSize:   999,
			PageToken:  1,
			SearchTerm: args[0],
		})
		if err != nil {
			fmt.Println(errorStyle.Render(fmt.Errorf("error: %v", err).Error()))
			os.Exit(1)
		}
		items := convLPR2Items(packages)
		m := InitSearch(items)
		if _, err := tea.NewProgram(m, tea.WithAltScreen()).Run(); err != nil {
			fmt.Println(errorStyle.Render(fmt.Errorf("error: %v", err).Error()))
			os.Exit(1)
		}

	},
}

SearchCmd represents the init command

Functions

func InitSearch

func InitSearch(items []list.Item) tea.Model

InitSearch initialize the search model for your program

Types

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model the search model definition

func (Model) Init

func (m Model) Init() tea.Cmd

Init run any intial IO on program start

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handle IO and commands

func (Model) View

func (m Model) View() string

View return the text UI to be output to the terminal

Jump to

Keyboard shortcuts

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