add register command

This commit is contained in:
2023-05-25 16:12:33 -07:00
parent 399faba8ef
commit cdb17168b3
7 changed files with 242 additions and 40 deletions

View File

@@ -27,6 +27,10 @@ func (m MGConfig) GetRepoPaths() []string {
return paths
}
func (m *MGConfig) AddRepo(path, remote string) {
m.Repos = append(m.Repos, Repo{Path: path, Remote: remote})
}
// LoadMGConfig loads the mgconfig file from the XDG_CONFIG_HOME directory
// or from the default location of $HOME/.config/mgconfig
// If the file is not found, an error is returned

View File

@@ -14,9 +14,9 @@ type MRConfig struct {
Aliases map[string]string
}
type Repo struct {
Path string
Checkout string
Aliases map[string]string
Path string
Remote string
Aliases map[string]string `json:"aliases,omitempty"`
}
// GetRepoPaths returns a slice of strings containing the paths of all repos
@@ -30,15 +30,16 @@ func (m MRConfig) GetRepoPaths() []string {
}
func (m MRConfig) ToMGConfig() MGConfig {
mgconf := MGConfig{
Repos: []Repo{},
Aliases: m.Aliases,
}
for _, r := range m.Repos {
mgconf.Repos = append(mgconf.Repos, Repo{
Path: r.Path,
Aliases: r.Aliases,
})
mgconf := MGConfig(m)
for i, repo := range mgconf.Repos {
checkout := repo.Remote
if strings.HasPrefix(checkout, "git clone '") {
// git clone 'git@bitbucket.org:taigrr/mg.git' 'mg'
remote := strings.TrimPrefix(checkout, "git clone '")
sp := strings.Split(remote, "' '")
remote = sp[0]
mgconf.Repos[i].Remote = remote
}
}
return mgconf
}
@@ -103,7 +104,8 @@ func LoadMRConfig() (MRConfig, error) {
if split[0] != "checkout" {
return MRConfig{}, fmt.Errorf("unexpected argument on line %d: %s", n, line)
}
config.Repos[length].Checkout = split[1]
config.Repos[length].Remote = split[1]
case "default":