-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use config.json in config repo for menu and settings
- Loading branch information
Toby Padilla
committed
Aug 8, 2021
1 parent
45ec4a8
commit 1e58693
Showing
6 changed files
with
169 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,10 @@ | ||
package tui | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"smoothie/git" | ||
"smoothie/tui/bubbles/commits" | ||
"smoothie/tui/bubbles/selection" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
gg "github.com/go-git/go-git/v5" | ||
"github.com/go-git/go-git/v5/plumbing/object" | ||
) | ||
|
||
type windowMsg struct{} | ||
|
@@ -27,78 +22,26 @@ func (b *Bubble) windowChangesCmd() tea.Msg { | |
} | ||
|
||
func (b *Bubble) loadGitCmd() tea.Msg { | ||
cn := "config" | ||
err := b.repoSource.LoadRepos() | ||
cr, err := b.repoSource.GetRepo(cn) | ||
if err == git.ErrMissingRepo { | ||
cr, err = b.repoSource.InitRepo(cn, false) | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
|
||
// Add default README and config | ||
rp := filepath.Join(b.repoSource.Path, cn, "README.md") | ||
rf, err := os.Create(rp) | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
defer rf.Close() | ||
_, err = rf.WriteString(defaultReadme) | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
err = rf.Sync() | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
cp := filepath.Join(b.repoSource.Path, cn, "config.json") | ||
cf, err := os.Create(cp) | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
defer cf.Close() | ||
_, err = cf.WriteString(defaultConfig) | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
err = cf.Sync() | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
wt, err := cr.Repository.Worktree() | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
_, err = wt.Add("README.md") | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
_, err = wt.Add("config.json") | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
_, err = wt.Commit("Default init", &gg.CommitOptions{ | ||
All: true, | ||
Author: &object.Signature{ | ||
Name: "Smoothie Server", | ||
Email: "[email protected]", | ||
}, | ||
}) | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
err = b.repoSource.LoadRepos() | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
} else if err != nil { | ||
return errMsg{err} | ||
} | ||
b.repos = b.repoSource.AllRepos() | ||
|
||
mes := make([]MenuEntry, 0) | ||
rs := make([]string, 0) | ||
for _, r := range b.repos { | ||
rs = append(rs, r.Name) | ||
for _, me := range b.config.Menu { | ||
mes = append(mes, me) | ||
} | ||
if b.config.ShowAllRepos { | ||
OUTER: | ||
for _, r := range b.repos { | ||
for _, me := range mes { | ||
if r.Name == me.Repo { | ||
continue OUTER | ||
} | ||
} | ||
mes = append(mes, MenuEntry{Name: r.Name, Repo: r.Name}) | ||
} | ||
} | ||
b.repoMenu = mes | ||
for _, me := range mes { | ||
rs = append(rs, me.Name) | ||
} | ||
b.repoSelect = selection.NewBubble(rs) | ||
b.boxes[0] = b.repoSelect | ||
|
@@ -107,10 +50,8 @@ func (b *Bubble) loadGitCmd() tea.Msg { | |
boxRightWidth-horizontalPadding-2, | ||
b.repoSource.GetCommits(200), | ||
) | ||
b.boxes[1] = b.commitsLog | ||
b.activeBox = 0 | ||
b.state = loadedState | ||
return nil | ||
return b.getRepoCmd("config")() | ||
} | ||
|
||
func (b *Bubble) getRepoCmd(name string) tea.Cmd { | ||
|
Oops, something went wrong.