// Copyright © 2019 Ettore Di Giacinto // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, see . package cmd import ( "fmt" "os" "strings" "github.com/ghodss/yaml" "github.com/jedib0t/go-pretty/table" "github.com/jedib0t/go-pretty/v6/list" . "github.com/mudler/luet/pkg/config" installer "github.com/mudler/luet/pkg/installer" . "github.com/mudler/luet/pkg/logger" pkg "github.com/mudler/luet/pkg/package" "github.com/spf13/cobra" ) type PackageResult struct { Name string `json:"name"` Category string `json:"category"` Version string `json:"version"` Repository string `json:"repository"` Target string `json:"target"` Hidden bool `json:"hidden"` } type Results struct { Packages []PackageResult `json:"packages"` } func (r PackageResult) String() string { return fmt.Sprintf("%s/%s-%s required for %s", r.Category, r.Name, r.Version, r.Target) } var rows table.Row = table.Row{"Package", "Category", "Name", "Version", "Repository", "Description", "License", "URI"} func packageToRow(repo string, p pkg.Package) table.Row { return table.Row{p.HumanReadableString(), p.GetCategory(), p.GetName(), p.GetVersion(), repo, p.GetDescription(), p.GetLicense(), strings.Join(p.GetURI(), "\n")} } func packageToList(l list.Writer, repo string, p pkg.Package) { l.AppendItem(p.HumanReadableString()) l.Indent() l.AppendItem(fmt.Sprintf("Category: %s", p.GetCategory())) l.AppendItem(fmt.Sprintf("Name: %s", p.GetName())) l.AppendItem(fmt.Sprintf("Version: %s", p.GetVersion())) l.AppendItem(fmt.Sprintf("Description: %s", p.GetDescription())) l.AppendItem(fmt.Sprintf("Repository: %s ", repo)) l.AppendItem(fmt.Sprintf("Uri: %s ", strings.Join(p.GetURI(), "\n"))) l.UnIndent() } var searchCmd = &cobra.Command{ Use: "search ", Short: "Search packages", Long: `Search for installed and available packages To search a package in the repositories: $ luet search To search a package and display results in a table (wide screens): $ luet search --table To look into the installed packages: $ luet search --installed Note: the regex argument is optional, if omitted implies "all" To search a package by label: $ luet search --by-label