items

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CategoriesCmd = &cobra.Command{
	Use:     "categories",
	Aliases: []string{"c"},
	Short:   "List all cached category names.",
	Long:    `Displays the list of all category names currently available in the cache.`,
	Example: `geol list categories
geol l c`,
	Run: func(cmd *cobra.Command, args []string) {

		utilities.AnalyzeCacheProductsValidity(cmd)
		categoriesPath, err := utilities.GetCategoriesPath()
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving categories path")
			os.Exit(1)
		}

		categories, err := utilities.GetCategoriesWithCacheRefresh(cmd, categoriesPath)
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving categories from cache")
			os.Exit(1)
		}

		var names []string
		for name := range categories {
			names = append(names, name)
		}
		sort.Strings(names)

		plusStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("2")).Render("+")
		for _, name := range names {
			if _, err := lipgloss.Printf("%s %s\n", plusStyle, boldStyle.Render(name)); err != nil {
				log.Error().Err(err).Msg("Error writing category name to stdout")
				os.Exit(1)
			}
		}

		nbCategories := strconv.Itoa(len(names))
		nbCategoriesStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("2"))
		if _, err := lipgloss.Printf("\n%s categories listed\n", nbCategoriesStyle.Render(nbCategories)); err != nil {
			log.Error().Err(err).Msg("Error writing category count to stdout")
			os.Exit(1)
		}
	},
}

CategoriesCmd represents the categories command

View Source
var ProductsCmd = &cobra.Command{
	Use:     "products",
	Aliases: []string{"p"},
	Short:   "List all cached product names.",
	Long:    `Displays the list of all product names currently available on https://endoflife.date.`,
	Example: `geol list products
geol list products --tree
geol l p -t`,
	Run: func(cmd *cobra.Command, args []string) {

		utilities.AnalyzeCacheProductsValidity(cmd)
		productsPath, err := utilities.GetProductsPath()
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving products path")
			os.Exit(1)
		}

		products, err := utilities.GetProductsWithCacheRefresh(cmd, productsPath)
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving products from cache")
			os.Exit(1)
		}

		treeFlag, _ := cmd.Flags().GetBool("tree")

		var names []string
		for name := range products.Products {
			names = append(names, name)
		}
		sort.Strings(names)

		if treeFlag {

			productTree := tree.Root(".")

			for _, name := range names {
				aliases := products.Products[name]
				if len(aliases) > 0 {
					aliases = aliases[1:]
				}
				sort.Strings(aliases)
				t := tree.New().Root(boldStyle.Render(name))
				for _, item := range aliases {
					t.Child(item)
				}
				productTree.Child(t)
			}
			if _, err := fmt.Fprintln(os.Stdout, productTree.String()); err != nil {
				log.Error().Err(err).Msg("Error writing product tree to stdout")
				os.Exit(1)
			}
		} else {

			plusStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("2")).Render("+")
			for _, name := range names {
				if _, err := lipgloss.Printf("%s %s\n", plusStyle, boldStyle.Render(name)); err != nil {
					log.Error().Err(err).Msg("Error writing product name to stdout")
					os.Exit(1)
				}
			}
		}

		nbProducts := strconv.Itoa(len(names))
		nbProductsStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("2"))
		if _, err := lipgloss.Printf("\n%s products listed\n", nbProductsStyle.Render(nbProducts)); err != nil {
			log.Error().Err(err).Msg("Error writing product count to stdout")
			os.Exit(1)
		}
	},
}

ProductsCmd represents the products command

View Source
var TagsCmd = &cobra.Command{
	Use:     "tags",
	Aliases: []string{"t"},
	Short:   "List all cached tag names.",
	Long:    `Displays the list of all tag names currently available in the cache.`,
	Example: `geol list tags
geol l t`,
	Run: func(cmd *cobra.Command, args []string) {

		utilities.AnalyzeCacheProductsValidity(cmd)
		tagsPath, err := utilities.GetTagsPath()
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving tags path")
			os.Exit(1)
		}

		tags, err := utilities.GetTagsWithCacheRefresh(cmd, tagsPath)
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving tags from cache")
			os.Exit(1)
		}

		var names []string
		for name := range tags {
			names = append(names, name)
		}
		sort.Strings(names)

		plusStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("2")).Render("+")
		for _, name := range names {
			if _, err := lipgloss.Printf("%s %s\n", plusStyle, boldStyle.Render(name)); err != nil {
				log.Error().Err(err).Msg("Error writing tag name to stdout")
				os.Exit(1)
			}
		}

		nbTags := strconv.Itoa(len(names))
		nbTagsStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("2"))
		if _, err := lipgloss.Printf("\n%s tags listed\n", nbTagsStyle.Render(nbTags)); err != nil {
			log.Error().Err(err).Msg("Error writing tag count to stdout")
			os.Exit(1)
		}
	},
}

TagsCmd represents the tags command

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