Skip to content

Commit

Permalink
feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvhdr committed Aug 13, 2024
1 parent 9e8b500 commit c3e8816
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ func init() {

rootCmd.Run = func(_ *cobra.Command, args []string) {
var repo *string
if len(args) > 0 {
_, repos := os.LookupEnv("FF_REPOS_VIEW")
if repos && len(args) > 0 {
repo = &args[0]
}
debug, err := rootCmd.Flags().GetBool("debug")
Expand Down
10 changes: 10 additions & 0 deletions config/feature_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package config

import "os"

const FF_REPO_VIEW = "FF_REPO_VIEW"

func IsFeatureEnabled(name string) bool {
_, ok := os.LookupEnv(name)
return ok
}
4 changes: 4 additions & 0 deletions config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ func (parser ConfigParser) readConfigFile(path string) (Config, error) {
if err != nil {
return config, err
}
repoFF := IsFeatureEnabled(FF_REPO_VIEW)
if config.Defaults.View == RepoView && !repoFF {
config.Defaults.View = PRsView
}

err = validate.Struct(config)
return config, err
Expand Down
2 changes: 0 additions & 2 deletions ui/components/reposection/reposection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/log"

"github.com/dlvhdr/gh-dash/v4/config"
"github.com/dlvhdr/gh-dash/v4/data"
Expand Down Expand Up @@ -108,7 +107,6 @@ func (m Model) Update(msg tea.Msg) (section.Section, tea.Cmd) {
}

case repoMsg:
log.Debug("repoMsg", "msg", msg.repo)
m.repo = msg.repo
m.Table.SetIsLoading(false)
m.Table.SetRows(m.BuildRows())
Expand Down
18 changes: 16 additions & 2 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,23 @@ func (m *Model) setCurrentViewSections(newSections []section.Section) {
}

func (m *Model) switchSelectedView() config.ViewType {
if m.ctx.View == config.PRsView {
repoFF := config.IsFeatureEnabled(config.FF_REPO_VIEW)

if repoFF {
switch true {
case m.ctx.View == config.RepoView:
return config.PRsView
case m.ctx.View == config.PRsView:
return config.IssuesView
case m.ctx.View == config.IssuesView:
return config.RepoView
}
}

switch true {
case m.ctx.View == config.PRsView:
return config.IssuesView
} else {
default:
return config.PRsView
}
}
Expand Down

0 comments on commit c3e8816

Please sign in to comment.