Skip to content

Commit

Permalink
Signed-off-by: sarthaksarthak9 <[email protected]>
Browse files Browse the repository at this point in the history
added force-color flag!!
  • Loading branch information
sarthaksarthak9 committed Nov 4, 2023
1 parent 1540969 commit baeaeb6
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,36 @@ type ConfigurableLogger interface {
//
//nolint:staticcheck
func NewPackCommand(logger ConfigurableLogger) (*cobra.Command, error) {
cobra.EnableCommandSorting = false
cfg, cfgPath, err := initConfig()
if err != nil {
return nil, err
}

packClient, err := initClient(logger, cfg)
if err != nil {
return nil, err
}

var forceColor bool // Add a variable to store the forceColor flag

rootCmd := &cobra.Command{
Use: "pack",
Short: "CLI for building apps using Cloud Native Buildpacks",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if fs := cmd.Flags(); fs != nil {
if forceColor { // Check if the forceColor flag is set
color.Enabled()
} else {
if flag, err := fs.GetBool("no-color"); err == nil && flag {
color.Disable(true)
} else {
_, canDisplayColor := term.IsTerminal(logging.GetWriterForLevel(logger, logging.InfoLevel))
if !canDisplayColor {
color.Disable(true)
}
}
}
cobra.EnableCommandSorting = false
cfg, cfgPath, err := initConfig()
if err != nil {
return nil, err
}

packClient, err := initClient(logger, cfg)
if err != nil {
return nil, err
}

var forceColor bool

rootCmd := &cobra.Command{
Use: "pack",
Short: "CLI for building apps using Cloud Native Buildpacks",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if fs := cmd.Flags(); fs != nil {
if forceColor {
color.Enabled()
} else {
if flag, err := fs.GetBool("no-color"); err == nil && flag {
color.Disable(true)
} else {
_, canDisplayColor := term.IsTerminal(logging.GetWriterForLevel(logger, logging.InfoLevel))
if !canDisplayColor {
color.Disable(true)
}
}
}

if flag, err := fs.GetBool("quiet"); err == nil {
logger.WantQuiet(flag)
Expand All @@ -77,6 +77,7 @@ func NewPackCommand(logger ConfigurableLogger) (*cobra.Command, error) {
rootCmd.PersistentFlags().Bool("timestamps", false, "Enable timestamps in output")
rootCmd.PersistentFlags().BoolP("quiet", "q", false, "Show less output")
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Show more output")
rootCmd.PersistentFlags().BoolVar(&forceColor, "force-color", false, "Force color output")
rootCmd.Flags().Bool("version", false, "Show current 'pack' version")

commands.AddHelpFlag(rootCmd, "pack")
Expand Down

0 comments on commit baeaeb6

Please sign in to comment.