Skip to content

Commit

Permalink
fix: correctly disable colors and interactive progress if not in inte…
Browse files Browse the repository at this point in the history
…ractive progress mode
  • Loading branch information
tulilirockz committed Dec 13, 2024
1 parent 7add70a commit b609be4
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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"
Expand Down Expand Up @@ -107,6 +108,15 @@ func init() {
rootCmd.AddCommand(updateCheckCmd)
rootCmd.AddCommand(hardwareCheckCmd)
rootCmd.AddCommand(imageOutdatedCmd)
rootCmd.Flags().BoolP("hw-check", "c", false, "Run hardware check before running updates")
rootCmd.Flags().BoolP("dry-run", "n", false, "Do a dry run")
rootCmd.Flags().BoolP("verbose", "v", false, "Display command outputs after run")
rootCmd.Flags().Bool("ci", false, "Makes some modifications to behavior if is running in CI")

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
Expand All @@ -115,13 +125,10 @@ func init() {
if !isTerminal {
interactiveProgress = false
}
rootCmd.Flags().BoolP("no-progress", "p", interactiveProgress, "Do not show progress bars")
rootCmd.Flags().BoolP("hw-check", "c", false, "Run hardware check before running updates")
rootCmd.Flags().BoolP("dry-run", "n", false, "Do a dry run")
rootCmd.Flags().BoolP("verbose", "v", false, "Display command outputs after run")
rootCmd.Flags().Bool("ci", false, "Makes some modifications to behavior if is running in CI")
if !text.ANSICodesSupported {
interactiveProgress = false
text.DisableColors()
}

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")
rootCmd.Flags().BoolP("no-progress", "p", !interactiveProgress, "Do not show progress bars")
}

0 comments on commit b609be4

Please sign in to comment.