Compare commits
3 Commits
v1.0.0
...
219a75a1d3
| Author | SHA1 | Date | |
|---|---|---|---|
| 219a75a1d3 | |||
| b286d5578e | |||
| d8003cce2f |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,2 @@
|
|||||||
*.log
|
*.log
|
||||||
.env
|
|
||||||
*.exe
|
*.exe
|
||||||
|
|||||||
3
go.mod
3
go.mod
@@ -5,7 +5,6 @@ go 1.23.6
|
|||||||
require (
|
require (
|
||||||
code.gitea.io/sdk/gitea v0.18.0
|
code.gitea.io/sdk/gitea v0.18.0
|
||||||
git.site.quack-lab.dev/dave/cylogger v1.4.0
|
git.site.quack-lab.dev/dave/cylogger v1.4.0
|
||||||
git.site.quack-lab.dev/dave/cyutils v1.4.0
|
|
||||||
github.com/go-git/go-git/v5 v5.12.0
|
github.com/go-git/go-git/v5 v5.12.0
|
||||||
golang.design/x/clipboard v0.7.0
|
golang.design/x/clipboard v0.7.0
|
||||||
)
|
)
|
||||||
@@ -30,6 +29,7 @@ require (
|
|||||||
github.com/pjbgf/sha1cd v0.3.0 // indirect
|
github.com/pjbgf/sha1cd v0.3.0 // indirect
|
||||||
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
|
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
|
||||||
github.com/skeema/knownhosts v1.2.2 // indirect
|
github.com/skeema/knownhosts v1.2.2 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.10 // indirect
|
||||||
github.com/xanzy/ssh-agent v0.3.3 // indirect
|
github.com/xanzy/ssh-agent v0.3.3 // indirect
|
||||||
golang.org/x/crypto v0.22.0 // indirect
|
golang.org/x/crypto v0.22.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect
|
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect
|
||||||
@@ -38,7 +38,6 @@ require (
|
|||||||
golang.org/x/mod v0.12.0 // indirect
|
golang.org/x/mod v0.12.0 // indirect
|
||||||
golang.org/x/net v0.22.0 // indirect
|
golang.org/x/net v0.22.0 // indirect
|
||||||
golang.org/x/sys v0.19.0 // indirect
|
golang.org/x/sys v0.19.0 // indirect
|
||||||
golang.org/x/time v0.12.0 // indirect
|
|
||||||
golang.org/x/tools v0.13.0 // indirect
|
golang.org/x/tools v0.13.0 // indirect
|
||||||
gopkg.in/warnings.v0 v0.1.2 // indirect
|
gopkg.in/warnings.v0 v0.1.2 // indirect
|
||||||
mvdan.cc/gofumpt v0.4.0 // indirect
|
mvdan.cc/gofumpt v0.4.0 // indirect
|
||||||
|
|||||||
6
go.sum
6
go.sum
@@ -4,8 +4,6 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
|
|||||||
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
||||||
git.site.quack-lab.dev/dave/cylogger v1.4.0 h1:3Ca7V5JWvruARJd5S8xDFwW9LnZ9QInqkYLRdrEFvuY=
|
git.site.quack-lab.dev/dave/cylogger v1.4.0 h1:3Ca7V5JWvruARJd5S8xDFwW9LnZ9QInqkYLRdrEFvuY=
|
||||||
git.site.quack-lab.dev/dave/cylogger v1.4.0/go.mod h1:wctgZplMvroA4X6p8f4B/LaCKtiBcT1Pp+L14kcS8jk=
|
git.site.quack-lab.dev/dave/cylogger v1.4.0/go.mod h1:wctgZplMvroA4X6p8f4B/LaCKtiBcT1Pp+L14kcS8jk=
|
||||||
git.site.quack-lab.dev/dave/cyutils v1.4.0 h1:/Xo3QfLIFNab+axHneWmUK4MyfuObl+qq8whF9vTQpk=
|
|
||||||
git.site.quack-lab.dev/dave/cyutils v1.4.0/go.mod h1:fBjALu2Cp2u2bDr+E4zbGVMBeIgFzROg+4TCcTNAiQU=
|
|
||||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||||
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
|
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 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
|
||||||
@@ -83,6 +81,8 @@ github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG
|
|||||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A=
|
github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A=
|
||||||
github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
|
github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
|
||||||
|
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||||
|
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
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.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
@@ -164,8 +164,6 @@ 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.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 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
|
|
||||||
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
|||||||
87
main.go
87
main.go
@@ -2,10 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"flag"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
flag "github.com/spf13/pflag"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"github.com/go-git/go-git/v5/config"
|
"github.com/go-git/go-git/v5/config"
|
||||||
@@ -14,28 +15,17 @@ import (
|
|||||||
logger "git.site.quack-lab.dev/dave/cylogger"
|
logger "git.site.quack-lab.dev/dave/cylogger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "1.0.0"
|
var Version = "2.0.0"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
name := flag.String("name", "", "Name of the repository")
|
name := flag.StringP("name", "n", "", "Name of the repository")
|
||||||
flag.String("n", "", "Name of the repository")
|
private := flag.BoolP("private", "p", false, "Make the repository private")
|
||||||
|
|
||||||
private := flag.Bool("private", false, "Make the repository private")
|
|
||||||
flag.Bool("p", false, "Make the repository private (shorthand)")
|
|
||||||
|
|
||||||
noinit := flag.Bool("noinit", false, "Do not add remote to the new repo")
|
noinit := flag.Bool("noinit", false, "Do not add remote to the new repo")
|
||||||
flag.Bool("ni", false, "Do not add remote to the new repo (shorthand)")
|
forceInit := flag.BoolP("force", "f", false, "Force assignment of the remote (deletes existing origin)")
|
||||||
|
remote := flag.StringP("remote", "r", "origin", "Name of the remote to create for the new repository")
|
||||||
forceInit := flag.Bool("f", false, "Force assignment of the remote (deletes existing origin)")
|
version := flag.BoolP("version", "v", false, "Show version")
|
||||||
|
dryrun := flag.Bool("dry-run", false, "Dry run")
|
||||||
remote := flag.String("remote", "origin", "Name of the remote to create for the new repository")
|
help := flag.BoolP("help", "h", false, "Show help")
|
||||||
flag.String("r", "origin", "Name of the remote to create for the new repository (shorthand)")
|
|
||||||
|
|
||||||
version := flag.Bool("v", false, "Show version")
|
|
||||||
flag.Bool("version", false, "Show version")
|
|
||||||
|
|
||||||
help := flag.Bool("h", false, "Show help")
|
|
||||||
flag.Bool("help", false, "Show help")
|
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
logger.InitFlag()
|
logger.InitFlag()
|
||||||
@@ -92,8 +82,9 @@ func main() {
|
|||||||
logger.Info("Name: %s", *name)
|
logger.Info("Name: %s", *name)
|
||||||
logger.Info("Private: %t", *private)
|
logger.Info("Private: %t", *private)
|
||||||
logger.Info("Noinit: %t", *noinit)
|
logger.Info("Noinit: %t", *noinit)
|
||||||
logger.Info("ForceInit: %t", *forceInit)
|
logger.Info("Force: %t", *forceInit)
|
||||||
logger.Info("Remote: %s", *remote)
|
logger.Info("Remote: %s", *remote)
|
||||||
|
logger.Info("Dryrun: %t", *dryrun)
|
||||||
|
|
||||||
client, err := gitea.NewClient(url)
|
client, err := gitea.NewClient(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -109,14 +100,16 @@ func main() {
|
|||||||
clipboard.Write(clipboard.FmtText, []byte(repo.CloneURL))
|
clipboard.Write(clipboard.FmtText, []byte(repo.CloneURL))
|
||||||
} else {
|
} else {
|
||||||
logger.Info("Repository does not exist, creating...")
|
logger.Info("Repository does not exist, creating...")
|
||||||
repo, _, err = client.CreateRepo(gitea.CreateRepoOption{
|
if !*dryrun {
|
||||||
Name: *name,
|
repo, _, err = client.CreateRepo(gitea.CreateRepoOption{
|
||||||
Private: *private,
|
Name: *name,
|
||||||
DefaultBranch: "master",
|
Private: *private,
|
||||||
})
|
DefaultBranch: "master",
|
||||||
if err != nil {
|
})
|
||||||
logger.Error("Error creating repository: %v", err)
|
if err != nil {
|
||||||
return
|
logger.Error("Error creating repository: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logger.Info("Repository created at: %s", repo.CloneURL)
|
logger.Info("Repository created at: %s", repo.CloneURL)
|
||||||
clipboard.Write(clipboard.FmtText, []byte(repo.CloneURL))
|
clipboard.Write(clipboard.FmtText, []byte(repo.CloneURL))
|
||||||
@@ -141,10 +134,12 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
localRepo, err = git.PlainInit(cwd, false)
|
if !*dryrun {
|
||||||
if err != nil {
|
localRepo, err = git.PlainInit(cwd, false)
|
||||||
logger.Error("Error initializing git repository: %v", err)
|
if err != nil {
|
||||||
return
|
logger.Error("Error initializing git repository: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.Info("Checking if remote %s exists in local repository...", *remote)
|
logger.Info("Checking if remote %s exists in local repository...", *remote)
|
||||||
@@ -153,10 +148,12 @@ func main() {
|
|||||||
logger.Info("Remote %s exists in local repository", *remote)
|
logger.Info("Remote %s exists in local repository", *remote)
|
||||||
if *forceInit {
|
if *forceInit {
|
||||||
logger.Info("Deleting remote %s from local repository...", *remote)
|
logger.Info("Deleting remote %s from local repository...", *remote)
|
||||||
err = localRepo.DeleteRemote(*remote)
|
if !*dryrun {
|
||||||
if err != nil {
|
err = localRepo.DeleteRemote(*remote)
|
||||||
logger.Error("Error deleting remote %s from local repository: %v", *remote, err)
|
if err != nil {
|
||||||
return
|
logger.Error("Error deleting remote %s from local repository: %v", *remote, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logger.Info("Remote %s deleted from local repository", *remote)
|
logger.Info("Remote %s deleted from local repository", *remote)
|
||||||
} else {
|
} else {
|
||||||
@@ -166,13 +163,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("Adding remote %s to local repository...", *remote)
|
logger.Info("Adding remote %s to local repository...", *remote)
|
||||||
_, err = localRepo.CreateRemote(&config.RemoteConfig{
|
if !*dryrun {
|
||||||
Name: *remote,
|
_, err = localRepo.CreateRemote(&config.RemoteConfig{
|
||||||
URLs: []string{repo.CloneURL},
|
Name: *remote,
|
||||||
})
|
URLs: []string{repo.CloneURL},
|
||||||
if err != nil {
|
})
|
||||||
logger.Error("Error adding remote %s to local repository: %v", *remote, err)
|
if err != nil {
|
||||||
return
|
logger.Error("Error adding remote %s to local repository: %v", *remote, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logger.Info("Remote added to local repository")
|
logger.Info("Remote added to local repository")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user