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)
|
settings := logger.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = logger.NewWidget(app, settings)
|
widget = logger.NewWidget(app, settings)
|
||||||
case "mercurial":
|
case "mercurial":
|
||||||
widget = mercurial.NewWidget(app, pages)
|
settings := mercurial.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = mercurial.NewWidget(app, pages, settings)
|
||||||
case "nbascore":
|
case "nbascore":
|
||||||
widget = nbascore.NewWidget(app, pages)
|
widget = nbascore.NewWidget(app, pages)
|
||||||
case "newrelic":
|
case "newrelic":
|
||||||
|
@ -19,13 +19,13 @@ type MercurialRepo struct {
|
|||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMercurialRepo(repoPath string) *MercurialRepo {
|
func NewMercurialRepo(repoPath string, commitCount int, commitFormat string) *MercurialRepo {
|
||||||
repo := MercurialRepo{Path: repoPath}
|
repo := MercurialRepo{Path: repoPath}
|
||||||
|
|
||||||
repo.Branch = strings.TrimSpace(repo.branch())
|
repo.Branch = strings.TrimSpace(repo.branch())
|
||||||
repo.Bookmark = strings.TrimSpace(repo.bookmark())
|
repo.Bookmark = strings.TrimSpace(repo.bookmark())
|
||||||
repo.ChangedFiles = repo.changedFiles()
|
repo.ChangedFiles = repo.changedFiles()
|
||||||
repo.Commits = repo.commits()
|
repo.Commits = repo.commits(commitCount, commitFormat)
|
||||||
repo.Repository = strings.TrimSpace(repo.Path)
|
repo.Repository = strings.TrimSpace(repo.Path)
|
||||||
|
|
||||||
return &repo
|
return &repo
|
||||||
@ -61,10 +61,8 @@ func (repo *MercurialRepo) changedFiles() []string {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *MercurialRepo) commits() []string {
|
func (repo *MercurialRepo) commits(commitCount int, commitFormat string) []string {
|
||||||
numStr := fmt.Sprintf("-l %d", wtf.Config.UInt("wtf.mods.mercurial.commitCount", 10))
|
numStr := fmt.Sprintf("-l %d", commitCount)
|
||||||
|
|
||||||
commitFormat := wtf.Config.UString("wtf.mods.mercurial.commitFormat", "[forestgreen]{rev}:{phase} [white]{desc|firstline|strip} [grey]{author|person} {date|age}[white]")
|
|
||||||
commitStr := fmt.Sprintf("--template=\"%s\n\"", commitFormat)
|
commitStr := fmt.Sprintf("--template=\"%s\n\"", commitFormat)
|
||||||
|
|
||||||
arg := []string{"log", repo.repoPath(), numStr, commitStr}
|
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
|
||||||
|
}
|
@ -31,9 +31,10 @@ type Widget struct {
|
|||||||
app *tview.Application
|
app *tview.Application
|
||||||
Data []*MercurialRepo
|
Data []*MercurialRepo
|
||||||
pages *tview.Pages
|
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{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
MultiSourceWidget: wtf.NewMultiSourceWidget("mercurial", "repository", "repositories"),
|
MultiSourceWidget: wtf.NewMultiSourceWidget("mercurial", "repository", "repositories"),
|
||||||
@ -41,6 +42,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
|||||||
|
|
||||||
app: app,
|
app: app,
|
||||||
pages: pages,
|
pages: pages,
|
||||||
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.LoadSources()
|
widget.LoadSources()
|
||||||
@ -79,7 +81,7 @@ func (widget *Widget) Pull() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
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.Data = widget.mercurialRepos(repoPaths)
|
||||||
widget.display()
|
widget.display()
|
||||||
@ -156,7 +158,7 @@ func (widget *Widget) mercurialRepos(repoPaths []string) []*MercurialRepo {
|
|||||||
repos := []*MercurialRepo{}
|
repos := []*MercurialRepo{}
|
||||||
|
|
||||||
for _, repoPath := range repoPaths {
|
for _, repoPath := range repoPaths {
|
||||||
repo := NewMercurialRepo(repoPath)
|
repo := NewMercurialRepo(repoPath, widget.settings.commitCount, widget.settings.commitFormat)
|
||||||
repos = append(repos, repo)
|
repos = append(repos, repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user