Skip to content

Commit

Permalink
chore: remove progress bar and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tulilirockz committed Dec 21, 2024
1 parent e4b2d78 commit 68ca8d6
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 296 deletions.
17 changes: 0 additions & 17 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import (
"path"
"path/filepath"

"github.com/jedib0t/go-pretty/v6/text"
"github.com/spf13/cobra"
appLogging "github.com/ublue-os/uupd/pkg/logging"
"golang.org/x/term"
)

func assertRoot(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -118,19 +116,4 @@ func init() {
rootCmd.PersistentFlags().StringVar(&fLogFile, "log-file", "-", "File where user-facing logs will be written to")
rootCmd.PersistentFlags().StringVar(&fLogLevel, "log-level", "info", "Log level for user-facing logs")
rootCmd.PersistentFlags().BoolVar(&fNoLogging, "quiet", false, "Make logs quiet")

interactiveProgress := true
if fLogFile != "-" {
interactiveProgress = false
}
isTerminal := term.IsTerminal(int(os.Stdout.Fd()))
if !isTerminal {
interactiveProgress = false
}
if !text.ANSICodesSupported {
interactiveProgress = false
text.DisableColors()
}

rootCmd.Flags().BoolP("no-progress", "p", !interactiveProgress, "Do not show progress bars")
}
40 changes: 9 additions & 31 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log/slog"
"os"

"github.com/jedib0t/go-pretty/v6/progress"
"github.com/spf13/cobra"
"github.com/ublue-os/uupd/checks"
"github.com/ublue-os/uupd/drv/brew"
Expand Down Expand Up @@ -98,34 +97,15 @@ func Update(cmd *cobra.Command, args []string) {
if mainSystemDriverConfig.Enabled {
totalSteps += mainSystemDriver.Steps()
}
pw := percent.NewProgressWriter()
pw.SetNumTrackersExpected(1)
pw.SetAutoStop(false)

progressEnabled, err := cmd.Flags().GetBool("no-progress")
if err != nil {
slog.Error("Failed to get no-progress flag", "error", err)
return
}
// Move this to its actual boolean value (~no-progress)
progressEnabled = !progressEnabled

if progressEnabled {
go pw.Render()
percent.ResetOscProgress()
}
// FIXME: check if is interactive
percent.ResetOscProgress()

// -1 because 0 index
tracker := percent.NewIncrementTracker(&progress.Tracker{Message: "Updating", Units: progress.UnitsDefault, Total: int64(totalSteps - 1)}, totalSteps-1)
pw.AppendTracker(tracker.Tracker)
tracker := &percent.Incrementer{MaxIncrements: totalSteps - 1}

var trackerConfig = &drv.TrackerConfiguration{
Tracker: tracker,
Writer: &pw,
Progress: progressEnabled,
}
flatpakUpdater.Tracker = trackerConfig
distroboxUpdater.Tracker = trackerConfig
flatpakUpdater.Tracker = tracker
distroboxUpdater.Tracker = tracker

var outputs = []drv.CommandOutput{}

Expand All @@ -149,7 +129,7 @@ func Update(cmd *cobra.Command, args []string) {

if mainSystemDriverConfig.Enabled {
slog.Debug(fmt.Sprintf("%s module", mainSystemDriverConfig.Title), slog.String("module_name", mainSystemDriverConfig.Title), slog.Any("module_configuration", mainSystemDriverConfig))
percent.ChangeTrackerMessageFancy(pw, tracker, progressEnabled, percent.TrackerMessage{Title: mainSystemDriverConfig.Title, Description: mainSystemDriverConfig.Description})
percent.ReportStatusChange(tracker, percent.TrackerMessage{Title: mainSystemDriverConfig.Title, Description: mainSystemDriverConfig.Description})
var out *[]drv.CommandOutput
out, err = mainSystemDriver.Update()
outputs = append(outputs, *out...)
Expand All @@ -158,7 +138,7 @@ func Update(cmd *cobra.Command, args []string) {

if brewUpdater.Config.Enabled {
slog.Debug(fmt.Sprintf("%s module", brewUpdater.Config.Title), slog.String("module_name", brewUpdater.Config.Title), slog.Any("module_configuration", brewUpdater.Config))
percent.ChangeTrackerMessageFancy(pw, tracker, progressEnabled, percent.TrackerMessage{Title: brewUpdater.Config.Title, Description: brewUpdater.Config.Description})
percent.ReportStatusChange(tracker, percent.TrackerMessage{Title: brewUpdater.Config.Title, Description: brewUpdater.Config.Description})
var out *[]drv.CommandOutput
out, err = brewUpdater.Update()
outputs = append(outputs, *out...)
Expand All @@ -181,10 +161,8 @@ func Update(cmd *cobra.Command, args []string) {
tracker.IncrementSection(err)
}

if progressEnabled {
pw.Stop()
percent.ResetOscProgress()
}
// FIXME: detect interactive session
percent.ResetOscProgress()
if verboseRun {
slog.Info("Verbose run requested")

Expand Down
6 changes: 3 additions & 3 deletions drv/brew/brew.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ func (up BrewUpdater) New(config UpdaterInitConfiguration) (BrewUpdater, error)
up.Config.Logger = config.Logger.With(slog.String("module", strings.ToLower(up.Config.Title)))

up.BrewPrefix = EnvOrFallback(up.Config.Environment, "HOMEBREW_PREFIX", "/home/linuxbrew/.linuxbrew")
up.BrewPrefix = EnvOrFallback(up.Config.Environment, "HOMEBREW_REPOSITORY", fmt.Sprintf("%s/Homebrew", up.BrewPrefix))
up.BrewPrefix = EnvOrFallback(up.Config.Environment, "HOMEBREW_CELLAR", fmt.Sprintf("%s/Cellar", up.BrewPrefix))
up.BrewPrefix = EnvOrFallback(up.Config.Environment, "HOMEBREW_PATH", fmt.Sprintf("%s/bin/brew", up.BrewPrefix))
up.BrewRepo = EnvOrFallback(up.Config.Environment, "HOMEBREW_REPOSITORY", fmt.Sprintf("%s/Homebrew", up.BrewPrefix))
up.BrewCellar = EnvOrFallback(up.Config.Environment, "HOMEBREW_CELLAR", fmt.Sprintf("%s/Cellar", up.BrewPrefix))
up.BrewPath = EnvOrFallback(up.Config.Environment, "HOMEBREW_PATH", fmt.Sprintf("%s/bin/brew", up.BrewPrefix))

if up.Config.DryRun {
return up, nil
Expand Down
16 changes: 8 additions & 8 deletions drv/distrobox/distrobox.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

type DistroboxUpdater struct {
Config DriverConfiguration
Tracker *TrackerConfiguration
Tracker *percent.Incrementer
binaryPath string
users []session.User
usersEnabled bool
Expand Down Expand Up @@ -61,18 +61,18 @@ func (up DistroboxUpdater) Update() (*[]CommandOutput, error) {
var finalOutput = []CommandOutput{}

if up.Config.DryRun {
percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description})
up.Tracker.Tracker.IncrementSection(nil)
percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description})
up.Tracker.IncrementSection(nil)

var err error = nil
for _, user := range up.users {
up.Tracker.Tracker.IncrementSection(err)
percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name})
up.Tracker.IncrementSection(err)
percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name})
}
return &finalOutput, nil
}

percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description})
percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description})
cli := []string{up.binaryPath, "upgrade", "-a"}
out, err := session.RunUID(up.Config.Logger, slog.LevelDebug, 0, cli, nil)
tmpout := CommandOutput{}.New(out, err)
Expand All @@ -83,9 +83,9 @@ func (up DistroboxUpdater) Update() (*[]CommandOutput, error) {

err = nil
for _, user := range up.users {
up.Tracker.Tracker.IncrementSection(err)
up.Tracker.IncrementSection(err)
context := *up.Config.UserDescription + " " + user.Name
percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name})
percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name})
cli := []string{up.binaryPath, "upgrade", "-a"}
out, err := session.RunUID(up.Config.Logger, slog.LevelDebug, user.UID, cli, nil)
tmpout = CommandOutput{}.New(out, err)
Expand Down
16 changes: 8 additions & 8 deletions drv/flatpak/flatpak.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type FlatpakUpdater struct {
Config DriverConfiguration
Tracker *TrackerConfiguration
Tracker *percent.Incrementer
binaryPath string
users []session.User
usersEnabled bool
Expand Down Expand Up @@ -62,18 +62,18 @@ func (up FlatpakUpdater) Update() (*[]CommandOutput, error) {
var finalOutput = []CommandOutput{}

if up.Config.DryRun {
percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description})
up.Tracker.Tracker.IncrementSection(nil)
percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description})
up.Tracker.IncrementSection(nil)

var err error = nil
for _, user := range up.users {
up.Tracker.Tracker.IncrementSection(err)
percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name})
up.Tracker.IncrementSection(err)
percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name})
}
return &finalOutput, nil
}

percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description})
percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description})
cli := []string{up.binaryPath, "update", "-y", "--noninteractive"}
flatpakCmd := exec.Command(cli[0], cli[1:]...)
out, err := session.RunLog(up.Config.Logger, slog.LevelDebug, flatpakCmd)
Expand All @@ -85,9 +85,9 @@ func (up FlatpakUpdater) Update() (*[]CommandOutput, error) {

err = nil
for _, user := range up.users {
up.Tracker.Tracker.IncrementSection(err)
up.Tracker.IncrementSection(err)
context := *up.Config.UserDescription + " " + user.Name
percent.ChangeTrackerMessageFancy(*up.Tracker.Writer, up.Tracker.Tracker, up.Tracker.Progress, percent.TrackerMessage{Title: up.Config.Title, Description: context})
percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: context})
cli := []string{up.binaryPath, "update", "-y"}
out, err := session.RunUID(up.Config.Logger, slog.LevelDebug, user.UID, cli, nil)
tmpout = CommandOutput{}.New(out, err)
Expand Down
8 changes: 0 additions & 8 deletions drv/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"os"
"strings"

"github.com/jedib0t/go-pretty/v6/progress"
"github.com/ublue-os/uupd/pkg/percent"
"github.com/ublue-os/uupd/pkg/session"
)

Expand Down Expand Up @@ -74,12 +72,6 @@ type DriverConfiguration struct {
UserDescription *string
}

type TrackerConfiguration struct {
Tracker *percent.IncrementTracker
Writer *progress.Writer
Progress bool
}

type UpdateDriver interface {
Steps() int
Check() (bool, error)
Expand Down
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ go 1.22.9

require (
github.com/godbus/dbus/v5 v5.1.0
github.com/jedib0t/go-pretty/v6 v6.6.3
github.com/shirou/gopsutil/v4 v4.24.10
github.com/spf13/cobra v1.8.1
golang.org/x/term v0.26.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -16,9 +14,7 @@ require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
Expand Down
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jedib0t/go-pretty/v6 v6.6.3 h1:nGqgS0tgIO1Hto47HSaaK4ac/I/Bu7usmdD3qvs0WvM=
github.com/jedib0t/go-pretty/v6 v6.6.3/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shirou/gopsutil/v4 v4.24.10 h1:7VOzPtfw/5YDU+jLEoBwXwxJbQetULywoSV4RYY7HkM=
github.com/shirou/gopsutil/v4 v4.24.10/go.mod h1:s4D/wg+ag4rG0WO7AiTj2BeYCRhym0vM7DHbZRxnIT8=
Expand All @@ -45,8 +39,6 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
8 changes: 7 additions & 1 deletion pkg/logging/userHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ func (h *UserHandler) Handle(ctx context.Context, r slog.Record) error {
colorize(lightGray, r.Time.Format(timeFormat)),
level,
colorize(white, r.Message),
colorize(darkGray, "\n"+trimmedBytes),
colorize(darkGray,
func() string {
if len(trimmedBytes) > 0 && trimmedBytes != "{}" {
return colorize(darkGray, "\n"+trimmedBytes)
}
return ""
}()),
)

return nil
Expand Down
70 changes: 0 additions & 70 deletions pkg/percent/colorpicker.go

This file was deleted.

Loading

0 comments on commit 68ca8d6

Please sign in to comment.