Skip to content

Commit

Permalink
set up defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
adelowo committed Jan 24, 2024
1 parent 5294452 commit f23fd47
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
6 changes: 6 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ func initializeConfig(cfg *config.Config) error {
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

viper.SetDefault("tui.color_scheme", "monokai")
viper.SetDefault("log_level", "debug")
viper.SetDefault("http.database.log_queries", false)
viper.SetDefault("http.port", 4200)
viper.SetDefault("http.domain", "sdump.app")

return viper.Unmarshal(cfg)
}

Expand Down
8 changes: 2 additions & 6 deletions cmd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ func createHTTPCommand(cmd *cobra.Command, cfg *config.Config) {
command := &cobra.Command{
Use: "http",
Short: "Start/run the HTTP server",
RunE: func(cmd *cobra.Command, _ []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
sig := make(chan os.Signal, 1)

signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)

if cfg.Log == "" {
cfg.Log = "error"
}

lvl, err := logrus.ParseLevel(cfg.Log)
lvl, err := logrus.ParseLevel(cfg.LogLevel)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func createSSHCommand(rootCmd *cobra.Command, cfg *config.Config) {
cmd := &cobra.Command{
Use: "ssh",
Short: "Start/run the TUI app",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
app := tui.New(cfg)

if _, err := app.Run(); err != nil {
Expand Down
2 changes: 0 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ http:
port: 4200
domain: http://localhost:4200
database:
type: psql
dsn: postgres://sdump:sdump@localhost:3432/sdump?sslmode=disable
log_queries: true
16 changes: 10 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ type HTTPConfig struct {
AdminSecret string `mapstructure:"admin_secret" json:"admin_secret,omitempty"`

Database struct {
DSN string `mapstructure:"dsn" json:"dsn,omitempty" yaml:"dsn"`
Type DatabaseType `mapstructure:"type" json:"type,omitempty" yaml:"type"`
LogQueries bool `mapstructure:"log_queries" json:"log_queries,omitempty"`
DSN string `mapstructure:"dsn" json:"dsn,omitempty" yaml:"dsn"`
LogQueries bool `mapstructure:"log_queries" json:"log_queries,omitempty"`
} `mapstructure:"database" json:"database,omitempty" yaml:"database"`

Domain string `json:"domain,omitempty"`
}

type TUIConfig struct {
ColorScheme string `mapstructure:"color_scheme" yaml:"color_scheme" json:"color_scheme,omitempty"`
}

type Config struct {
SSH SSHConfig `mapstructure:"ssh" json:"ssh,omitempty" yaml:"ssh"`
HTTP HTTPConfig `json:"http,omitempty" mapstructure:"http"`
Log string `mapstructure:"log" json:"log,omitempty"`
SSH SSHConfig `mapstructure:"ssh" json:"ssh,omitempty" yaml:"ssh"`
HTTP HTTPConfig `json:"http,omitempty" mapstructure:"http" yaml:"http"`
LogLevel string `mapstructure:"log_level" json:"log_level,omitempty" yaml:"log_level"`
TUI TUIConfig `mapstructure:"tui" json:"tui,omitempty" yaml:"tui"`
}
4 changes: 2 additions & 2 deletions internal/tui/css.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func boldenString(s string, withFeint bool) string {
return style.Render(s)
}

func highlightCode(w io.Writer, s string) error {
func highlightCode(w io.Writer, s, colorscheme string) error {
// TODO: make monokai configurable
err := quick.Highlight(w, s, "json", "terminal256", "monokai")
err := quick.Highlight(w, s, "json", "terminal256", colorscheme)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion internal/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (m model) makeTable() string {

// if we have an error here, just reuse the json body as it is without adding
// color
if err := highlightCode(m.detailedRequestViewBuffer, jsonBody); err != nil {
if err := highlightCode(m.detailedRequestViewBuffer, jsonBody, m.cfg.TUI.ColorScheme); err != nil {
m.detailedRequestViewBuffer.WriteString(jsonBody)
}

Expand Down

0 comments on commit f23fd47

Please sign in to comment.