mirror of
https://github.com/taigrr/mg.git
synced 2026-04-02 11:38:41 -07:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e93a0489d3 | |||
| 567ab899e0 | |||
| a889092b0d | |||
|
1a593ad588
|
|||
|
c5310d13b0
|
|||
|
256e82cca2
|
|||
|
b99b1eabec
|
|||
|
f503d4b0eb
|
|||
|
f368381458
|
|||
|
a5817c554b
|
|||
|
15122346d1
|
|||
|
c2d67df8f0
|
|||
|
84d7a73202
|
|||
|
662d80fbf5
|
|||
|
e4475de48c
|
|||
| 82be16a6ba | |||
|
a4a3f1f332
|
|||
|
15cbf5c0a0
|
|||
|
2085e2b8b7
|
|||
|
2818cfb61d
|
|||
|
809d4a0711
|
|||
|
cdb17168b3
|
|||
|
399faba8ef
|
|||
|
9a4f8023d8
|
|||
|
93a21b8c61
|
|||
|
28f0329d4a
|
|||
|
97c2e898fc
|
|||
|
5929432d08
|
|||
|
7455da4355
|
|||
| 144d4f6b87 | |||
| f28b5df9ef |
12
.github/FUNDING.yml
vendored
Normal file
12
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: taigrr # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
cmd/mg/mg
|
||||
32
README.md
Normal file
32
README.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# mg
|
||||
|
||||
Golang replacement for [myrepos](https://myrepos.branchable.com/) which only supports git repos.
|
||||
|
||||
This app will support the following subcommands:
|
||||
|
||||
- mg commit
|
||||
- mg push
|
||||
- mg status
|
||||
- mg diff
|
||||
- mg pull
|
||||
- mg fetch
|
||||
- mg register
|
||||
- mg unregister
|
||||
|
||||
Passing the `-jX` argument will spin up X jobs simultaneously
|
||||
|
||||
mg supports loading an existing ~/.mrconfig and migrating it to ~/.config/mg.conf, provided no mg.conf file exists.
|
||||
|
||||
|
||||
## Improvements over mr:
|
||||
1. No external dependencies (even git!*)
|
||||
1. More output options (summary of failures)
|
||||
1. More deterministic behavior (global vs local run, register from git project subdir)
|
||||
1. Exports public functions and can be embedded into other Go programs idiomatically
|
||||
|
||||
|
||||
## Why to stick with mr:
|
||||
1. If you need support for non-git VCS tooling
|
||||
1. If you want to use the [mr plugin ecosystem](https://myrepos.branchable.com/#:~:text=repos%20to%20myrepos-,related%20software,-garden%3A%20manage%20git)
|
||||
|
||||
*: custom-registered commands may rely on external applications.
|
||||
96
cmd/mg/cmd/clone.go
Normal file
96
cmd/mg/cmd/clone.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
git "github.com/go-git/go-git/v5"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/taigrr/mg/parse"
|
||||
)
|
||||
|
||||
// cloneCmd represents the clone command
|
||||
var (
|
||||
cloneCmd = &cobra.Command{
|
||||
Use: "clone",
|
||||
Short: "ensure all repos defined in the config are cloned",
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
type RepoError struct {
|
||||
Error error
|
||||
Repo string
|
||||
}
|
||||
if jobs < 1 {
|
||||
log.Println("jobs must be greater than 0")
|
||||
os.Exit(1)
|
||||
}
|
||||
conf := GetConfig()
|
||||
if len(args) > 0 {
|
||||
log.Println("too many arguments")
|
||||
os.Exit(1)
|
||||
}
|
||||
repoChan := make(chan parse.Repo, len(conf.Repos))
|
||||
errs := []RepoError{}
|
||||
alreadyCloned := 0
|
||||
mutex := sync.Mutex{}
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(conf.Repos))
|
||||
for i := 0; i < jobs; i++ {
|
||||
go func() {
|
||||
for repo := range repoChan {
|
||||
_, err := git.PlainOpenWithOptions(repo.Remote, &(git.PlainOpenOptions{DetectDotGit: true}))
|
||||
if err == nil {
|
||||
log.Printf("already cloned: %s\n", repo.Path)
|
||||
mutex.Lock()
|
||||
alreadyCloned++
|
||||
mutex.Unlock()
|
||||
} else if err == git.ErrRepositoryNotExists {
|
||||
log.Printf("attempting clone: %s\n", repo)
|
||||
_, err = git.PlainClone(repo.Path, false, &git.CloneOptions{
|
||||
URL: repo.Remote,
|
||||
})
|
||||
if err != nil {
|
||||
mutex.Lock()
|
||||
errs = append(errs, RepoError{Error: err, Repo: repo.Path})
|
||||
mutex.Unlock()
|
||||
log.Printf("clone failed for %s: %v\n", repo.Path, err)
|
||||
wg.Done()
|
||||
continue
|
||||
}
|
||||
fmt.Printf("successfully cloned %s\n", repo)
|
||||
wg.Done()
|
||||
continue
|
||||
} else {
|
||||
mutex.Lock()
|
||||
errs = append(errs, RepoError{Error: err, Repo: repo.Path})
|
||||
mutex.Unlock()
|
||||
log.Printf("clone failed for %s: %v\n", repo, err)
|
||||
wg.Done()
|
||||
continue
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
for _, repo := range conf.Repos {
|
||||
repoChan <- repo
|
||||
}
|
||||
close(repoChan)
|
||||
wg.Wait()
|
||||
for _, err := range errs {
|
||||
log.Printf("error pulling %s: %s\n", err.Repo, err.Error)
|
||||
}
|
||||
lenErrs := len(errs)
|
||||
fmt.Println()
|
||||
fmt.Printf("successfully cloned %d/%d repos\n", len(conf.Repos)-lenErrs, len(conf.Repos))
|
||||
fmt.Printf("%d repos already cloned\n", alreadyCloned)
|
||||
fmt.Printf("failed to clone %d/%d repos\n", lenErrs, len(conf.Repos))
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(cloneCmd)
|
||||
cloneCmd.Flags().IntVarP(&jobs, "jobs", "j", 1, "number of jobs to run in parallel")
|
||||
}
|
||||
20
cmd/mg/cmd/commit.go
Normal file
20
cmd/mg/cmd/commit.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// commitCmd represents the commit command
|
||||
var commitCmd = &cobra.Command{
|
||||
Use: "commit",
|
||||
Short: "commit all current repos with the same message",
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
fmt.Println("commit called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(commitCmd)
|
||||
}
|
||||
31
cmd/mg/cmd/common.go
Normal file
31
cmd/mg/cmd/common.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/taigrr/mg/parse"
|
||||
)
|
||||
|
||||
func GetConfig() parse.MGConfig {
|
||||
conf, err := parse.LoadMGConfig()
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
// Try to load mr config instead
|
||||
mrconf, err := parse.LoadMRConfig()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
conf = mrconf.ToMGConfig()
|
||||
log.Println("migrated mrconfig to mgconfig")
|
||||
err = conf.Save()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
return conf
|
||||
}
|
||||
21
cmd/mg/cmd/config.go
Normal file
21
cmd/mg/cmd/config.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// configCmd represents the config command
|
||||
var configCmd = &cobra.Command{
|
||||
Use: "config",
|
||||
Short: "",
|
||||
Long: ``,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("config called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(configCmd)
|
||||
}
|
||||
20
cmd/mg/cmd/diff.go
Normal file
20
cmd/mg/cmd/diff.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// diffCmd represents the diff command
|
||||
var diffCmd = &cobra.Command{
|
||||
Use: "diff",
|
||||
Short: "compute a collective diff",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("diff called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(diffCmd)
|
||||
}
|
||||
19
cmd/mg/cmd/fetch.go
Normal file
19
cmd/mg/cmd/fetch.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var fetchCmd = &cobra.Command{
|
||||
Use: "fetch",
|
||||
Short: "fetch all git repos without merging",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("fetch called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(fetchCmd)
|
||||
}
|
||||
64
cmd/mg/cmd/import.go
Normal file
64
cmd/mg/cmd/import.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/taigrr/mg/parse"
|
||||
)
|
||||
|
||||
var importCmd = &cobra.Command{
|
||||
Use: "import <file>",
|
||||
Short: "merge a new mgconfig into the current one",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
conf := GetConfig()
|
||||
if args[0] == "-" {
|
||||
f, err := io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
parsed, err := parse.ParseMGConfig(f)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
stats, err := conf.Merge(parsed)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println(stats)
|
||||
} else {
|
||||
f, err := os.ReadFile(args[0])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
parsed, err := parse.ParseMGConfig(f)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
stats, err := conf.Merge(parsed)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println(stats)
|
||||
}
|
||||
err := conf.Save()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(importCmd)
|
||||
}
|
||||
103
cmd/mg/cmd/pull.go
Normal file
103
cmd/mg/cmd/pull.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
git "github.com/go-git/go-git/v5"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// pullCmd represents the pull command
|
||||
var (
|
||||
jobs int
|
||||
pullCmd = &cobra.Command{
|
||||
Use: "pull",
|
||||
Short: "add current path to list of repos",
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
type RepoError struct {
|
||||
Error error
|
||||
Repo string
|
||||
}
|
||||
if jobs < 1 {
|
||||
log.Println("jobs must be greater than 0")
|
||||
os.Exit(1)
|
||||
}
|
||||
conf := GetConfig()
|
||||
if len(args) > 0 {
|
||||
log.Println("too many arguments")
|
||||
os.Exit(1)
|
||||
}
|
||||
repoChan := make(chan string, len(conf.Repos))
|
||||
errs := []RepoError{}
|
||||
alreadyUpToDate := 0
|
||||
mutex := sync.Mutex{}
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(conf.Repos))
|
||||
for i := 0; i < jobs; i++ {
|
||||
go func() {
|
||||
for repo := range repoChan {
|
||||
log.Printf("attempting pull: %s\n", repo)
|
||||
r, err := git.PlainOpenWithOptions(repo, &(git.PlainOpenOptions{DetectDotGit: true}))
|
||||
if err != nil {
|
||||
mutex.Lock()
|
||||
errs = append(errs, RepoError{Error: err, Repo: repo})
|
||||
mutex.Unlock()
|
||||
log.Printf("pull failed for %s: %v\n", repo, err)
|
||||
wg.Done()
|
||||
continue
|
||||
}
|
||||
w, err := r.Worktree()
|
||||
if err != nil {
|
||||
mutex.Lock()
|
||||
errs = append(errs, RepoError{Error: err, Repo: repo})
|
||||
mutex.Unlock()
|
||||
log.Printf("pull failed for %s: %v\n", repo, err)
|
||||
wg.Done()
|
||||
continue
|
||||
}
|
||||
err = w.Pull(&git.PullOptions{})
|
||||
if err == git.NoErrAlreadyUpToDate {
|
||||
mutex.Lock()
|
||||
alreadyUpToDate++
|
||||
mutex.Unlock()
|
||||
fmt.Printf("repo %s: already up to date\n", repo)
|
||||
wg.Done()
|
||||
continue
|
||||
} else if err != nil {
|
||||
mutex.Lock()
|
||||
errs = append(errs, RepoError{Error: err, Repo: repo})
|
||||
mutex.Unlock()
|
||||
log.Printf("pull failed for %s: %v\n", repo, err)
|
||||
wg.Done()
|
||||
continue
|
||||
} else {
|
||||
fmt.Printf("successfully pulled %s\n", w.Filesystem.Root())
|
||||
}
|
||||
wg.Done()
|
||||
}
|
||||
}()
|
||||
}
|
||||
for _, repo := range conf.Repos {
|
||||
repoChan <- repo.Path
|
||||
}
|
||||
close(repoChan)
|
||||
wg.Wait()
|
||||
for _, err := range errs {
|
||||
log.Printf("error pulling %s: %s\n", err.Repo, err.Error)
|
||||
}
|
||||
lenErrs := len(errs)
|
||||
fmt.Println()
|
||||
fmt.Printf("successfully pulled %d/%d repos\n", len(conf.Repos)-lenErrs, len(conf.Repos))
|
||||
fmt.Printf("%d repos already up to date\n", alreadyUpToDate)
|
||||
fmt.Printf("failed to pull %d/%d repos\n", lenErrs, len(conf.Repos))
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(pullCmd)
|
||||
pullCmd.Flags().IntVarP(&jobs, "jobs", "j", 1, "number of jobs to run in parallel")
|
||||
}
|
||||
20
cmd/mg/cmd/push.go
Normal file
20
cmd/mg/cmd/push.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// pushCmd represents the push command
|
||||
var pushCmd = &cobra.Command{
|
||||
Use: "push",
|
||||
Short: "push all git repos",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("push called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(pushCmd)
|
||||
}
|
||||
72
cmd/mg/cmd/register.go
Normal file
72
cmd/mg/cmd/register.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
git "github.com/go-git/go-git/v5"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var registerCmd = &cobra.Command{
|
||||
Use: "register",
|
||||
Short: "add current path to list of repos",
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
conf := GetConfig()
|
||||
path, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if len(args) == 1 {
|
||||
path = args[0]
|
||||
} else if len(args) > 1 {
|
||||
log.Println("too many arguments")
|
||||
os.Exit(1)
|
||||
}
|
||||
r, err := git.PlainOpenWithOptions(path, &(git.PlainOpenOptions{DetectDotGit: true}))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
remotes, err := r.Remotes()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if len(remotes) == 0 {
|
||||
log.Println("no remotes found")
|
||||
os.Exit(1)
|
||||
}
|
||||
remote := remotes[0]
|
||||
urls := remote.Config().URLs
|
||||
if len(urls) == 0 {
|
||||
log.Println("no urls found for remote")
|
||||
os.Exit(1)
|
||||
}
|
||||
url := urls[0]
|
||||
newPath, err := r.Worktree()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
path = newPath.Filesystem.Root()
|
||||
for _, v := range conf.Repos {
|
||||
if v.Path == path {
|
||||
fmt.Printf("repo %s already registered\n", path)
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
conf.AddRepo(path, url)
|
||||
err = conf.Save()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(registerCmd)
|
||||
}
|
||||
22
cmd/mg/cmd/root.go
Normal file
22
cmd/mg/cmd/root.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "mg",
|
||||
Short: "go replacement for myrepos which only supports git repos",
|
||||
}
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||
func Execute() {
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
20
cmd/mg/cmd/status.go
Normal file
20
cmd/mg/cmd/status.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// statusCmd represents the status command
|
||||
var statusCmd = &cobra.Command{
|
||||
Use: "status",
|
||||
Short: "get the combined git status for all git repos",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("status called")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(statusCmd)
|
||||
}
|
||||
60
cmd/mg/cmd/unregister.go
Normal file
60
cmd/mg/cmd/unregister.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
git "github.com/go-git/go-git/v5"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// unregisterCmd represents the unregister command
|
||||
var unregisterCmd = &cobra.Command{
|
||||
Use: "unregister",
|
||||
Short: "add current path to list of repos",
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
conf := GetConfig()
|
||||
path, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if len(args) == 1 {
|
||||
path = args[0]
|
||||
err = conf.DelRepo(path)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
} else if len(args) > 1 {
|
||||
log.Println("too many arguments")
|
||||
os.Exit(1)
|
||||
}
|
||||
r, err := git.PlainOpenWithOptions(path, &(git.PlainOpenOptions{DetectDotGit: true}))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
newPath, err := r.Worktree()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
path = newPath.Filesystem.Root()
|
||||
err = conf.DelRepo(path)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = conf.Save()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(unregisterCmd)
|
||||
}
|
||||
9
cmd/mg/main.go
Normal file
9
cmd/mg/main.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/taigrr/mg/cmd/mg/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
}
|
||||
33
go.mod
33
go.mod
@@ -1,3 +1,34 @@
|
||||
module github.com/taigrr/mg
|
||||
|
||||
go 1.19
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
github.com/go-git/go-git/v5 v5.11.0
|
||||
github.com/spf13/cobra v1.8.0
|
||||
)
|
||||
|
||||
require (
|
||||
dario.cat/mergo v1.0.0 // indirect
|
||||
github.com/Microsoft/go-winio v0.6.1 // indirect
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c // indirect
|
||||
github.com/cloudflare/circl v1.3.7 // indirect
|
||||
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
|
||||
github.com/emirpasic/gods v1.18.1 // indirect
|
||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
|
||||
github.com/go-git/go-billy/v5 v5.5.0 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||
github.com/kevinburke/ssh_config v1.2.0 // indirect
|
||||
github.com/pjbgf/sha1cd v0.3.0 // indirect
|
||||
github.com/sergi/go-diff v1.3.1 // indirect
|
||||
github.com/skeema/knownhosts v1.2.1 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/xanzy/ssh-agent v0.3.3 // indirect
|
||||
golang.org/x/crypto v0.17.0 // indirect
|
||||
golang.org/x/mod v0.14.0 // indirect
|
||||
golang.org/x/net v0.19.0 // indirect
|
||||
golang.org/x/sys v0.16.0 // indirect
|
||||
golang.org/x/tools v0.16.1 // indirect
|
||||
gopkg.in/warnings.v0 v0.1.2 // indirect
|
||||
)
|
||||
|
||||
153
go.sum
Normal file
153
go.sum
Normal file
@@ -0,0 +1,153 @@
|
||||
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
|
||||
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
||||
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
|
||||
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
|
||||
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c h1:kMFnB0vCcX7IL/m9Y5LO+KQYv+t1CQOiFe6+SV2J7bE=
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
||||
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
|
||||
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
|
||||
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
|
||||
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU=
|
||||
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
|
||||
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
|
||||
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
|
||||
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
|
||||
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
|
||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
|
||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
|
||||
github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU=
|
||||
github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
|
||||
github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4=
|
||||
github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
||||
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
|
||||
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
|
||||
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
|
||||
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
|
||||
github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
|
||||
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
|
||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ=
|
||||
github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
|
||||
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
|
||||
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
|
||||
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
|
||||
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
||||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
|
||||
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
||||
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
|
||||
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
|
||||
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
|
||||
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
|
||||
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
|
||||
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
|
||||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
141
parse/mgconf.go
Normal file
141
parse/mgconf.go
Normal file
@@ -0,0 +1,141 @@
|
||||
package parse
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var errAlreadyRegistered = os.ErrExist
|
||||
|
||||
// MGConfig is the struct that represents the mgconfig file
|
||||
// It contains a slice of Repo structs and a map of aliases
|
||||
// The aliases map is a map of strings to strings, where the key is the alias
|
||||
// and the value is a command to be run
|
||||
type MGConfig struct {
|
||||
Repos []Repo
|
||||
Aliases map[string]string
|
||||
}
|
||||
|
||||
// GetRepoPaths returns a slice of strings containing the paths of the repos
|
||||
// in the mgconfig file
|
||||
|
||||
func (m MGConfig) GetRepoPaths() []string {
|
||||
paths := []string{}
|
||||
for _, r := range m.Repos {
|
||||
paths = append(paths, r.Path)
|
||||
}
|
||||
return paths
|
||||
}
|
||||
|
||||
func (m *MGConfig) DelRepo(path string) error {
|
||||
for i, v := range m.Repos {
|
||||
if v.Path == path {
|
||||
m.Repos = append(m.Repos[:i], m.Repos[i+1:]...)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return os.ErrNotExist
|
||||
}
|
||||
|
||||
func (m *MGConfig) AddRepo(path, remote string) error {
|
||||
for _, v := range m.Repos {
|
||||
if v.Path == path {
|
||||
return errAlreadyRegistered
|
||||
}
|
||||
}
|
||||
|
||||
m.Repos = append(m.Repos, Repo{Path: path, Remote: remote})
|
||||
return nil
|
||||
}
|
||||
|
||||
type Stats struct {
|
||||
Duplicates int
|
||||
NewPaths []string
|
||||
}
|
||||
|
||||
func (s Stats) String() string {
|
||||
str := ""
|
||||
for _, v := range s.NewPaths {
|
||||
str += "Added repo " + v + "\n"
|
||||
}
|
||||
str += "\nAdded " + fmt.Sprintf("%d", len(s.NewPaths)) + " new repos\n"
|
||||
str += "Skipped " + fmt.Sprintf("%d", s.Duplicates) + " duplicate repos"
|
||||
return str
|
||||
}
|
||||
|
||||
func (m *MGConfig) Merge(m2 MGConfig) (Stats, error) {
|
||||
stats := Stats{}
|
||||
for _, v := range m2.Repos {
|
||||
err := m.AddRepo(v.Path, v.Remote)
|
||||
switch err {
|
||||
case errAlreadyRegistered:
|
||||
stats.Duplicates++
|
||||
continue
|
||||
case nil:
|
||||
stats.NewPaths = append(stats.NewPaths, v.Path)
|
||||
continue
|
||||
default:
|
||||
|
||||
return stats, err
|
||||
}
|
||||
}
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
// 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
|
||||
func LoadMGConfig() (MGConfig, error) {
|
||||
mgConf := os.Getenv("MGCONFIG")
|
||||
if mgConf == "" {
|
||||
confDir := os.Getenv("XDG_CONFIG_HOME")
|
||||
if confDir == "" {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return MGConfig{}, err
|
||||
}
|
||||
confDir = filepath.Join(home, ".config")
|
||||
if _, err := os.Stat(confDir); err != nil {
|
||||
return MGConfig{}, err
|
||||
}
|
||||
}
|
||||
mgConf = filepath.Join(confDir, "mgconfig")
|
||||
}
|
||||
file, err := os.ReadFile(mgConf)
|
||||
if err != nil {
|
||||
return MGConfig{}, err
|
||||
}
|
||||
return ParseMGConfig(file)
|
||||
}
|
||||
|
||||
// ParseMGConfig parses the mgconfig file from a byte slice
|
||||
func ParseMGConfig(b []byte) (MGConfig, error) {
|
||||
var config MGConfig
|
||||
err := json.Unmarshal(b, &config)
|
||||
return config, err
|
||||
}
|
||||
|
||||
func (m MGConfig) Save() error {
|
||||
mgConf := os.Getenv("MGCONFIG")
|
||||
if mgConf == "" {
|
||||
confDir := os.Getenv("XDG_CONFIG_HOME")
|
||||
if confDir == "" {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
confDir = filepath.Join(home, ".config")
|
||||
if _, err := os.Stat(confDir); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
mgConf = filepath.Join(confDir, "mgconfig")
|
||||
}
|
||||
b, err := json.MarshalIndent(m, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(mgConf, b, 0o644)
|
||||
}
|
||||
@@ -3,22 +3,23 @@ package parse
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type MRConfig struct {
|
||||
Unregister string
|
||||
GC string
|
||||
Repos []Repo
|
||||
Repos []Repo
|
||||
Aliases map[string]string
|
||||
}
|
||||
type Repo struct {
|
||||
Path string
|
||||
Checkout string
|
||||
Path string
|
||||
Remote string
|
||||
Aliases map[string]string `json:"aliases,omitempty"`
|
||||
}
|
||||
|
||||
// GetRepoPaths returns a slice of strings containing the paths of all repos
|
||||
// in the MRConfig struct
|
||||
func (m MRConfig) GetRepoPaths() []string {
|
||||
paths := []string{}
|
||||
for _, r := range m.Repos {
|
||||
@@ -27,6 +28,24 @@ func (m MRConfig) GetRepoPaths() []string {
|
||||
return paths
|
||||
}
|
||||
|
||||
func (m MRConfig) ToMGConfig() MGConfig {
|
||||
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
|
||||
}
|
||||
|
||||
// LoadMRConfig loads the mrconfig file from the user's home directory
|
||||
// and returns a MRConfig struct
|
||||
// TODO: load aliases into map instead of hardcoded Unregister prop
|
||||
func LoadMRConfig() (MRConfig, error) {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
@@ -40,13 +59,16 @@ func LoadMRConfig() (MRConfig, error) {
|
||||
if s.IsDir() {
|
||||
return MRConfig{}, errors.New("expected mrconfig file but got a directory")
|
||||
}
|
||||
f, err := ioutil.ReadFile(mrconfPath)
|
||||
f, err := os.ReadFile(mrconfPath)
|
||||
if err != nil {
|
||||
return MRConfig{}, err
|
||||
}
|
||||
text := string(f)
|
||||
lines := strings.Split(text, "\n")
|
||||
config := MRConfig{}
|
||||
config := MRConfig{
|
||||
Aliases: make(map[string]string),
|
||||
Repos: []Repo{},
|
||||
}
|
||||
|
||||
length := -1
|
||||
mode := "default"
|
||||
@@ -81,13 +103,17 @@ 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":
|
||||
|
||||
// TODO load text into Aliases map instead of hardcoded Unregister prop
|
||||
switch split[0] {
|
||||
case "unregister":
|
||||
config.Unregister = split[1]
|
||||
config.Aliases["unregister"] = split[1]
|
||||
case "git_gc":
|
||||
config.GC = split[1]
|
||||
config.Aliases["gc"] = split[1]
|
||||
default:
|
||||
return MRConfig{}, fmt.Errorf("unexpected argument on line %d: %s", n, line)
|
||||
}
|
||||
|
||||
16
parse/myrepos_test.go
Normal file
16
parse/myrepos_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package parse
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestLoadMRConfig(t *testing.T) {
|
||||
// test cases for LoadMRConfig
|
||||
tests := []struct {
|
||||
id string
|
||||
}{}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.id, func(t *testing.T) {
|
||||
// TODO
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user