More tests and env variables
Signed-off-by: jolheiser <john.olheiser@gmail.com>pull/7/head
parent
dc19c1b993
commit
1c516ad3db
82
DOCS.md
82
DOCS.md
|
@ -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
|
17
cmd/app.go
17
cmd/app.go
|
@ -31,27 +31,23 @@ func NewApp() *cli.App {
|
|||
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 @@ func NewApp() *cli.App {
|
|||
|
||||
return app
|
||||
}
|
||||
|
||||
func before(ctx *cli.Context) error {
|
||||
if ctx.Bool("debug") {
|
||||
beaver.Console.Level = beaver.DEBUG
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -52,12 +52,12 @@ func runDownload(ctx *cli.Context) error {
|
|||
}
|
||||
|
||||
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"))
|
||||
if err != nil {
|
||||
|
|
4
docs.go
4
docs.go
|
@ -4,6 +4,7 @@ package main
|
|||
|
||||
import (
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"go.jolheiser.com/tmpl/cmd"
|
||||
|
@ -26,6 +27,9 @@ func main() {
|
|||
// 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)
|
||||
}
|
||||
|
|
|
@ -11,5 +11,5 @@ type Source struct {
|
|||
|
||||
// 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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue