mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 Mercurial extracted to new config format
This commit is contained in:
parent
8bc217e9a1
commit
3259e16ada
3
main.go
3
main.go
@ -247,7 +247,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
||||
settings := logger.NewSettingsFromYAML(wtf.Config)
|
||||
widget = logger.NewWidget(app, settings)
|
||||
case "mercurial":
|
||||
widget = mercurial.NewWidget(app, pages)
|
||||
settings := mercurial.NewSettingsFromYAML(wtf.Config)
|
||||
widget = mercurial.NewWidget(app, pages, settings)
|
||||
case "nbascore":
|
||||
widget = nbascore.NewWidget(app, pages)
|
||||
case "newrelic":
|
||||
|
@ -19,13 +19,13 @@ type MercurialRepo struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
func NewMercurialRepo(repoPath string) *MercurialRepo {
|
||||
func NewMercurialRepo(repoPath string, commitCount int, commitFormat string) *MercurialRepo {
|
||||
repo := MercurialRepo{Path: repoPath}
|
||||
|
||||
repo.Branch = strings.TrimSpace(repo.branch())
|
||||
repo.Bookmark = strings.TrimSpace(repo.bookmark())
|
||||
repo.ChangedFiles = repo.changedFiles()
|
||||
repo.Commits = repo.commits()
|
||||
repo.Commits = repo.commits(commitCount, commitFormat)
|
||||
repo.Repository = strings.TrimSpace(repo.Path)
|
||||
|
||||
return &repo
|
||||
@ -61,10 +61,8 @@ func (repo *MercurialRepo) changedFiles() []string {
|
||||
return data
|
||||
}
|
||||
|
||||
func (repo *MercurialRepo) commits() []string {
|
||||
numStr := fmt.Sprintf("-l %d", wtf.Config.UInt("wtf.mods.mercurial.commitCount", 10))
|
||||
|
||||
commitFormat := wtf.Config.UString("wtf.mods.mercurial.commitFormat", "[forestgreen]{rev}:{phase} [white]{desc|firstline|strip} [grey]{author|person} {date|age}[white]")
|
||||
func (repo *MercurialRepo) commits(commitCount int, commitFormat string) []string {
|
||||
numStr := fmt.Sprintf("-l %d", commitCount)
|
||||
commitStr := fmt.Sprintf("--template=\"%s\n\"", commitFormat)
|
||||
|
||||
arg := []string{"log", repo.repoPath(), numStr, commitStr}
|
||||
|
28
modules/mercurial/settings.go
Normal file
28
modules/mercurial/settings.go
Normal file
@ -0,0 +1,28 @@
|
||||
package mercurial
|
||||
|
||||
import (
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
common *cfg.Common
|
||||
|
||||
commitCount int
|
||||
commitFormat string
|
||||
repositories []interface{}
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.mercurial")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
|
||||
commitCount: localConfig.UInt("commitCount", 10),
|
||||
commitFormat: localConfig.UString("commitFormat", "[forestgreen]{rev}:{phase} [white]{desc|firstline|strip} [grey]{author|person} {date|age}[white]"),
|
||||
repositories: localConfig.UList("repositories"),
|
||||
}
|
||||
|
||||
return &settings
|
||||
}
|
@ -28,19 +28,21 @@ type Widget struct {
|
||||
wtf.MultiSourceWidget
|
||||
wtf.TextWidget
|
||||
|
||||
app *tview.Application
|
||||
Data []*MercurialRepo
|
||||
pages *tview.Pages
|
||||
app *tview.Application
|
||||
Data []*MercurialRepo
|
||||
pages *tview.Pages
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
MultiSourceWidget: wtf.NewMultiSourceWidget("mercurial", "repository", "repositories"),
|
||||
TextWidget: wtf.NewTextWidget(app, "Mercurial", "mercurial", true),
|
||||
|
||||
app: app,
|
||||
pages: pages,
|
||||
app: app,
|
||||
pages: pages,
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.LoadSources()
|
||||
@ -79,7 +81,7 @@ func (widget *Widget) Pull() {
|
||||
}
|
||||
|
||||
func (widget *Widget) Refresh() {
|
||||
repoPaths := wtf.ToStrs(wtf.Config.UList("wtf.mods.mercurial.repositories"))
|
||||
repoPaths := wtf.ToStrs(widget.settings.repositories)
|
||||
|
||||
widget.Data = widget.mercurialRepos(repoPaths)
|
||||
widget.display()
|
||||
@ -156,7 +158,7 @@ func (widget *Widget) mercurialRepos(repoPaths []string) []*MercurialRepo {
|
||||
repos := []*MercurialRepo{}
|
||||
|
||||
for _, repoPath := range repoPaths {
|
||||
repo := NewMercurialRepo(repoPath)
|
||||
repo := NewMercurialRepo(repoPath, widget.settings.commitCount, widget.settings.commitFormat)
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user