From 4501b09bdc8f09dab657c1b4615ab1bdee5cb316 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Mon, 2 Sep 2024 09:46:51 -0600 Subject: [PATCH] feat: automatic support for distillery pre-releases, better logging --- pkg/checksum/compare_test.go | 4 ++-- pkg/commands/install/install.go | 13 ++++++++----- pkg/common/global.go | 3 +++ pkg/source/github.go | 2 ++ pkg/source/source.go | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/checksum/compare_test.go b/pkg/checksum/compare_test.go index 3e25d25..36adb55 100644 --- a/pkg/checksum/compare_test.go +++ b/pkg/checksum/compare_test.go @@ -54,7 +54,7 @@ func TestCompareHashWithChecksumFile(t *testing.T) { defer os.Remove(checksumFile.Name()) // Write the hash and filename to the checksum file - _, err = checksumFile.WriteString(fmt.Sprintf("%s %s\n", hash, tmpFile.Name())) + _, err = fmt.Fprintf(checksumFile, "%s %s\n", hash, tmpFile.Name()) assert.NoError(t, err) checksumFile.Close() @@ -69,7 +69,7 @@ func TestCompareHashWithChecksumFile(t *testing.T) { assert.NoError(t, err) defer os.Remove(checksumFile.Name()) - _, err = checksumFile.WriteString(fmt.Sprintf("%s %s\n", hash, tmpFile.Name())) + _, err = fmt.Fprintf(checksumFile, "%s %s\n", hash, tmpFile.Name()) assert.NoError(t, err) checksumFile.Close() diff --git a/pkg/commands/install/install.go b/pkg/commands/install/install.go index 228ba68..a6bf167 100644 --- a/pkg/commands/install/install.go +++ b/pkg/commands/install/install.go @@ -8,8 +8,6 @@ import ( "strings" "github.com/apex/log" - clilog "github.com/apex/log/handlers/cli" - "github.com/urfave/cli/v2" "github.com/ekristen/distillery/pkg/common" @@ -17,9 +15,6 @@ import ( ) func Execute(c *cli.Context) error { - log.SetHandler(clilog.Default) - log.SetLevel(log.DebugLevel) - homeDir, err := os.UserHomeDir() if err != nil { return err @@ -38,6 +33,10 @@ func Execute(c *cli.Context) error { _ = os.MkdirAll(metadataDir, 0755) _ = os.MkdirAll(downloadsDir, 0755) + if c.Args().First() == "ekristen/distillery" { + _ = c.Set("include-pre-releases", "true") + } + src, err := source.New(c.Args().First(), &source.Options{ OS: c.String("os"), Arch: c.String("arch"), @@ -66,6 +65,10 @@ func Execute(c *cli.Context) error { log.Infof(" os: %s", c.String("os")) log.Infof(" arch: %s", c.String("arch")) + if c.Bool("include-pre-releases") { + log.Infof("including pre-releases") + } + if err := src.Run(c.Context, c.String("version"), c.String("github-token")); err != nil { return err } diff --git a/pkg/common/global.go b/pkg/common/global.go index 3592ee8..60be195 100644 --- a/pkg/common/global.go +++ b/pkg/common/global.go @@ -6,6 +6,7 @@ import ( "runtime" "github.com/apex/log" + clilog "github.com/apex/log/handlers/cli" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) @@ -41,6 +42,8 @@ func Flags() []cli.Flag { } func Before(c *cli.Context) error { + log.SetHandler(clilog.Default) + formatter := &logrus.TextFormatter{ DisableColors: c.Bool("log-disable-color"), FullTimestamp: c.Bool("log-full-timestamp"), diff --git a/pkg/source/github.go b/pkg/source/github.go index b4e0001..04c10f8 100644 --- a/pkg/source/github.go +++ b/pkg/source/github.go @@ -137,6 +137,8 @@ func (s *GitHub) FindRelease(ctx context.Context) error { return fmt.Errorf("release not found") } + log.Infof("installing version: %s", release.GetTagName()) + s.Release = release return nil diff --git a/pkg/source/source.go b/pkg/source/source.go index 674eef4..4a47fbd 100644 --- a/pkg/source/source.go +++ b/pkg/source/source.go @@ -66,7 +66,7 @@ func (s *Source) GetArch() string { } func (s *Source) Download(ctx context.Context) error { - logrus.Info("download called") + log.Info("downloading assets") if s.Binary != nil { if err := s.Binary.Download(ctx); err != nil { return err