From 950cee6df08ba3df8a4e552b1eaff203aaf2e6c7 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Wed, 17 May 2023 12:33:44 +0000 Subject: [PATCH] feat: add --dump to dump cache --- distro.go | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/distro.go b/distro.go index 5f24a21..f2bcec2 100644 --- a/distro.go +++ b/distro.go @@ -2,12 +2,14 @@ package main import ( "context" + "fmt" "os" "path/filepath" "regexp" "time" "github.com/cavaliergopher/grab/v3" + "github.com/davecgh/go-spew/spew" "github.com/remeh/sizedwaitgroup" "github.com/rs/zerolog/log" @@ -25,14 +27,17 @@ type DistroCmd struct { type DebianCmd struct { Cache DebianCacheCmd `cmd:"" help:"populate cache"` Fetch DebianFetchCmd `cmd:"" help:"download deb packages"` + + Regex string `help:"match deb pkg names by regex" default:".*"` } type DebianCacheCmd struct { Path string `help:"path to cache"` Refetch int `help:"days before refetch versions without deb package" default:"7"` + Dump bool `help:"dump cache"` } -func (cmd *DebianCacheCmd) Run() (err error) { +func (cmd *DebianCacheCmd) Run(dcmd *DebianCmd) (err error) { if cmd.Path != "" { debian.CachePath = cmd.Path } @@ -40,21 +45,33 @@ func (cmd *DebianCacheCmd) Run() (err error) { log.Info().Msg("Fetching kernels...") - _, err = debian.GetKernels() + kernels, err := debian.GetKernels() if err != nil { log.Error().Err(err).Msg("") return } + if cmd.Dump { + re, err := regexp.Compile(dcmd.Regex) + if err != nil { + log.Fatal().Err(err).Msg("regex") + } + + for _, kernel := range kernels { + if !re.MatchString(kernel.Image.Deb.Name) { + continue + } + fmt.Println(spew.Sdump(kernel)) + } + } + log.Info().Msg("Success") return } type DebianFetchCmd struct { - Path string `help:"path to download directory" type:"existingdir" default:"./"` - Regexp string `help:"match deb pkg names by regexp" default:".*"` - - IgnoreMirror bool `help:"ignore check if packages on the mirror"` + Path string `help:"path to download directory" type:"existingdir" default:"./"` + IgnoreMirror bool `help:"ignore check if packages on the mirror"` Max int `help:"do not download more than X" default:"100500"` @@ -124,12 +141,15 @@ func (cmd *DebianFetchCmd) fetch(pkg snapshot.Package) { cmd.Max-- } -func (cmd *DebianFetchCmd) Run() (err error) { - re, err := regexp.Compile(cmd.Regexp) +func (cmd *DebianFetchCmd) Run(dcmd *DebianCmd) (err error) { + re, err := regexp.Compile(dcmd.Regex) if err != nil { - log.Fatal().Err(err).Msg("regexp") + log.Fatal().Err(err).Msg("regex") } + log.Info().Msg("will not download packages that exist on the mirror") + log.Info().Msg("use --ignore-mirror if you really need it") + kernels, err := debian.GetKernels() if err != nil { log.Error().Err(err).Msg("")