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 8, 2024
1 parent b0d7584 commit bff3fe8
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 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,12 @@ 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
}
if !interactiveProgress {
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 bff3fe8

Please sign in to comment.