local

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: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClearCmd = &cobra.Command{
	Use:     "clear",
	Aliases: []string{"c"},
	Short:   "Delete the locally cached products file.",
	Long: `Removes the local products cache file from the user's config directory.

This command is useful for clearing the cached list of products and their aliases previously downloaded from the endoflife.date API. The cache file is stored in the config directory under geol/products.json. If the file does not exist, a message is displayed.`,
	Run: func(cmd *cobra.Command, args []string) {
		productsPath, err := utilities.GetProductsPath()
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving products path")
			os.Exit(1)
		}
		if err := utilities.RemoveFileIfExists(productsPath); err != nil {
			log.Error().Err(err).Msg("Error deleting cache file")
			os.Exit(1)
		}
		log.Info().Str("path", productsPath).Msg("Cache file removed.")

		tagsPath, err := utilities.GetTagsPath()
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving tags path")
			os.Exit(1)
		}
		if err := utilities.RemoveFileIfExists(tagsPath); err != nil {
			log.Error().Err(err).Msg("Error deleting tags file")
			os.Exit(1)
		}
		log.Info().Str("path", tagsPath).Msg("Tags file removed.")

		categoriesPath, err := utilities.GetCategoriesPath()
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving categories path")
			os.Exit(1)
		}
		if err := utilities.RemoveFileIfExists(categoriesPath); err != nil {
			log.Error().Err(err).Msg("Error deleting categories file")
			os.Exit(1)
		}
		log.Info().Str("path", categoriesPath).Msg("Categories file removed.")
	},
}

ClearCmd represents the clear command

View Source
var RefreshCmd = &cobra.Command{
	Use:     "refresh",
	Aliases: []string{"r"},
	Short:   "Download the latest list of products and their aliases from the endoflife.date API and save it locally.",
	Long: `Fetches the current list of products and their aliases from the endoflife.date API, processes the data into a local JSON file under the user's config directory, and ensures the file is updated with the latest information.

This command is useful for keeping the local product list in sync with the upstream source for further use by the application. The resulting file is stored in the config directory under geol/products.json.`,
	Run: func(cmd *cobra.Command, args []string) {
		utilities.RefreshAllCaches(cmd)
	},
}

RefreshCmd represents the refresh command

View Source
var StatusCmd = &cobra.Command{
	Use:     "status",
	Aliases: []string{"s"},
	Short:   "Show information about the local products cache file.",
	Long: `Displays the status of the local products cache file stored in the user's config directory.

This command prints the last update date and the number of products currently cached in geol/products.json. It helps verify if the cache is present and up to date.`,
	Run: func(cmd *cobra.Command, args []string) {
		productsPath, err := utilities.GetProductsPath()
		if err == nil {
			if info, err2 := utilities.EnsureCacheExistsGeneric(productsPath, cmd); err2 == nil {
				modTime := info.ModTime()
				log.Info().Msg("Cache last updated " + modTime.Format("2006-01-02 15:04:05"))
			}
		}
		utilities.AnalyzeCacheProductsValidity(cmd)
		errorOccurred := false

		products, err := utilities.GetProductsWithCacheRefresh(cmd, productsPath)
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving products from cache")
			errorOccurred = true
		}
		log.Info().Int("Number of products", len(products.Products)).Msg("")

		tagsPath, err := utilities.GetTagsPath()
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving tags path")
			errorOccurred = true
		}

		tags, err := utilities.GetTagsWithCacheRefresh(cmd, tagsPath)
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving tags from cache")
			errorOccurred = true
		}
		log.Info().Int("Number of tags", len(tags)).Msg("")

		categoriesPath, err := utilities.GetCategoriesPath()
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving categories path")
			errorOccurred = true
		}

		categories, err := utilities.GetCategoriesWithCacheRefresh(cmd, categoriesPath)
		if err != nil {
			log.Error().Err(err).Msg("Error retrieving categories from cache")
			errorOccurred = true
		}
		log.Info().Int("Number of categories", len(categories)).Msg("")

		if errorOccurred {
			os.Exit(1)
		}
	},
}

StatusCmd represents the status 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