Home

tmpl @main - refs - log -
-
https://git.jolheiser.com/tmpl.git
Template automation
tree log patch
More tests and env variables Signed-off-by: jolheiser <john.olheiser@gmail.com>
Signature
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEgqEQpE3xoo1QwJO/uFOtpdp7v3oFAl+1/eEACgkQuFOtpdp7 v3ohoxAAjFSMsFErt0hpoc7WxWSKrdh4WIQ0husfwsEMos2aZmrXE+9XgNL5sSwb A+2GTo7UdXjsDANLuSlCkMpTlcTU1bdCzaVBepA5LNW4jnpPg/xeh5AngQUhMem7 pS6rP66dnwXZT/wcm0s3zph3jbHUkl6chp37Ba4l3aAIeXcqjAe+UaivmXuyp7qk bWJmi0boNr3YS2WVyGOKqN/rpsbmdLFi2piiXPq9KBbuwBa1pUfEPrqMfEo0LFq7 EcQkjq0kVo0G6987FLD4vG38J3ZwyEI312tXP0KYrLsFd7wPZ6d1/Qoc/ZUDBR1x s5zfOgm611FuH0BG2MUH7zRBMoASfrVZxQHeubuB8PuptPAseqsflIvH7JDdqZBZ h2z5dPMZ7JPoQ5aHkkPRs95FowpSf0+ntvDDunJ6HLwBtekPff86sHvoX1A7wM8i k9Cs+5kKKYR6Pd05hRqHyHqDH+024yebNix+KJ7MKNTAnWM7YcELUmnklRebp87G tVaYxZ3d5Pf93PzXuMfa+siwwZesxqQjVL7fdTX2oEXTKcSxtvKeQ2sHCIGGMDMk bleFhj6TPS03XAs33e2fd58NUwDTnYcl8NGcjYPOsqa+2y5M+95vo9lZeYoJSeSc FXndq7ZJm9ooBUDhLEndXYNAuewcGdtQz/kMq7ebK7dMwhAtwXM= =cmD0 -----END PGP SIGNATURE-----
jolheiser <john.olheiser@gmail.com>
4 years ago
6 changed files, 58 additions(+), 100 deletions(-)
D DOCS.md
diff --git a/DOCS.md b/DOCS.md
deleted file mode 100644
index 7f9a148eb7a5ac728ddfc946d1da6e584fa83689..0000000000000000000000000000000000000000
--- a/DOCS.md
+++ /dev/null
@@ -1,82 +0,0 @@
-# NAME
-
-tmpl - Template automation
-
-# SYNOPSIS
-
-tmpl
-
-```
-[--debug|-d]
-[--registry|-r]=[value]
-[--source|-s]=[value]
-```
-
-**Usage**:
-
-```
-tmpl [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
-```
-
-# GLOBAL OPTIONS
-
-**--debug, -d**: Debug mode
-
-**--registry, -r**="": Registry directory of tmpl (default: /home/jolheiser/.tmpl)
-
-**--source, -s**="": Short-name source to use
-
-
-# COMMANDS
-
-## download
-
-Download a template
-
-**--branch, -b**="": Branch to clone (default: main)
-
-## init
-
-Initialize a template
-
-## list
-
-List templates in the registry
-
-## remove
-
-Remove a template
-
-## save
-
-Save a local template
-
-## source
-
-Commands for working with sources
-
-### list
-
-List available sources
-
-### add
-
-Add a source
-
-### remove
-
-Remove a source
-
-## test
-
-Test if a directory is a valid template
-
-## update
-
-Update a template
-
-## use
-
-Use a template
-
-**--defaults**: Use template defaults
M cmd/app.go -> cmd/app.go
diff --git a/cmd/app.go b/cmd/app.go
index ba08026feef942eb038c8c5dec5901cb8828bab7..2c414c1812943c266fae8e361b6cdf87b51b9926 100644
--- a/cmd/app.go
+++ b/cmd/app.go
@@ -31,27 +31,23 @@ 	app.Usage = "Template automation"
 	app.Description = "Template automation"
 	app.Version = Version
 	app.Flags = []cli.Flag{
-		&cli.BoolFlag{
-			Name:        "debug",
-			Aliases:     []string{"d"},
-			Usage:       "Debug mode",
-			Destination: &flags.Debug,
-		},
 		&cli.StringFlag{
 			Name:        "registry",
 			Aliases:     []string{"r"},
 			Usage:       "Registry directory of tmpl",
 			Value:       defaultDir,
+			DefaultText: "~/.tmpl",
 			Destination: &flags.Registry,
+			EnvVars:     []string{"TMPL_REGISTRY"},
 		},
 		&cli.StringFlag{
 			Name:        "source",
 			Aliases:     []string{"s"},
 			Usage:       "Short-name source to use",
 			Destination: &flags.Source,
+			EnvVars:     []string{"TMPL_SOURCE"},
 		},
 	}
-	app.Before = before
 
 	app.Commands = []*cli.Command{
 		Download,
@@ -67,10 +63,3 @@ 	}
 
 	return app
 }
-
-func before(ctx *cli.Context) error {
-	if ctx.Bool("debug") {
-		beaver.Console.Level = beaver.DEBUG
-	}
-	return nil
-}
M cmd/download.go -> cmd/download.go
diff --git a/cmd/download.go b/cmd/download.go
index c173c9e96ec0c3e241cca9cdf991f99eaa03eaac..f88fd7cde5342e9b67dccd104ad47344427699c3 100644
--- a/cmd/download.go
+++ b/cmd/download.go
@@ -52,11 +52,11 @@ 		}
 	}
 
 	cloneURL := ctx.Args().First()
-	if !strings.HasSuffix(cloneURL, ".git") {
-		cloneURL += ".git"
-	}
 	if source != nil {
 		cloneURL = source.CloneURL(cloneURL)
+	}
+	if !strings.HasSuffix(cloneURL, ".git") {
+		cloneURL += ".git"
 	}
 
 	t, err := reg.DownloadTemplate(ctx.Args().Get(1), cloneURL, ctx.String("branch"))
M docs.go -> docs.go
diff --git a/docs.go b/docs.go
index 3f5bd464612e9852dbd9fe8dbd4f2560c4f8c14c..5f18aae7e9016ae49be44dbea722514c473e7ab9 100644
--- a/docs.go
+++ b/docs.go
@@ -4,6 +4,7 @@ package main
 
 import (
 	"os"
+	"regexp"
 	"strings"
 
 	"go.jolheiser.com/tmpl/cmd"
@@ -25,6 +26,9 @@ 	}
 
 	// CLI ToMarkdown issue related to man-pages
 	md = md[strings.Index(md, "#"):]
+
+	// CLI is using real default instead of DefaultText
+	md = regexp.MustCompile(`[\/\w]+\.tmpl`).ReplaceAllString(md, "~/.tmpl")
 
 	if _, err := fi.WriteString(md); err != nil {
 		panic(err)
M registry/source.go -> registry/source.go
diff --git a/registry/source.go b/registry/source.go
index b42a792ee8120d47c907325f8683481799003db4..7770538f8756aacb8cd0da0b6110351fae86318c 100644
--- a/registry/source.go
+++ b/registry/source.go
@@ -11,5 +11,5 @@ }
 
 // CloneURL constructs a URL suitable for cloning a repository
 func (s *Source) CloneURL(namespace string) string {
-	return fmt.Sprintf("%s%s", s.URL, namespace)
+	return fmt.Sprintf("%s%s.git", s.URL, namespace)
 }
I registry/source_test.go
diff --git a/registry/source_test.go b/registry/source_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..26134410acc69401a1261858e3fbea271701f95c
--- /dev/null
+++ b/registry/source_test.go
@@ -0,0 +1,47 @@
+package registry
+
+import (
+	"strings"
+	"testing"
+)
+
+func TestSource(t *testing.T) {
+	tt := []struct {
+		Name     string
+		Source   *Source
+		CloneURL string
+	}{
+		{
+			Name: "Gitea",
+			Source: &Source{
+				URL: "https://gitea.com/",
+			},
+			CloneURL: "https://gitea.com/user/repo.git",
+		},
+		{
+			Name: "GitHub",
+			Source: &Source{
+				URL: "https://github.com/",
+			},
+			CloneURL: "https://github.com/user/repo.git",
+		},
+		{
+			Name: "GitLab",
+			Source: &Source{
+				URL: "https://gitlab.com/",
+			},
+			CloneURL: "https://gitlab.com/user/repo.git",
+		},
+	}
+
+	namespace := "user/repo"
+	for _, tc := range tt {
+		t.Run(tc.Name, func(t *testing.T) {
+			cloneURL := tc.Source.CloneURL(namespace)
+			if !strings.EqualFold(tc.CloneURL, cloneURL) {
+				t.Logf("incorrect clone URL:\n\tExpected: %s\n\tGot: %s\n", tc.CloneURL, cloneURL)
+				t.Fail()
+			}
+		})
+	}
+}