product

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ProductCmd = &cobra.Command{
	Use:     "product",
	Aliases: []string{"p"},
	Short:   "Display the latest version of product(s) and the end of life date.",
	Long:    "Show the latest version, release date, and end-of-life information for one or more products. Use the `extended` subcommand for more detailed output.",
	Example: `geol product linux ubuntu
geol product extended golang k8s
geol product describe nodejs`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			log.Error().Msg("Please specify at least one product.")
			os.Exit(1)
		}

		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)
		}

		var results []productResult

		for _, prod := range args {
			found := false
			for name, aliases := range products.Products {
				if strings.EqualFold(prod, name) {
					found = true
					prod = name
					break
				}
				for _, alias := range aliases {
					if strings.EqualFold(prod, alias) {
						found = true
						prod = name
						break
					}
				}
				if found {
					break
				}
			}
			if !found {
				log.Error().Msgf("Product %s not found in the API.", prod)
				continue
			}

			url := utilities.ApiUrl + "products/" + prod
			resp, err := http.Get(url)
			if err != nil {
				log.Error().Err(err).Msgf("Error requesting %s", prod)
				os.Exit(1)
			}
			body, err := io.ReadAll(resp.Body)
			if cerr := resp.Body.Close(); cerr != nil {
				log.Error().Err(cerr).Msgf("Error closing HTTP body for %s", prod)
				os.Exit(1)
			}
			if err != nil {
				log.Error().Err(err).Msgf("Error reading response for %s", prod)
				os.Exit(1)
			}
			if resp.StatusCode != 200 {
				log.Warn().Msgf("Product %s not found on the API.", prod)
				os.Exit(1)
			}

			// JSON decoding
			var apiResp struct {
				Result struct {
					Name   string `json:"name"`
					Labels struct {
						Eol string `json:"eol"`
					} `json:"labels"`
					Releases []struct {
						Name        string `json:"name"`
						ReleaseDate string `json:"releaseDate"`
						EolFrom     string `json:"eolFrom"`
					} `json:"releases"`
				} `json:"result"`
			}
			if err := json.Unmarshal(body, &apiResp); err != nil {
				log.Error().Err(err).Msgf("Error decoding JSON for %s", prod)
				os.Exit(1)
			}
			var relName, relDate, relEol string
			if len(apiResp.Result.Releases) > 0 {
				relName = apiResp.Result.Releases[0].Name
				relDate = apiResp.Result.Releases[0].ReleaseDate
				relEol = apiResp.Result.Releases[0].EolFrom
			}
			results = append(results, productResult{
				Name: apiResp.Result.Name,

				ReleaseName: relName,
				ReleaseDate: relDate,
				EolFrom:     relEol,
			})
		}

		if len(results) == 0 {
			log.Error().Msg("None of the products were found in the API.")
			os.Exit(1)
		}
		var buf bytes.Buffer

		buf.WriteString("| **Name** | **Latest Cycle** | **Release Date** | **EOL From** |\n")
		buf.WriteString("|------|--------------|--------------|----------|\n")
		for _, r := range results {
			name := strings.ReplaceAll(r.Name, "|", "\\|")
			relName := strings.ReplaceAll(r.ReleaseName, "|", "\\|")
			relDate := strings.ReplaceAll(r.ReleaseDate, "|", "\\|")
			relEol := strings.ReplaceAll(r.EolFrom, "|", "\\|")
			buf.WriteString(fmt.Sprintf("| %s | %s | %s | %s |\n", name, relName, relDate, relEol))
		}

		out, err := glamour.RenderWithEnvironmentConfig(buf.String())
		if err != nil {
			fmt.Print(buf.String())
		} else {

			_, _ = lipgloss.Print(out)
		}
	},
}

ProductCmd represents the product command

Functions

This section is empty.

Types

type ApiRespExtended added in v1.3.0

type ApiRespExtended struct {
	Result struct {
		Name     string `json:"name"`
		Releases []struct {
			Name        string `json:"name"`
			ReleaseDate string `json:"releaseDate"`
			Latest      struct {
				Name string `json:"name"`
				Date string `json:"date"`
			} `json:"latest"`
			EoasFrom string `json:"eoasFrom"`
			EolFrom  string `json:"eolFrom"`
			IsLTS    bool   `json:"isLTS"`
		} `json:"releases"`
	}
}

type ApiRestDescribe added in v1.5.0

type ApiRestDescribe struct {
	Result struct {
		Name           string `json:"name"`
		VersionCommand string `json:"versionCommand"`
		Identifiers    []struct {
			Type string `json:"type"`
			Id   string `json:"id"`
		} `json:"identifiers"`
	}
}

type ReleaseInfo added in v1.2.0

type ReleaseInfo struct {
	Name        string
	ReleaseDate string
	LatestName  string
	LatestDate  string
	EoasFrom    string
	EolFrom     string
	LTS         bool
}

Jump to

Keyboard shortcuts

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