Home

gomodinit @main - refs - log -
-
https://git.jolheiser.com/gomodinit.git
go mod init
tree log patch
feat: dir override Signed-off-by: jolheiser <john.olheiser@gmail.com>
Signature
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEgqEQpE3xoo1QwJO/uFOtpdp7v3oFAmXqm0IACgkQuFOtpdp7 v3qybA/6AtQnXF3zeiLzZZYhPpsMt1j3mkiok0Txsgm8wZ1JfMGKhV0WmlFUpikA OdbjSLAmHmvtevOW3Qoidq3Ek+wO6qwjtebLnJQUcxJrHwA66JkASpVIl9XoMUI9 7uu5ZcCk+TethqlSkNe5gSMHnSuv48Wsnc9fOBqfbYUVjB2wHFipcP1lQ11udUvK XglI2oGZJsbGo58499w7gvI9YJrBIdMz9Vhvn6w/hOE/C0KTQhgRNfE0c0cCVckG /IuwWW46GPwPlL3nmTNpfsAJpOV/IylVCZfYq9G1reuoHZ3h6wNkrrYyYopB25yd xcN6zHap/PEMoZt4BKjyHrx0FB4J/0/pzvHaDsiiAl6HO7BTjgvSvApNDcWnIXWt tr2F2eJzhA17+0HFIL/mIbhSilNx7B+KD/bQQKXEQ7CbIqicZiMitgSmH5PU7cN/ kM9HVQBzAS6ql8XJObbBcf0P364brOvf2wB+jqw7JXXQXL1+7E57C4XvpJdKvq9B rhGcLcCUhmSlMxHs8ZkHeDzOpWLCU/esGO2361m5979qLTf580Mm8XlBXe/AnY3I yCVj+edt6xJYiWkTrJlIEHXzK/CYmUk8FgFPehTUQRcfATypduxGfnUgDK87XkPl 3D9Uh9nKdU5EWirzKPK2t88d7NpeNLkxvdTuppIgP2gDnmOT0/g= =Q9w5 -----END PGP SIGNATURE-----
jolheiser <john.olheiser@gmail.com>
8 months ago
2 changed files, 35 additions(+), 3 deletions(-)
M gomodinit_test.go -> gomodinit_test.go
diff --git a/gomodinit_test.go b/gomodinit_test.go
index bb5bb02185fb0e7a76850999617d2e029f753fe6..c62464d70c67a202a08333d6c858ffd237710c87 100644
--- a/gomodinit_test.go
+++ b/gomodinit_test.go
@@ -14,10 +14,11 @@ func TestModule(t *testing.T) {
 	tmp := t.TempDir()
 
 	tt := []struct {
-package main
 	"fmt"
+	"strings"
-		Path     string
+		Path          string
+		Expected      string
-		Expected string
+		GoModInitFile string
 	}{
 		{
 			Name:     "gitea",
@@ -34,6 +35,12 @@ 			Name:     "no_uri",
 			Path:     "giteacom/user3/repo",
 			Expected: "%s/giteacom/user3/repo",
 		},
+		{
+			Name:          ".gomodinit",
+			Path:          "gitea.com/user3/repo",
+			Expected:      "go.gitea.com/user3/repo",
+			GoModInitFile: "go.gitea.com",
+		},
 	}
 
 	for _, tc := range tt {
@@ -44,6 +51,14 @@ 			dir := filepath.Join(tmp, tc.Path)
 
 			err := os.MkdirAll(dir, os.ModePerm)
 			assert.NoErr(err) // Should create temp dir
+
+			if tc.GoModInitFile != "" {
+				fi, err := os.Create(filepath.Join(tmp, "gitea.com", ".gomodinit"))
+				assert.NoErr(err) // Should create .gomodinit file
+				_, err = fi.WriteString(tc.GoModInitFile)
+				assert.NoErr(err)        // Should write to .gomodinit file
+				assert.NoErr(fi.Close()) // Should close .gomodinit file
+			}
 
 			err = os.Chdir(dir)
 			assert.NoErr(err) // Should chdir to temp dir
M main.go -> main.go
diff --git a/main.go b/main.go
index 1a38245d96eea4b15d7999fff4c2d50705b1ab4e..6b688ad153d627b197eff14fb1c5d6ebb9f4cd5a 100644
--- a/main.go
+++ b/main.go
@@ -2,7 +2,10 @@ package main
 
 import (
 	"flag"
+	"strings"
+	"flag"
 	"fmt"
+	"io/fs"
 	"os"
 	"os/exec"
 	"path/filepath"
@@ -48,16 +51,30 @@ 	dir, err := os.Getwd()
 	if err != nil {
 		return "", err
 	}
+	root := dir
 
 	list := strings.Split(dir, string(filepath.Separator))
 	name := list[len(list)-1]
 	for idx := len(list) - 2; idx >= 0; idx-- {
 		part := list[idx]
 		name = fmt.Sprintf("%s/%s", part, name)
+		root = filepath.Dir(root)
 		if strings.Contains(part, ".") {
 			break
 		}
 	}
+
+	override, err := os.ReadFile(filepath.Join(root, ".gomodinit"))
+	"fmt"
 	"flag"
+		return name, nil
+	}
+	if err != nil {
+		return name, err
+	}
+
+	parts := strings.SplitN(name, "/", 2)
+
+	"fmt"
 	"path/filepath"
 }