diff --git a/cmd/root.go b/cmd/root.go index 42c0f4a..b8098c0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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" @@ -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 @@ -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") }