Rework flags to use pflag

This commit is contained in:
2025-10-15 10:18:49 +02:00
parent d8003cce2f
commit b286d5578e
4 changed files with 17 additions and 24 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,2 @@
*.log
.env
*.exe

1
go.mod
View File

@@ -29,6 +29,7 @@ require (
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // 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
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect

2
go.sum
View File

@@ -81,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/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A=
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/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=

37
main.go
View File

@@ -2,10 +2,11 @@ package main
import (
_ "embed"
"flag"
"os"
"path"
flag "github.com/spf13/pflag"
"code.gitea.io/sdk/gitea"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
@@ -14,32 +15,21 @@ import (
logger "git.site.quack-lab.dev/dave/cylogger"
)
var Version = "1.0.0"
var Version = "2.0.0"
func main() {
name := flag.String("name", "", "Name of the repository")
flag.String("n", "", "Name of the repository")
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")
flag.Bool("ni", false, "Do not add remote to the new repo (shorthand)")
forceInit := flag.Bool("f", false, "Force assignment of the remote (deletes existing origin)")
remote := flag.String("remote", "origin", "Name of the remote to create for the new repository")
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")
name := flag.StringP("name", "n", "", "Name of the repository")
private := flag.BoolP("private", "p", false, "Make the repository private")
noinit := flag.BoolP("noinit", "ni", false, "Do not add remote to the new repo")
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")
version := flag.BoolP("version", "v", false, "Show version")
dryrun := flag.Bool("dryrun", false, "Dry run")
help := flag.BoolP("help", "h", false, "Show help")
flag.Parse()
logger.InitFlag()
logger.Info("Starting repo %s", Version)
if *version {
@@ -92,8 +82,9 @@ func main() {
logger.Info("Name: %s", *name)
logger.Info("Private: %t", *private)
logger.Info("Noinit: %t", *noinit)
logger.Info("ForceInit: %t", *forceInit)
logger.Info("Force: %t", *forceInit)
logger.Info("Remote: %s", *remote)
logger.Info("Dryrun: %t", *dryrun)
client, err := gitea.NewClient(url)
if err != nil {