Skip to content

Commit

Permalink
Skip flagd banner when non-console logger in use
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Drenski <[email protected]>
  • Loading branch information
austindrenski committed Jan 16, 2025
1 parent 64c5787 commit c1d671f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 45 deletions.
17 changes: 17 additions & 0 deletions flagd-proxy/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"log"
"os"

"github.com/dimiro1/banner"
"github.com/mattn/go-colorable"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -22,6 +24,21 @@ var rootCmd = &cobra.Command{
Short: "flagd-proxy allows flagd to subscribe to CRD changes without the required permissions.",
Long: ``,
DisableAutoGenTag: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if viper.GetString(logFormatFlagName) == "console" {
banner.InitString(colorable.NewColorableStdout(), true, true, `
{{ .AnsiColor.BrightRed }} ______ __ ________ _______ ______
{{ .AnsiColor.BrightRed }} /_____/\ /_/\ /_______/\ /______/\ /_____/\
{{ .AnsiColor.BrightRed }} \::::_\/_\:\ \ \::: _ \ \\::::__\/__\:::_ \ \
{{ .AnsiColor.BrightRed }} \:\/___/\\:\ \ \::(_) \ \\:\ /____/\\:\ \ \ \
{{ .AnsiColor.BrightRed }} \:::._\/ \:\ \____\:: __ \ \\:\\_ _\/ \:\ \ \ \
{{ .AnsiColor.BrightRed }} \:\ \ \:\/___/\\:.\ \ \ \\:\_\ \ \ \:\/.:| |
{{ .AnsiColor.BrightRed }} \_\/ \_____\/ \__\/\__\/ \_____\/ \____/_/
{{ .AnsiColor.BrightRed }} Kubernetes Proxy
{{ .AnsiColor.Default }}
`)
}
},
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
27 changes: 4 additions & 23 deletions flagd-proxy/main.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
package main

import (
"bytes"

"github.com/dimiro1/banner"
"github.com/mattn/go-colorable"
"github.com/open-feature/flagd/flagd-proxy/cmd"
)
import "github.com/open-feature/flagd/flagd-proxy/cmd"

var (
version = "dev"
commit = "HEAD"
date = "unknown"
bannerText = `
{{ .AnsiColor.BrightRed }} ______ __ ________ _______ ______
{{ .AnsiColor.BrightRed }} /_____/\ /_/\ /_______/\ /______/\ /_____/\
{{ .AnsiColor.BrightRed }} \::::_\/_\:\ \ \::: _ \ \\::::__\/__\:::_ \ \
{{ .AnsiColor.BrightRed }} \:\/___/\\:\ \ \::(_) \ \\:\ /____/\\:\ \ \ \
{{ .AnsiColor.BrightRed }} \:::._\/ \:\ \____\:: __ \ \\:\\_ _\/ \:\ \ \ \
{{ .AnsiColor.BrightRed }} \:\ \ \:\/___/\\:.\ \ \ \\:\_\ \ \ \:\/.:| |
{{ .AnsiColor.BrightRed }} \_\/ \_____\/ \__\/\__\/ \_____\/ \____/_/
{{ .AnsiColor.BrightRed }} Kubernetes Proxy
{{ .AnsiColor.Default }}
`
version = "dev"
commit = "HEAD"
date = "unknown"
)

func main() {
banner.Init(colorable.NewColorableStdout(), true, true,
bytes.NewBufferString(bannerText))
cmd.Execute(version, commit, date)
}
16 changes: 16 additions & 0 deletions flagd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"log"
"os"

"github.com/dimiro1/banner"
"github.com/mattn/go-colorable"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -23,6 +25,20 @@ var rootCmd = &cobra.Command{
"It is designed to conform to Open Feature schema for flag definitions.",
Long: ``,
DisableAutoGenTag: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if viper.GetString(logFormatFlagName) == "console" {
banner.InitString(colorable.NewColorableStdout(), true, true, `
{{ .AnsiColor.BrightRed }} ______ __ ________ _______ ______
{{ .AnsiColor.BrightRed }} /_____/\ /_/\ /_______/\ /______/\ /_____/\
{{ .AnsiColor.BrightRed }} \::::_\/_\:\ \ \::: _ \ \\::::__\/__\:::_ \ \
{{ .AnsiColor.BrightRed }} \:\/___/\\:\ \ \::(_) \ \\:\ /____/\\:\ \ \ \
{{ .AnsiColor.BrightRed }} \:::._\/ \:\ \____\:: __ \ \\:\\_ _\/ \:\ \ \ \
{{ .AnsiColor.BrightRed }} \:\ \ \:\/___/\\:.\ \ \ \\:\_\ \ \ \:\/.:| |
{{ .AnsiColor.BrightRed }} \_\/ \_____\/ \__\/\__\/ \_____\/ \____/_/
{{ .AnsiColor.Default }}
`)
}
},
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
Expand Down
26 changes: 4 additions & 22 deletions flagd/main.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
package main

import (
"bytes"

"github.com/dimiro1/banner"
"github.com/mattn/go-colorable"
"github.com/open-feature/flagd/flagd/cmd"
)
import "github.com/open-feature/flagd/flagd/cmd"

var (
version = "dev"
commit = "HEAD"
date = "unknown"
bannerText = `
{{ .AnsiColor.BrightRed }} ______ __ ________ _______ ______
{{ .AnsiColor.BrightRed }} /_____/\ /_/\ /_______/\ /______/\ /_____/\
{{ .AnsiColor.BrightRed }} \::::_\/_\:\ \ \::: _ \ \\::::__\/__\:::_ \ \
{{ .AnsiColor.BrightRed }} \:\/___/\\:\ \ \::(_) \ \\:\ /____/\\:\ \ \ \
{{ .AnsiColor.BrightRed }} \:::._\/ \:\ \____\:: __ \ \\:\\_ _\/ \:\ \ \ \
{{ .AnsiColor.BrightRed }} \:\ \ \:\/___/\\:.\ \ \ \\:\_\ \ \ \:\/.:| |
{{ .AnsiColor.BrightRed }} \_\/ \_____\/ \__\/\__\/ \_____\/ \____/_/
{{ .AnsiColor.Default }}
`
version = "dev"
commit = "HEAD"
date = "unknown"
)

func main() {
banner.Init(colorable.NewColorableStdout(), true, true,
bytes.NewBufferString(bannerText))
cmd.Execute(version, commit, date)
}

0 comments on commit c1d671f

Please sign in to comment.